The DATA statement initializes variables, substrings, arrays, and array elements.
DATA nlist / clist / [[,] nlist / clist /] ...
Parameter |
Description |
nlist |
List of variables, arrays, array elements, substrings, and implied DO lists separated by commas |
clist |
List of the form: c [, c ] |
c |
One of the forms: c or r*c, and c is a constant or the symbolic name of a constant. |
r |
Nonzero, unsigned integer constant or the symbolic name of such constant |
All initially defined items are defined with the specified values when an executable program begins running.
r*c is equivalent to r successive occurrences of the constant c.
A DATA statement is a nonexecutable statement, and must appear after all specification statements, but it can be interspersed with statement functions and executable statements, although this is non-standard@.
Initializing a local variable in a DATA statement after an executable reference to that variable is flagged as an error when compiling with the -stackvar option. See the Sun Fortran User's Guide.
Taking into account the repeat factor, the number of constants in clist must be equal to the number of items in the nlist. The appearance of an array in nlist is equivalent to specifying a list of all elements in that array. Array elements can be indexed by constant subscripts only.
Automatic variables or arrays cannot appear on a DATA statement.
Normal type conversion takes place for each noncharacter member of the clist.
If the length of a character item in nlist is greater than the length of the corresponding constant in clist, it is padded with blank characters on the right.
If the length of a character item in nlist is less than that of the corresponding constant in clist, the additional rightmost characters are ignored.
If the constant in clist is of integer type and the item of nlist is of character type, they must conform to the following rules:
The character item must have a length of one character.
The constant must be of type integer and have a value in the range 0 through 255. For ^A, ^B, ^C, do not hold down the Control key and press A, B, or C; use the CHAR intrinsic function.
If the constant of clist is a character constant or a Hollerith constant, and the item of nlist is of type INTEGER, then the number of characters that can be assigned is 2 or 4 for INTEGER*2 and INTEGER*4 respectively. If the character constant or the Hollerith constant has fewer characters than the capacity of the item, the constant is extended on the right with spaces. If the character or the Hollerith constant contains more characters than can be stored, the constant is truncated on the right.
An nlist can specify an implied DO list for initialization of array elements.
The form of an implied DO list is:
Parameter |
Description |
dlist |
List of array element names and implied DO lists |
iv |
Integer variable, called the implied DO variable |
m1 |
Integer constant expression specifying the initial value of iv |
m2 |
Integer constant expression specifying the limit value of iv |
m3 |
Integer constant expression specifying the increment value of iv. If m3 is omitted, then a default value of 1 is assumed. |
The range of an implied DO loop is dlist. The iteration count for the implied DO is computed from m1, m2, and m3, and it must be positive.
Implied DO lists may also appear within the variables lists on I/O statements PRINT, READ, and WRITE.
Variables can also be initialized in type statements. This is an extension of the FORTRAN 77 Standard. Examples are given under each of the individual type statements and under the general type statement. @
Example 1: Character, integer, and real scalars. Real arrays:
CHARACTER TTL*16 REAL VEC(5), PAIR(2) DATA TTL /'Arbitrary Titles'/, & M /9/, N /0/, & PAIR(1) /9.0/, & VEC /3*9.0, 0.1, 0.9/ ...
Example 2: Arrays--implied DO:
REAL R(3,2), S(4,4) DATA ( S(I,I), I=1,4)/4*1.0/, & ( R(I,J), J=1,3), I=1,2)/6*1.0/ ...
Example 3: Mixing an integer and a character:
CHARACTER CR*1 INTEGER I*2, N*4 DATA I /'00'/,N/4Hs12t/,CR/13/ ...