• Aucun résultat trouvé

DATA STATEMENT

Dans le document CRAY® COMPUTER SYSTEMS (Page 142-146)

DATA STRUCTURES, STORAGE,

4.4 DATA STATEMENT

(5)

INTEGER I(lO,12),J(lO,12),K(lO,12),L I

=

MAX(J,K,L)

Each element of array I is assigned the highest among the

corresponding elements in arrays J and K, and scalar variable L.

INTEGER L(5,lO),M(5,lO),N(5,lO),I(5,lO),J L

=

CVMGP(M,N,I)

L

=

CVMGM(M,N,J)

The CVMG intrinsic functions operate on array operands in the same way as do other multi-argument intrinsic functions.

4.4 DATA STATEMENT

The DATA statement provides initial values for variables, arrays, and array elements. A DATA statement can be intermixed with specification statements but must follow type and DIMENSION statements for variables appearing in the DATA statement. Outmoded features of the DATA statement are described in E.6.

Entities appearing in DATA statements are treated as if they had been named in a SAVE statement, even when stack mode is specified.

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

The ANSI Fortran Standard does not specify storage allocation methods.

The format of a DATA statement is as follows:

DATA nlist/clist/[[,)nlist/clist/) ...

nlist

clist

List of variable names, array names, array element names, substring names, and implied-DO lists separated by commas.

Subscript and substring expressions must be integer

constant expressions (see 5.1); subscript expressions can include implied-DO variables. Declaration statements affecting the names in nlist must precede the DATA statement. nlist cannot include names of constants, dummy arguments, functions, entities in blank common, or entities associated with entities in blank common.

List of the form [r*]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 constant c.

Examples:

DATA PI/3.14/, E/2.73/, G/4.77/

DATA C(1),C(2),C(3),C(4),C(5)/1.0,2.0,3*O.O/ C(10)/1.0/

Initial values of the entities are defined by the correspondence between

clist and nlist elements. 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. Counted in this way, the same number of items must be specified by an nlist and its corresponding clist. (See E.6 for an exception to this rule.)

Examples:

(1)

REAL A(5) DATA A/5*O.O/

Array A above has five elements, and the DATA statement assigns zero to each element.

( 2 )

( 3 )

INTEGER J(2,3) DATA J/1,2,3,4,5,61

Array J above has six elements, which are assigned different values in the clist of the DATA statement. That is, J(l,l)=l, J(2,1)=2, J(l,2)=3, J(2,2)=4, J(l,3)=5, and J(2,3)=6.

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

DATA GRID/11.0,21.0,12.0,22.0,13.0,23.01, KBUF/4000*XCONI DATA I/11 K/20001

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

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

The above code shows the interaction of several specification statements with DATA statements. Notice that NEG is defined in a PARAMETER statement and used in the last DATA statement.

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 arrays. The following format represents one item in an

nlist as shown in the DATA statement format; the values assigned are contained in a subsequent clist.

(dlist, dvar

=

init,lim[,incr])

dlist

dvar

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. dvar is initially defined with init and is incremented by incr on each iteration of the loop. The range of this variable is dlist; that is, i t does not conflict with other uses of the same name. dvar must be used in the subscript list of every array referenced in

dlist.

init, lim, and incr

Initial value, limit, and increment of the implied-DO variable; must be integer constant expressions (see 5.1), which can contain references to dvar. The expressions can contain implied-DO variables of other implied-DO lists containing this implied-DO list within their ranges.

incr cannot be zero, and defaults to 1.

The range of an implied-DO list is the list dlist. The trip count and values of the implied-DO variable dvar are established as for a DO-loop except that the trip count must be positive. Interpretation of an implied-DO list in a DATA statement causes each item in the list dlist to be specified once for each iteration, so that appropriate values are substituted where implied-DO variables are referenced.

Examples:

(1)

REAL A(25)

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

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

(2)

INTEGER J(100)

DATA (J(I),J(I-1),I=5,100,5)/10*O,10*l,10*0,10*11

The implied-DO in the above DATA statement selects 40 elements of array J and assigns values of 0 and 1 to them in groups of ten each.

( 3)

DIMENSION A(5), B(5)

DATA «A(I),B(I»,I=1,5)/10*0.01 ! Incorrect format

The implied-DO list in the above DATA statement is incorrect. The list of array element names (A(I),B(I» is treated as a single complex variable.

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 5-3.

The type of the nlist entity and that of the clist constant must agree when either is of type character or logical. (An exception for

If the length of a character entity in nlist is greater than the length of the corresponding clist 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.

4.4.3 ENTITIES THAT CAN APPEAR IN A DATA STATEMENT

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 automatic array or an element of an automatic array

• An entity in blank common or task common

The ANSI Fortran Standard does not permit a DATA statement to initialize entities in named common blocks except in block data subprograms.

Dans le document CRAY® COMPUTER SYSTEMS (Page 142-146)