The DATA statement assigns initial values to variables and array
elements before program execution. It takes the following form:
DATA nlist/clist/[[,] nlist/clist/] . . .
- nlist
- Is a list containing any combination of variable names, array
names, array element names, character substring names, and implied-
DO lists. (RECORDs are not allowed in this
list.) Elements in the list must be separated by commas.
Subscript expressions and expressions in substring references must
be integer expressions containing integer constants and implied-DO
variables.
An implied-DO list in a DATA statement takes the following form:
(dlist, i = n1,n2[,n3])
- dlist
- Is a list of one or more array element names, character
substring names, or implied-DO lists, separated by commas.
- i
- Is the name of an integer variable.
- n1, n2, n3
- Are integer constant expressions. The expression can contain
implied-DO variables of other implied-DO lists that have this
implied-DO list within their ranges.
- clist
- Is a list of constants separated by commas; clist
constants take one of the following forms:
c
n *c
- c
- Is a constant or the symbolic name of a constant.
- n
- Defines the number of times the same value is to be assigned
to successive entities in the associated nlist; n
is a nonzero, unsigned integer constant or the symbolic name of an
unsigned integer constant.
Rules and Behavior
The DATA statement assigns the constant values in each
clist to the entities in the preceding nlist, from
left to right, as they appear in the nlist. The number of
constants must equal the number of entities in the nlist.
When an unsubscripted array name appears in a DATA statement,
values are assigned to every element of that array in the order
of subscript progression. The associated constant list must contain
enough values to fill the array.
The following list describes the relationship between nlist
items and clist items:
- If both the constant value in clist and the
entity in nlist have numeric data types, conversion
is based on the following rules:
- If necessary, the constant value is converted to the
data type of the variable being initialized.
- When a bit constant is assigned
to a variable or array element, the number of digits that can
be assigned depends on the data type of the data item (see
Table 2-1). If the constant contains
fewer digits than the capacity of the variable or array
element, the constant is extended on the left with zeros.
If the constant contains more digits than can be stored, the
constant is truncated on the left.
- If the constant value in clist and the entity in
nlist are both of character data type, the conversion is
based on the following rules:
- If the length of the constant is less than the length
of the entity, the rightmost character positions of the entity
are initialized with space characters.
- If the length of the constant is greater than the
length of the entity, the character constant is truncated on
the right.
- If the constant value in
clist is of numeric data type and the entity in
nlist is of character data type, the constant and the
entity must conform to the following restrictions:
- The character entity must have a length of one
character.
- The constant must be an integer or bit constant and
must have a value in the range 0 through 255.
When the clist constant and the nlist entity
conform to these restrictions, the nlist entity
is initialized with the character that has the ASCII code
specified by the clist constant. (This behavior lets you
initialize a character entity to any 8-bit ASCII code.)
- If the constant value in
clist is a Hollerith constant or character constant
and the entity in nlist is a numeric variable or
numeric array element, the number of characters that can be
assigned depends on the data type of the data item (see
Table 2-1). If the Hollerith or character
constant contains fewer characters than the capacity of the
variable or array element, the constant is extended on the right
with space characters. If the constant contains more characters
than can be stored, the constant is truncated on the right.
Example
In the following example, the first DATA statement assigns zero to
all 10 elements of array A and 4 asterisks followed by 2 spaces to
the character variable STARS:
INTEGER A(10), B(10)
CHARACTER BELL, TAB, LF, FF, STARS*6
DATA A,STARS /10*0,'****'/
DATA BELL,TAB,LF,FF /7,9,10,12/
DATA (B(I), I=1,10,2) /5*1/
The second DATA statement assigns ASCII control character codes
to the character variables BELL, TAB, LF, and FF. The last DATA
statement uses an implied-DO loop to assign values to the odd
numbered elements in the array B.
Previous Page Next Page Table of Contents