| United States-English |
|
|
|
![]() |
HP Fortran 90 Programmer's Reference: HP Fortran 90 Programmer's Reference > Chapter 10 HP Fortran 90 statementsDATA |
|
Initializes program variables. Syntax
DescriptionThe DATA statement initializes variables local to a program unit before the program unit begins execution. Initialization occurs as follows: The var-list is expanded to form a sequence of scalar variables, and the val-list is expanded to form a sequence of scalar constants. The number of items in each expanded sequence must be the same, and there must be a one-to-one correspondence between the items in the two expanded lists. The variables in the expanded sequence of var-list are initialized on the basis of the correspondence. If var-list contains an array name, the expanded sequence of constants must contain a constant for every element in the array. A zero-sized array or an implied-DO list with an iteration count of zero in var-list contributes no variables to the expanded sequence of variables. However, a zero-length character variable does contribute a variable to the list. If a constant is of any numeric or logical type, the corresponding variable can be of any numeric type. If an object is of derived type, the corresponding constant must be of the same type. If the type of the constant does not agree with the type of the variable, type conversion is performed, as described in Table 5-5 “Conversion of variable=expression”. Variables can be initialized with binary, octal, or hexadecimal constants. A variable or array element must not appear in a DATA statement more than once. If two variables share the same storage space through an EQUIVALENCE statement, only one can appear in a DATA statement. If a substring of a character variable or other array element appears in a DATA statement, no overlapping substring (including the entire variable or array element) can appear in any DATA statement. The length of a character constant and the declared length of its corresponding character variable need not be the same. If the constant is shorter than the variable, blank characters are placed in the remaining positions. If the constant is longer than the variable, the constant is truncated from the right until it is the same length as the variable If a subscripted array element appears in var-list, then the subscript must be a specification expression. DATA statements can be interspersed among executable statements. However, they initialize prior to runtime and, therefore, cannot be used as executable assignment statements. Fortran 90 extensions A variable of type other than integer may be initialized with a binary, octal, or hexadecimal constant. The data type for a constant is determined from the type of the corresponding variable. The size (in bytes) of the variable determines how many digits of the octal or hexadecimal constant are used. If the constant lacks enough digits, the value is padded on the left with zeros. If the constant has too many digits, it is truncated on the left. An integer, binary, octal, or hexadecimal constant can initialize a character variable of length one, as long as the value of the constant is in the range 0 to 255. ExamplesThe following DATA statement initializes integer, logical, and character variables:
The next DATA statement specifies a repetition factor of 3 to assign the value of 2 to all three elements of array i:
The next DATA statement uses two nested implied-DO loops to assign the literal value X to each element of an array of 50 elements, k(10,5):
Related statementsBYTE, CHARACTER, COMPLEX, DOUBLE COMPLEX, DOUBLE PRECISION, INTEGER, LOGICAL, and REAL Related conceptsFor related information, see the following: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||