XL Fortran for AIX 8.1

Language Reference



The DATA statement provides initial values for variables.


         | '-,-'                                      |
         V                                            |

is a variable or an implied-DO list. Any subscript or substring expression must be an initialization expression.

implied-DO list

>>-(--do_object_list--,--do_variable-- = ----------------------->

is an array element, scalar structure component, substring, or implied-DO list

is a named scalar integer variable called the implied-DO variable. This variable is a statement entity.

integer_expr1, integer_expr2,  and  integer_expr3
are each scalar integer expressions. The primaries of an expression can only contain constants or implied-DO variables of other implied-DO lists that have this implied-DO list within their ranges. Each operation must be intrinsic.


   '-r-- * -'


is a nonnegative scalar integer constant. If r is a named constant, it must have been declared previously in the scoping unit or made accessible by use or host association.

+---------------------------------Fortran 95---------------------------------+

r is also a nonnegative scalar integer subobject of a constant. Similar to the above paragraph, if it is a subobject of a named constant, it must have been declared previously in the scoping unit or made accessible by use or host association.

+-----------------------------End of Fortran 95------------------------------+

If r is a subobject of a constant, any subscript in it is an initialization expression. If r is omitted, the default value is 1. The form r*data_value is equivalent to r successive appearances of the data value.

is a scalar constant, signed integer literal constant, signed real literal constant, structure constructor, FORTRAN 95 Begins scalar subobject of a constant, or NULL(). FORTRAN 95 Ends


Specifying a non-pointer array object as a data_object is the same as specifying a list of all the elements in the array object in the order they are stored.

+---------------------------------Fortran 95---------------------------------+

An array with pointer attribute has only one corresponding initial value which is NULL().

+-----------------------------End of Fortran 95------------------------------+

Each data_object_list must specify the same number of items as its corresponding initial_value_list. There is a one-to-one correspondence between the items in these two lists. This correspondence establishes the initial value of each data_object.

+---------------------------------Fortran 95---------------------------------+

For pointer initialization, if the data_value is NULL() then the corresponding data_object must have pointer attribute. If the data_object has pointer attribute then the corresponding data_value must be NULL().

+-----------------------------End of Fortran 95------------------------------+

The definition of each data_object by its corresponding initial_value must follow the rules for intrinsic assignment, except as noted under Using Typeless Constants.

If initial_value is a structure constructor, each component must be an initialization expression. If data_object is a variable, any substring, subscript, or stride expressions must be initialization expressions.

If data_value is a named constant or structure constructor, the named constant or derived type must have been declared previously in the scoping unit or made accessible by use or host association.

Zero-sized arrays, implied-DO lists with iteration counts of zero, and values with a repeat factor of zero contribute no variables to the expanded initial_value_list, although a zero-length scalar character variable contributes one variable to the list.

You can use an implied-DO list in a DATA statement to initialize array elements, scalar structure components and substrings. The implied-DO list is expanded into a sequence of scalar structure components, array elements, or substrings, under the control of the implied-DO variable. Array elements and scalar structure components must not have constant parents. Each scalar structure component must contain at least one component reference that specifies a subscript list.

The range of an implied-DO list is the do_object_list. The iteration count and the values of the implied-DO variable are established from integer_expr1, integer_expr2, and integer_expr3, the same as for a DO statement. When the implied-DO list is executed, it specifies the items in the do_object_list once for each iteration of the implied-DO list, with the appropriate substitution of values for any occurrence of the implied-DO variables. If the implied-DO variable has an iteration count of 0, no variables are added to the expanded sequence.

Each subscript expression in a do_object can only contain constants or implied-DO variables of implied-DO lists that have the subscript expression within their ranges. Each operation must be intrinsic.

+-------------------------------IBM Extension--------------------------------+

To initialize list items of type logical with logical constants, you can also use the abbreviated forms (T for .TRUE. and F for .FALSE.). If T or F is a constant name that was defined previously with the PARAMETER attribute, XL Fortran recognizes the string as the named constant and assigns its value to the corresponding list item in the DATA statement.

+----------------------------End of IBM Extension----------------------------+

In a block data program unit, you can use a DATA statement or type declaration statement to provide an initial value for a variable in a named common block.

In an internal or module subprogram, if the data_object is the same name as an entity in the host, and the data_object is not declared in any other specification statement in the internal subprogram, the data_object must not be referenced or defined before the DATA statement.

A DATA statement cannot provide an initial value for:

You must not initialize a variable more than once in an executable program. If you associate two or more variables, you can only initialize one of the data objects.


Example 1:

      INTEGER Z(100),EVEN_ODD(0:9)
      DATA    FIRST_TIME / .TRUE. /
      DATA    Z  / 100* 0 /
! Implied-DO list
      DATA  (EVEN_ODD(J),J=0,8,2) / 5 * 0 /  &
    &      ,(EVEN_ODD(J),J=1,9,2) / 5 * 1 /
! Nested example
      DIMENSION TDARR(3,4)  ! Initializes a two-dimensional array
      DATA ((TDARR(I,J),J=1,4),I=1,3) /12 * 0/
! Character substring example
      DATA (CHARARR(J)(1:3),J=1,1) /'aaa'/
      DATA (CHARARR(J)(4:7),J=1,1) /'bbbb'/
      DATA (CHARARR(J)(8:10),J=1,1) /'ccc'/
! CHARARR(1) contains 'aaabbbbccc'

Example 2:

      INTEGER :: COUNT(2)
DATA A /SPARM(2)%COUNT(2) * 10/

Related Information

[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]