The DATA statement provides initial values for data objects.
SyntaxDATA data-stmt-set [[,] data-stmt-set] ...Where:
data-stmt-set is object-list / value-list /
object-list is a comma-separated list of variable names or implied-dos.
value-list is a comma-separated list of [repeat *] data-constant
repeat is a scalar INTEGER constant.
data-constant is a scalar constant (either literal or named)
or a structure constructor.
implied-do is (implied-do-object-list , implied-do-var=expr, expr[, expr])
implied-do-object-list is a comma-separated list of array elements, scalar structure components, or implied-dos.
implied-do-var is a scalar INTEGER variable.
expr is a scalar INTEGER expression.
Each object in object-list must have a corresponding value in value-list.
Each value in value-list must be a constant that is either previously defined or made accessible by host or use association. Each constant should be of the same kind as the corresponding object being initialized.
A variable, or part of a variable, must not be initialized more than once in an executable program.
If the type of a variable that is being initialized is not declared prior to its appearance in a DATA statement, it is of default type. Any subsequent declaration of the type of the variable must be of default kind.
A whole array that appears in an object-list is equivalent to a complete sequence of its array elements in array element order. An array section is equivalent to the sequence of its array elements in array element order.
An implied-do is expanded to form a sequence of array elements and structure components, under the control of the implied-do-var, as in the DO construct.
repeat indicates the number of times the following constant is to be included in the sequence; omission of repeat defaults to a repeat factor of 1.
A variable that is initialized in a DATA statement cannot also be any of the following: a dummy argument; accessible by host or use association; in a blank common block; be a function name or function result name; an automatic object; a pointer; or an allocatable array.
Variables that are initialized using the DATA statement in a block data program unit may appear in a named common block. Variables that are initialized using the DATA statement in program units other than block data cannot appear in a named common block.
If an object in an object-list is of type INTEGER, its corresponding value may be a binary, octal, or hexadecimal constant.
Exampleinteger, parameter :: arrsize=100000,init=0 real,parameter :: rinit=0. real :: r1,r2,r3,array1(2,2),array2(arrsize) real(kind(1.d0)) :: r4,r5 complex :: q integer :: l,b,o,z,array3(10) data r1,r2,r3 /1.,2.,3./, array1 /1.,2.,3.,4./ data r4 /1.23456789012345d0/ ! correct initialization data r5 /1.23456789012345/ ! loses precision data array2 /arrsize*rinit/,q /(0.,0.)/ data (array3(l),l=1,10) /10*init/ data b /B'01101000100010111110100001111010'/ data o /O'15042764172'/ data z /Z'688be87a'/ write(*,*) r4,r5