



Initialising Arrays DATA statements to initialise arrays, all of them
simpler and more efficient than the equivalent set of DO-loops. Perhaps the most
common requirement is to initialise all the elements of an array: in this case the
array name can appear without subscripts. If several of the elements are to
have the same initial value a repeat count can be precede any constant:
REAL FLUX(1000) DATA FLUX / 512*0.0, 488*-1.0 / |
Named constants are permitted, but not constant expressions. The repeat count may be a literal or named integer constant. To initialise a multi-dimensional array with parameterised array bounds it is necessary to define another integer constant to hold the total number of elements:
PARAMETER (NX = 800, NY = 360, NTOTAL = NX * NY) DOUBLE PRECISION SCREEN(NX,NY), ZERO PARAMETER (ZERO = 0.0D0) DATA SCREEN / NTOTAL * ZERO / |
REAL SPARSE(50,50) DATA SPARSE(1,1), SPARSE(50,50) / 1.0, 99.99999 / |
INTEGER ODD(10) DATA (ODD(I),I=1,10,2)/ 5 * 43/ DATA (ODD(I),I=2,10,2)/ 5 * 0 / |
DATA
statement in which it is used. Any integer variable may be used as a loop control
index in a DATA statement without effects elsewhere; the value of I itself is not defined
by these statements.
When initialising part of a multi-dimensional array it may occasionally be useful
to nest DO-loops like this:
DOUBLE PRECISION FIELD(5,5) DATA ((FIELD(I,J),I=1,J), J=1,5) / 15 * -1.0D0 / |