• Aucun résultat trouvé

PARAMETER STATEMENT

Dans le document CRAY® COMPUTER SYSTEMS (Page 119-125)

DATA STRUCTURES, STORAGE,

4.1.1 PARAMETER STATEMENT

A PARAMETER statement assigns a symbolic name to a constant. Because this value is established at compile time, it can be used in optimization.

p

e

PARAMETER (p=e[,p=e] •.. )

Symbolic name of a constant; must be integer, real, double precision, complex, or logical. Pointers are not allowed.

Constant expression (see section 5 introduction); cannot include a function reference or array reference. In an exponentiation expression x**y, y must be an integer.

Other requirements are referenced in the next paragraph.

If the data type of p is arithmetic, e must be an arithmetic constant expression (see 5.1). If

P

is of type character, e must be a character constant expression (see 5.2). If P is of type logical, e must be a logical constant expression (see 5.4). Any symbolic name in e must be a constant that has been defined in the same or an earlier PARAMETER

statement.

Type conversion of a constant expression in a PARAMETER statement follows the same rules used for assignment statements (see table 5-1). The type of a symbolic name in a PARAMETER statement is specified by a previous type statement or IMPLICIT statement, or by default.

The length of a character constant must be specified in a type statement or an IMPLICIT statement before the first appearance of its name.

Otherwise, the length is assumed to be one. The length cannot be changed by subsequent statements. If the length is specified as (*), the

parameter length is the length of the actual character string.

A symbolic name can be assigned a constant value only once in a program unit. Constants named in a PARAMETER statement can be referenced in any subsequent statement in the same program unit except in a format

specification or to form a part of any other constant, such as either part of a complex constant.

Examples:

PARAMETER (PI=3.1415926, SPEED=1.86E5) IMPLICIT LOGICAL(O)

PARAMETER (ON=.TRUE.,OFF=.FALSE.) CHARACTER *(9) TITLE

PARAMETER (TITLE='CHAPTER 1') CHARACTER

*

(*) STRING

PARAMETER (STRING='THIS IS TOO LONG TO COUNT')

COMPLEX Z

PARAMETER (Z = (1.0,2.0)/(7.0,8.0»

PARAMETER (FBASE=32, F=98.6, C=9./5.*(F-FBASE»

In the last example, FBASE is initialized first, then used later within the same PARAMETER statement in an expression to initialize C.

4.2 VARIABLES

A variable is a name whose value can be changed during program execution;

it is unsubscripted and is not an array or array element. The term subscripted variable is used in some books to apply to an array element;

this is not an ANSI term and is not used in this manual. Scalar and simple variables are merely variables as defined above, as distinguished from arrays or array elements. A variable name is local to a program unit (see 2.1.5).

Storage of a variable can be static or stack, as specified by the alloc or ALLOC option and the ALLOC directive. Storage allocation is discussed in subsection 4.5.2.

A variable has one data type throughout a program, as specified by the rules governing symbolic names (see 3.1). If a variable's type is implied

by its name, the variable is not required to be declared before it appears in an executable statement, but it must have a value before being used in an expression. Definition of a variable value is discussed in 4.5.3.

A variable can have the same name as a common block. A variable or common block can have the same name as a dummy argument of a statement function, but the dummy argument name is local to the statement function definition statement. The data type (and, if type character, the length) is the same in all of these uses, except for use as a common block name •

. A variable name has the following restrictions:

• It cannot appear in a PARAMETER, INTRINSIC, or EXTERNAL statement.

• It cannot be the name of an array, subroutine, main program, or block data subprogram; the entry name in an ENTRY statement; nor a NAMELIST group name.

4.3 ARRAYS

An array is a nonempty, ordered sequence of data items, called array elements, that occupy consecutive locations in storage. An array name is the symbolic name of an array and obeys the data typing rules used for other symbolic names; all elements of a given array are of one type. An array element name identifies one element and consists of an array name with a subscript indicating the element's position within the array. Each subscript expression corresponds to an array dimension. An array

declarator is a list item that specifies an array's symbolic name and the size of each dimension of the array.

Example:

One-dimensional array IFOUR has four elements. Its declarator in a type statement is INTEGER IFOUR(4). Its third element is IFOUR(3).

An array name with no subscript identifies the entire array in contexts that allow such use (see 4.3.9). In an EQUIVALENCE statement, an array name with no subscript identifies the first element of the array.

An array element substring is a character substring of a character array element (see 3.7.2).

An array is classified as dummy, pointee, or actual, depending on its relation to storage; and as constant-size, adjustable, or assumed-size depending on how its size is determined. Table 4-1 shows the possible combinations of these categories. An X indicates that the indicated pair is valid, such as actual and constant-size. The position of the word Automatic shows that this term applies to an array that is both

adjustable and actual; this usage is a CFT77 extension.

Table 4-1. Possible Kinds of Arrays

Actual Dummy Pointee

Constant-size X X X

Adjustable Automatic X X

Assumed-size X X

4.3.1 DUMMY, ACTUAL, AND POINTEE ARRAYS

An array is classified as dummy, pointee, or actual, depending on its use as a dummy argument, a pointee, or neither. These uses determine how an array is stored.

An actual array is allocated storage and is not a dummy or pointee array.

It can appear in the main program or in procedure subprograms and can be constant-size or automatic (see 4.3.3).

A dummy array appears as a dummy argument in a procedure subprogram; i t is associated with an actual array or array element through one or more procedure calls. A dummy array can be constant-size, adjustable, or assumed-size. See 4.3.8 concerning arrays as arguments.

Example:

PROGRAM

REAL ACTARR(10) CALL SUBRTN (ACTARR)

SUBROUTINE SUBRTN (DUMARR) REAL DUMARR(10)

Actual array ACTARR above is used as an argument in the call to

subroutine SUBRTN. The subroutine declares dummy array DUMARR, which becomes associated with ACTARR. Storage for ACTARR is allocated by the calling program unit; this same storage is accessed by references to DUMARR during the call to SUBRTN.

A pointee array is the object of a pointer (see 3.9); i t can be constant, adjustable, or assumed-size but cannot be a dummy argument. It is not allocated storage; rather, its storage begins at the pointer address. The name of a pointee array must appear in a POINTER statement, either alone or as part of the array declarator; the declarator can also appear in a DIMENSION or type statement. Subsection 3.9.2 includes an example in which a pointee array is stored in a common block.

The ANSI Fortran Standard does not provide for pointers or pointee arrays.

4.3.2 CONSTANT, ADJUSTABLE, AND ASSUMED-SIZE ARRAYS

An array is constant-size, adjustable, or assumed-size, depending on how its size is determined. Each category has a corresponding kind of

declarator (see 4.3.5).

A constant-size array has dimensions that do not vary in size; that is, the dimension bounds in the array declarator are arithmetic constant expressions (see 5.1).

An adjustable array is a dummy, pointee, or automatic array whose size is determined during program execution, as specified by the array

declarator. Each reference to a subprogram can specify dimension sizes for an adjustable array in the subprogram; the sizes are constant during subprogram execution. Variables defining adjustable dimension bound expressions (see 4.3.5) can be redefined or become undefined during

execution of the subprogram, with no effect on the bound or on array size.

An assumed-size array is a dummy or pointee array whose last dimension is of an unknown size (specified as "*") that is assumed to be large

enough for all references made to the array. An assumed-size array cannot be used in an I/O statement as an item in an I/O list, as a format

identifier, or as a unit identifier for an internal file. An assumed-size array name cannot be used as a whole array reference (see 4.3.11) but can be used to form an array section (see 4.3.10).

The ANSI Fortran Standard does not provide for array syntax or array sections.

4.3.3 AUTOMATIC ARRAYS (CFT77 EXTENSION)

An automatic array is an actual array, appearing only in a procedure

subprogram, whose size is determined at runtime in the same way as that of an adjustable array. An automatic array is typically needed for scratch storage within a subprogram. Storage- for the array is allocated when the procedure is entered and released on exit. As with an adjustable array dummy argument, an automatic array declaration cannot be changed once i t is evaluated.

The ANSI Fortran Standard does not provide for automatic arrays.

4.3.4 DIMENSION STATEMENT

The DIMENSION statement specifies the symbolic names and dimension specifications of arrays, by means of array declarators. Array

declarators can also appear in COMMON statements, type statements, and POINTER statements.

DIMENSION a(d)[,a(d») ••.

a(d) Array declarator; see 4.3.5, following.

Each symbolic name a appearing in a DIMENSION statement declares a to be an array in that program unit. An array name can appear only once in an array declarator in a program unit.

Dans le document CRAY® COMPUTER SYSTEMS (Page 119-125)