FORTRAN Reference Manual

Statements
FORTRAN Reference Manual528615-001
7-25
DATA Statement
Considerations
DATA statements must follow any specification statements that define the entities
initialized by the DATA statement. Except for this restriction, DATA statements can
appear anywhere in a program unit.
list cannot include the name of a RECORD, dummy argument, function, entry
point, or entity in blank common.
list can include names of entities in a named common block only within a
BLOCK DATA subprogram.
Each list must contain the same number of items as the corresponding data. In
the following example, A is initialized to 3.0, B is initialized to 4.0, and C is
initialized to the string “Total Revenue”:
CHARACTER c*20
DATA a, b, c/ 3.0, 4.0, 'Total Revenue'/
Corresponding list and data items must agree with respect to type. If the length
of a list character item exceeds the length of its corresponding data, the excess
characters are initially defined as blanks. If the length of a list character is less
than its corresponding data, the trailing data characters are truncated.
The DATA specification statement accepts real numbers in decimal format as well
as in exponential D and E formats. For example:
DOUBLE PRECISION weight
DATA number, weight/3, 1.31D3/
If you specify an unsubscripted array name as a list item, the corresponding
data must contain one value for each element of that array. Values are assigned
to the array elements in a predefined progression, with the leftmost subscript
varying most rapidly.
The repeat count form
If you need to initialize a series of variables to a single value, you can use the
repeat count form of the DATA statement. The following statement stores the value
of 98.6 in the variables A, B, C, and D:
DATA a, b, c, d / 4 * 98.6 /
To initialize each element of the array INVENTORY(100) to 0, enter:
DATA inventory / 100 * 0 /
The implied DO list form
See Using Implied DO Lists on page 5-27.