0

I have a large array of integer parameters (6024 triplets, for a total of ~9000 elements in a 3x6024 array) to place in a module as data for other functions. The parameter is defined:

Integer, Parameter :: nj = 6024
Integer, Parameter :: abc(1:3,1:nj) = &
    & RESHAPE( (/ a1 , b1 , c1, &  !j = 1
                & a2 , b2 , c2, &  !j = 2
                !... like 6000 more lines ...
                & aj , bj , cj  /), &  !j = nj
                & SHAPE=(/3,nj/),ORDER=(/2,1/) )

Where aj,bj, and cj are arbitrary integer constants.

I prefer this formatting (using continuation lines to keep the triplets together) for readability, but for a long array it introduces too many continuation lines to be in compliance with standard Fortran (Fortran 2003 and newer allow up to 255 continuation lines). These parameters are not predictably distributed, so an implied loop for definition is not an option.

I could put more triplets on a line, but 4-byte integers take up 12 characters each (10 digits, sign, comma), with the continuation & that leaves room for 10 integers on a standard-compliant free-form line (132 characters). In 255 continuation lines, this establishes a practical limit of ~2550 elements (of this type) that can be listed for the array parameter definition.

Is there a way to do this parameter definition in Fortran 2008 standard-compliant code? Can a parameter array be defined in segments? e.g.

Integer, Parameter :: nj = 6024
Integer, Parameter :: abc(1:3,1:nj)
Integer, Parameter :: abc(:,1)  = (/ a1 , b1 , c1 /) !j = 1
Integer, Parameter :: abc(:,2)  = (/ a2 , b2 , c2 /) !j = 2
                                  !... like 6000 more lines ...
Integer, Parameter :: abc(:,nj) = (/ aj , bj , cj /) !j = nj
Seanny123
  • 8,776
  • 13
  • 68
  • 124
whit
  • 131
  • 6
  • I've reviewed both of the potential duplicates helpfully identified, and I'm not quite satisfied. The proposed answers are fairly specific to each case. I'm more interested in an approach for an arbitrarily-long arbitrarily-shaped parameter. – whit Jul 20 '18 at 15:38
  • 1
    If you can explain (in your question) why, for example, "assemble it in source manageable chunks - perhaps column by column." doesn't quite meet your needs, then that would help us give an alternative approach/reopen this one. – francescalus Jul 20 '18 at 15:57
  • Reshape takes an array as argument, and you can create an array by combining other arrays, like `arr = [arr1, arr2, arr3]`. You associate an array to each line of dimensions. Also, a data statement can define an array in chunks. You could even have a separate data file just for it. – Rodrigo Rodrigues Jul 20 '18 at 18:05
  • Is there any reason not to read it in from a file? Personally I think that'll be much more readable than a 6000 line long parameter statement. Stick it in a module with a initialisation routine, throw in a protected attribute for safety and you should be sorted. – Ian Bush Jul 22 '18 at 08:45

0 Answers0