• Keine Ergebnisse gefunden

DATA STATEMENT

Im Dokument COMPUTER SYSTEMS (Seite 124-127)

20 FORMAT ("SAM'S NOT HERE") STOP

4.4 DATA STATEMENT

A DATA statement provides initial values for variables, arrays, and array elements. Only those entities named in DATA statements become defined prior to executable program execution; all other entities are undefined at this time.

A DATA statement can be intermixed with specification statements but must follow type statements for variables appearing in the DATA statement.

Entities appearing in DATA statements are assigned to static storage.

The ANSI FORTRAN standard specifies that the DATA statement follows all specification statements.

The ANSI FORTRAN Standard does not specify storage allocation methods.

Format:

DATA nlistlclistl[[,]nlistlclistl] .•.

nlist

clist

List of variable names, array names, array element names, substring names, and implied-DO lists (described below) separated by commas

List of the form [~*]c[,[r*]c] •••

c Constant or the symbolic name of a constant

r Nonzero, unsigned, integer constant or the symbolic name of such a constant

The r*c form is interpreted to provide r successive values of the constant c.

Elements of arrays named in nlist must be individually accounted for in clist.

Example:

INTEGER I(5) DATA I/5*01

Array I above has five elements, and the DATA statement assigns it five zeros.

Counting as separate items the elements of any arrays in nlist, and counting an r*c entry in clist as r items, the ith item in nlist becomes defined with the ith value from clist. The same number of items must be specified by each nlist and its corresponding clist.

The initial values of the entities are defined by this correspondence.

Exceptions to this rule are shown in appendix E, Outmoded Features.

Each subscript expression in the list nlist must be an integer constant expression except for implied-DO variables. Each substring expression in the list nlist must be an integer constant expression.

Names of constants, dummy arguments, and functions must not appear in nlist. Names of entities in a named common block or in blank common (including entities associated with an entity in blank common) can appear in nlist.

The ANSI FORTRAN Standard does not permit entities in blank common to be initialized in a DATA statement.

If a variable, an array element, or an entity associated with either is defined by a DATA statement more than once in an executable program, the one nearest the end of the program is the only definition to apply.

4.4.1 IMPLIED-DO LIST IN A DATA STATEMENT

An implied-DO list allows a DATA statement to initialize a group of

values systematically as in a DO loop. The implied-DO is used frequently for initializing an array. The following format represents one item in an nlist as shown above; the values assigned are contained in a

subsequent clist.

dlist

i

List of array element names and implied-DO lists separated by commas. dlist cannot contain substring names, even if they are substrings of array elements.

Name of an integer variable called the implied-DO variable

e1' e2' and e3

Integer constant expressions containing only integer constants, the names of integer constants, and implied-DO variables of other implied-DO lists containing this

implied-DO list within their ranges. If omitted, e3 is assumed to be 1.

The range of an implied-DO list is the list dlist. The iteration count and values of the implied-DO variable i are established as for a

DO-loop except that the iteration count must be greater than zero.

Interpretation of an implied-DO list in a DATA statement causes each item in the list dlist to be specified once for each iteration, and for

appropriate values to be substituted where implied-DO variables are referenced.

Each subscript expression in the list dlist must be an integer constant expression except that the expression may contain implied-DO variables of implied-DO lists that have the subscript expressions within their ranges.

Any declaratives affecting the variable or array names in nlist must precede the DATA statement.

Examples:

(1) DIMENSION A(25)

DATA (A(I),I=1,10)/10*11

The first ten values of array A above are set to 1.

(2) DIMENSION GRID (2,3),KBUF(10,200,2) PARAMETER (XCON=6.0)

DATA GRID 111.0,21.0,12.0,22.0,13.0,23.0/,KBUF/4000*XCONI DATA I/1/K/20001

PARAMETER (NEG=-6) INTEGER NB (10)

DATA NB/-3,7*-4,2*NEGI

4.4.2 DATA TYPES IN A DATA STATEMENT

When the nlist entity is of type integer, real, or double-precision, the corresponding clist constant is converted, if necessary, to the type of the nlist entity according to the rules for arithmetic conversion, as shown in table 2-4.

An nlist entity of type logical must correspond to a clist constant of the same type. A clist entity of type logical must correspond to an nlist entity of type logical.

An entity in the list nlist that corresponds to a character constant must be of type character. If the length of the character entity in the

list nlist is greater than the length of its corresponding character constant, the additional rightmost characters in the entity are initially defined with blank characters. If the length of the character entity in the list nlist, is less than the length of its corresponding character constant, the additional rightmost characters in the constant are ignored.

Other rules concerning data tyges in the DATA statement are shown in appendix E, Outmoded Features.

4.4.3 ENTITIES THAT CAN BE DEFINED

Any variable or array element can be initially defined in a DATA statement except for the following.

An entity that is a dummy argument

A variable in a function subprogram whose name is also the name of the function subprogram

• A pointee

• An entity declared to be in BLANK COMMON

Im Dokument COMPUTER SYSTEMS (Seite 124-127)