HP 3000 Manuals

DATA Statement (Nonexecutable) [ HP FORTRAN 77/iX Reference ] MPE/iX 5.0 Documentation


HP FORTRAN 77/iX Reference

DATA Statement (Nonexecutable) 

The DATA statement assigns initial values to variables before execution
begins.

[]
----------------------------------------------------------------------------------------------- | | | | | Item | Description/Default | Restrictions | | | | | ----------------------------------------------------------------------------------------------- | | | | | iteration_constant | Nonzero unsigned integer. The | None. | | | default is one. | | | | | | ----------------------------------------------------------------------------------------------- | | | | | iteration_constant_name | Named constant, defined by a | None. | | | PARAMETER statement, representing | | | | a nonzero unsigned integer. The | | | | default is one. | | | | | | ----------------------------------------------------------------------------------------------- | | | | | * | Repeat specifier. | None. | | | | | ----------------------------------------------------------------------------------------------- Semantics The number of items in the constant list must agree with the number of variables in the variable list. Each subscript in an array element in the variable list must be an integer or short integer constant expression, or an integer or short integer expression containing only constants and implied DO variables. If the variable list contains an array name without a subscript, one constant must be specified for each element of that array. The elements in the constant list are associated with the elements of the array in column-major order. The assignment of constants in a DATA statement to their corresponding variables follows the rules of the assignment statement. (See "Assignment Statement (Executable)" for details.) If a constant has a type of character or logical, the corresponding variable must be of the same type. Character variables can be initialized with octal, hexadecimal or hollerith constants as well. If a constant is of any numeric type (integer, real, or complex), the corresponding variable can be of any numeric type. Type conversion occurs automatically among the various numeric types, as in assignment statements. The length of a character constant and the declared length of its corresponding character variable do not have to be the same. If the constant is shorter than the variable, the variable is filled on the right with blank characters. If the constant is longer than the variable, the constant is truncated, losing characters from the right. Any local variable except a record can be initialized in a DATA statement, before execution of the program. A local variable mentioned in a DATA statement is treated the same way as one specified in a SAVE statement. Labeled common variables can also be initialized in a DATA statement within a block data subprogram. The total size of local variables in a single subroutine must be less than one gigabyte. (A gigabyte is 1,073,741,824 (230) bytes.) A variable or array element must not appear in a DATA statement more than once because a variable is initialized only once. If two variables (numeric or character) share the same storage space through the EQUIVALENCE statement, only one can appear in a DATA statement. Each subscript expression in a DATA statement must be an integer constant expression, except for implied DO loop variables. The use of octal and hexadecimal constants in DATA statements are MIL-STD-1753 standard extensions to the ANSI 77 standard. DATA statements can be placed anywhere after specification statements in a program unit. DATA statements cannot be used in procedures contained in executable libraries. Examples Notes --------------------------------------------------------------------------------------- DATA a,b,c,d/3.0,3.1,3.2,3.3/ The values 3.0, 3.1, 3.2, and 3.3 are assigned to a, b, c, and d, respectively. DIMENSION i(3) All three elements of i are assigned an DATA i/3*2/ initial value of 2. DIMENSION i(3) All three elements of i are assigned an DATA i(1)/2/i(2)/2/i(3)/2/ initial value of 2. Equivalent to the previous example. DIMENSION i(3) All three elements of i are assigned an DATA i(1),i(2),i(3)/2,2,2/ initial value of 2. Equivalent to the previous two examples. PARAMETER (init_val = -1) Each element of m is assigned an initial DIMENSION m(10) value of init_val that is a named constant DATA m/10*init_val/ previously defined in a PARAMETER statement. Implied DO Loops in DATA Statements The implied DO loop in a DATA statement acts like the implied DO loop in an input/output statement. It is executed at compilation time to initialize parts of arrays or generate a full variable list. The format of an implied DO loop in a DATA statement is shown below:
[]
----------------------------------------------------------------------------------------------- | | | | | Item | Description/Default | Restrictions | | | | | ----------------------------------------------------------------------------------------------- | | | | | implied_do_list | Data list in the form of an | Can contain other nested implied | | | implied DO loop. | DO loops. | | | | | ----------------------------------------------------------------------------------------------- | | | | | index | Variable that controls the number | None. | | | of times the elements in | | | | substring_name, | | | | array_element_name, or | | | | implied_do_list are read or | | | | written. | | | | | | ----------------------------------------------------------------------------------------------- | | | | | init | Integer expression that is the | init can use only constants and | | | initial value given to index at | the indexes of outer loops. | | | the start of the execution of the | | | | implied DO loop. | | | | | | ----------------------------------------------------------------------------------------------- | | | | | limit | Integer expression that is the | limit can use only constants and | | | termination value for index. | the indexes of outer loops. | | | | | ----------------------------------------------------------------------------------------------- | | | | | step | Integer expression that is the | step can use only constants and | | | increment by which index is | the indexes of outer loops. step | | | changed after each execution of | should not equal 0. If it does, | | | the DO loop; step can be positive | an error occurs, as setting step | | | or negative. Its default value is | equal to 0 can cause the loop to | | | one. | be skipped entirely. | | | | | ----------------------------------------------------------------------------------------------- The index can be used in expressions for subscript values or position specifiers of character substrings. Inner implied DO loops can use the indexes of outer loops. The iteration count in an implied DO loop in a DATA statement must be positive. Examples Notes --------------------------------------------------------------------------------------- DIMENSION i(3) An implied DO loop assigns an initial value DATA (i(k),k=1,3)/3*2/ of 2 to all three elements of i. Equivalent to the previous three examples. CHARACTER k(10,5) Two nested implied DO loops assign the DATA ((k(i,j),j=1,5),i=1,10)/50*'x'/ literal character x to each element in an array of 50 elements, k(10,5).


MPE/iX 5.0 Documentation