Print

Print


Greetings fellow Fortranners:

In translating some code we came across a presumably unusual
situation.

We would like to have, for example, something like this:

DOUBLE PRECISION, PARAMETER :: a(1024) = (/6.33795775455379D0, [...]

where the entire parameter array is initialized with an equally large
array constructed using 1024 unique double precision constants.  We
would also like to do so in a standard conforming way.

The rub is that if my calculations are correct, with 39 continuation
lines and 132 characters per line, that means an upper bound for the
number of characters inside the (/ and /) is approximately 5196
characters, including commas but excluding continuation characters.
This leaves just over four characters per double precision value
excluding the commas, on average, which for our purposes is too few.

Taking 16 characters per constant, plus two for the D0 and one for the
comma, we would need in this case 19456 characters inside the (/ and
/), or over 148 lines of 132 characters each, after counting the
continuation character.

Of course, we could make the array an ordinary array and initialize it
with a series of data statements, but we would really like it to be a
parameter as it is just a table for looking up constants and never
modified by the code.  Like most folks, we believe good programming
practice is to use the PARAMETER attribute wherever possible.

Also, I would guess that most if not all compilers in use today
support source code with lines longer than 132 characters and with
more than 39 continuation lines, but we would like this code to be
standard conforming.

So how can we declare such a parameter array in a way that conforms to
the standard?

All I can think of is to declare a set of smaller parameter arrays,
each small enough not to exceed the source code limits, and then to
use them to initialize the larger array, as in:

DOUBLE PRECISION, PARAMETER :: a_1(128) = (/6.33795775455379D0, [...]
  [...]
DOUBLE PRECISION, PARAMETER :: a_8(128) = (/6.02529426559128D0, [...]

INTEGER :: i

DOUBLE PRECISION, PARAMETER :: a(1024) = (/ (a_1(i),i=1,128), &
                                              [...]
                                            (a_8(i),i=1,128) /)

But this seems less than elegant, even though I suspect a decent
compiler would get rid of the smaller arrays if they are only used to
initialize the larger one.

Any thoughts?

Thanks!

John

--
John Jeffrey Venier, M.Stat.                  Programmer Analyst III
Section of Computer Science             Department of Biomathematics
The University of Texas M. D. Anderson Cancer Center, Houston, Texas
[log in to unmask]                                +1 713 792 2622