Intel® Fortran Compiler 16.0 User and Reference Guide

DATA

Statement: Assigns initial values to variables before program execution.

DATA var-list /clist/ [[,] var-list /clist/]...

var-list

Is a list of variables or implied-DO lists, separated by commas.

Subscript expressions and expressions in substring references must be initialization expressions.

An implied-DO list in a DATA statement takes the following form:

( do-list, var= expr1, expr2[, expr3])

do-list

Is a list of one or more array elements, substrings, scalar structure components, or implied-DO lists, separated by commas. Any array elements or scalar structure components must not have a constant parent.

var

Is the name of a scalar integer variable (the implied-DO variable).

expr

Is a list of variables or implied-DO lists, separated by commas.

clist

Is a list of variables or implied-DO lists, separated by commas.

A constant can be specified in the form r*constant, where r is a repeat specification. It is a nonnegative scalar integer constant (with no kind parameter). If it is a named constant, it must have been declared previously in the scoping unit or made accessible through use or host association. If r is omitted, it is assumed to be 1.

Description

A variable can be initialized only once in an executable program. A variable that appears in a DATA statement and is typed implicitly can appear in a subsequent type declaration which may change the implicit typing.

The number of constants in c-list must equal the number of variables in var-list. The constants are assigned to the variables in the order in which they appear (from left to right).

The following objects cannot be initialized in a DATA statement:

Except for variables in named COMMON blocks, a named variable has the SAVE attribute if any part of it is initialized in a DATA statement. You can confirm this property by specifying the variable in a SAVE statement or a type declaration statement containing the SAVE attribute.

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. If the associated constant list does not contain enough values to fill the array, a warning is issued and the remaining array elements become undefined.

Array element values can be initialized in three ways: by name, by element, or by an implied-DO list (interpreted in the same way as a DO construct).

The following conversion rules and restrictions apply to variable and constant list items:

Example

The following example shows the three ways that DATA statements can initialize array element values:

  DIMENSION A(10,10)
  DATA A/100*1.0/    ! initialization by name
  DATA A(1,1), A(10,1), A(3,3) /2*2.5, 2.0/ ! initialization by element
  DATA ((A(I,J), I=1,5,2), J=1,5) /15*1.0/  ! initialization by implied-DO list

The following example shows DATA statements containing structure components:

  TYPE EMPLOYEE
    INTEGER ID
    CHARACTER(LEN=40) NAME
  END TYPE EMPLOYEE
  TYPE(EMPLOYEE) MAN_NAME, CON_NAME
  DATA MAN_NAME / EMPLOYEE(417, 'Henry Adams') /
  DATA CON_NAME%ID, CON_NAME%NAME /891, "David James"/

In the following example, the first DATA statement assigns zero to all 10 elements of array A, and four asterisks followed by two blanks 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/

In this case, 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 list to assign the value 1 to the odd-numbered elements in the array B.

The following shows another example:

    INTEGER n, order, alpha, list(100)
    REAL coef(4), eps(2),
    pi(5), x(5,5)
    CHARACTER*12 help
    COMPLEX*8 cstuff
    DATA  n /0/, order /3/
    DATA  alpha /'A'/
    DATA  coef /1.0, 2*3.0, 1.0/, eps(1) /.00001/
    DATA  cstuff /(-1.0, -1.0)/
!    The following example initializes diagonal and below in
!    a 5x5 matrix:
    DATA  ((x(j,i), i=1,j), j=1,5) / 15*1.0 /
    DATA  pi / 5*3.14159 /
    DATA  list / 100*0 /
    DATA  help(1:4), help(5:8), help(9:12) /3*'HELP'/

Consider the following:

 CHARACTER (LEN = 10) NAME
 INTEGER, DIMENSION (0:9) :: MILES
 REAL, DIMENSION (100, 100) :: SKEW
 TYPE (MEMBER) MYNAME, YOURS
 DATA NAME / 'JOHN DOE' /, miles / 10*0 /
 DATA ((SKEW (k, j), j = 1, k), k = 1, 100) / 5050*0.0 /
 DATA ((SKEW (k, j), j = k + 1, 100), k = 1, 99) / 4950*1.0 /
 DATA MYNAME / MEMBER (21, 'JOHN SMITH') /
 DATA YOURS % age, YOURS % name / 35, 'FRED BROWN' /

In this example, the character variable NAME is initialized with the value JOHN DOE with two trailing blanks to fill out the declared length of the variable. The ten elements of MILES are initialized to zero. The two-dimensional array SKEW is initialized so that its lower triangle is zero and its upper triangle is one. The structures MYNAME and YOURS are declared using the derived type MEMBER. The derived-type variable MYNAME is initialized by a structure constructor. The derived-type variable YOURS is initialized by supplying a separate value for each component.

The first DATA statement in the previous example could also be written as:

 DATA name / 'JOHN DOE' /
 DATA miles / 10*0 /

A pointer can be initialized as disassociated by using a DATA statement. For example:

 INTEGER, POINTER :: P
 DATA P/NULL( )/
 END

See Also