• Aucun résultat trouvé

ARRAY SECTION (CFT77 EXTENSION)

Dans le document CRAY® COMPUTER SYSTEMS (Page 134-138)

DATA STRUCTURES, STORAGE,

4.3.10 ARRAY SECTION (CFT77 EXTENSION)

An array section is a group of elements, within an array, that can be used as an operand in an array expression (see 4.3.11). An array section name has the same form as an array element name, except that one or more subscript expressions are replaced by section selectors, each of which specifies an entire dimension or part of a dimension. The simplest form of a section selector is a colon, which specifies a whole dimension.

Example:

Array declarator: A(4,3,2) Array section name: A(:,2,:)

The above section name specifies an array section with two dimensions.

The section's first dimension corresponds with A's first dimension, and the second with A's third dimension. All elements of the

resulting array section occupy the second column of A. Elements of A that are part of the array section are indicated by XIS in the

following diagram:

In an array section, a dimension's size equals the number of elements selected by the section selector for that dimension. The size of an array section equals the product of its dimension sizes.

4.3.10.1 Uses and restrictions

The following points apply to the use of array sections:

• Array sections can be formed from character arrays (see 3.7.2).

• Array sections are permitted only in assignment statements, on either side of the equal sign.

• Array sections may not be used as actual arguments to external functions or statement functions, but they may be actual arguments to intrinsic functions.

• A section of an assumed-size array is allowed only if the section selector for the last dimension is a subscript expression, an indexed section selector with the upper bound specified, or a vector-valued section selector with a known size.

4.3.10.2 Array section name

The format of an array section name is as follows:

a(s[,s] ... )

a Array name

s Section subscript expression, corresponding to one dimension in an array section. The expression can be a subscript expression, behaving the same as a subscript expression in an array element name, or a section selector. A section selector can be either indexed or vector-valued; see the following text.

4.3.10.3 Indexed section selectors

An indexed section selector is a section subscript expression that selects the elements of one dimension within a certain range and at a certain interval. It takes the following form:

[1]:[u][:i]

1, u

i

Subscript expressions selecting (respectively) the lower and upper bounds for one dimension of an array section. 1 and u must be integer scalar expressions.

1 and u default to the lower and upper bounds for the dimension in the array that contains the array section. 1 and u must be greater than or equal to the array dimension's lower bound and less than or equal to the dimension's upper bound. The upper bound u must be specified for the last dimension of a section of an assumed-size array.

Increment, cannot be 0; default is 1.

A specifier consisting of only a colon uses all defaults and therefore specifies the entire dimension. A specifier of 4:10:2 specifies positions 4, 6, 8, and 10 of a dimension.

An indexed section selector selects the elements from 1 to u in increments of i. Thus the elements selected are 1, l+i, 1+2i, and so on. The total number of elements identified, which must be positive and greater than zero, is given by the following expression:

INT«u-1+i)/i)

Examples:

(1)

( 2 )

REAL D (7,5)

= 0(2:6:2,2:4:2)

The array section name in the second line identifies rows 2 through 6 in increments of 2 (first dimension), and columns 2 through 4 in increments of 2 (second dimension). The following diagram shows the section within the array.

REAL A(10)

t

First Dimension

... =

A(1:10:2)

Second

~ Dimension ~

x

X

X X

X X

The array section name in the second line specifies the following elements:

I

X

I

X X X X

4.3.10.4 Vector-valued section selectors

A vector-valued section selector is the name of a one-dimensional array (not assumed-size), array expression, or array section; i t must be type integer. Vector-valued section selectors allow an array section to include any arbitrary group of array elements.

A vector-valued section selector selects elements in positions given by the elements of the section selector. The elements of the section selector must be greater than or equal to the lower bound of the dimension, and less than or equal to the upper bound. The number of elements selected is equal to the number of elements in the vector-valued section selector.

Example:,

INTEGER A(10), 1(20,20), 81(5), 82(5)

The following are array section names using vector-valued section selectors:

A(81)

The array section's elements are selected by array 81.

A(81+82)

81+82 is an array expression; the resulting array is a vector-valued selector.

A(I(81,3»

Array section 1(81,3) is a one-dimensional array section selected by array 81 from the third column of array I. This array section is in turn a vector-valued section selector for an array section drawn from array A.

A problem occurs when two elements of a vector-valued section selector have the same value. When this occurs, two elements of the specified array section represent the same element of the original array. When an assignment includes such an array section, the order of operations is not guaranteed, leaving some values unpredictable. CFT77 implements array sections as specified in the AN8I Fortran 8X standard, which explicitly allows a reversed order of assignment.

Example:

INTEGER A(5),B(5),C(5),D(5),IX(5) DATA IX/1,2,3,4,41

DO 10, J=1,5 A(J)=J**2

Repeated value

10 CONTINUE B(IX)=A C=B(IX) D=A(IX)

Assignment order not guaranteed

Because IX(4) and IX(5) have the same value, the above array sections cause one element of array A or B to be, in effect, specified twice in the same assignment statement: that is, A(IX(4» and A(IX(5» are both element A(4). When the above code was run, the final values of arrays A, B, C, and D were as shown below; but this result could

change, depending on optimization and the particular release of CFT77.

A:

B:

C:

D:

1 1 1 1

Dans le document CRAY® COMPUTER SYSTEMS (Page 134-138)