• Aucun résultat trouvé

Declaring variables

Dans le document hA pubs\latex\fpe\edl\...) (Page 43-47)

Variables and arrays

6.1 Declaring variables

6.1.1 Implicit type, data-length and mode specification

You do not need to declare scalar variables explicitly within a FORTRAN-PLUS program unit; the variable name can simply appear in an executable statement within the program unit, provided that you do not use the same name for any other item in the program unit other than a COMMON block. If the program unit is a function subprogram, the function name (see section 10.1.2.;) is treated, within the program unit, as a variable name.

You can use the same name as a variable name in another fORTRAN-PLUS program unit, in which case it will refer to a different variable, unless you have associated the variables by COMMON

FORTRAN-PLUS enhanced manlO2.O1 31

association (see chapter 12) or argument association (see section 10.4.3).

If a variable name appears in an executable statement without an explicit type declaration, the type of the variable is determined by the first letter of the variable name. If this is I, J, K, L, M or N, the variable is assumed to be of type integer, otherwise it is assumed to be of type real, unless the IMPLICIT statement has been used. The data-length of the variable is assumed to be 4 bytes, and the mode is assumed to be scalar.

You can use the IMPLICIT statement to change the default type and data-length associated with the initial letter of a variable name. An IMPLICIT statement applies only to the program unit in which it appears and has no effect on the types of any built-in functions or the types of any variables where type is specified explicitly. The statement has the form:

IMPLICIT type *data..length (letters) where:

• type can be INTEGER, LOGICAL, REAL or CHARACTER

• *data_length indicates the number of bytes used to represent real or integer objects (see section 4.4) and can be omitted. *data4engthcannot be used for logical objects and character objects can only have a data-length of 1.

• letters can be a single letter, or a list of letters separated by commas, or a range of letters (which has to appear in alphabetical order, separated by a minus sign). Single letters can be combined with a range

You cannot specify the same initial letter in more than one IMPLICIT statement in the same program unit. If you intend an IMPLICIT statement to affect the type of a name in a PARAME TER statement, the IMPLICIT statement has to come before the PARAMETER statement. The IMPLICIT statement has to appear before the first executable statement in the program unit.

For example:

IMPLICIT REAL*3 (A-H,X,Y)

6.1.2 Explicit declaration

This section describes explicit declaration of variablesdeclaration of arrays is described in section 6.2.

You can specify explicitly the type, data-length and mode of a variable only once in a program unit, although you can specify each attribute in separate non-executable statements. You can specify type, data-length and mode in the following ways:

1. In a type specificationstatement of the form:

type*data_length item1 ,item2,

where type and data-length are as given in section 4.4.

32 manlO2.O1 AMT

6.1. Declaring variables 33

Each item is one of the following:

(a) name/value-list/

(b) vec tor-variable-declarator/value-list/

(c) matrix- variable-declarator/value-list/

where:

• name is the name of the variable

• /value-list/, which is optional, gives the variable or its components initial values and has the format as described in section 6.5 on the DATA statement.

Vector and matrix declarators show that the variable is a vector or matrix and specify the shape (that is, the size of each parallel dimension) of the variable.

A vector-variable-declarator has the form:

n ame(dim1)

A matrix-variable-declaratorhas the form:

name(*dimi, *dim2)

A vector is declared with dim1 components and a matrix with dim1 rows and dim2 columns.

*dimi and *dim9 are referred to as parallel dimension subscriptsand each occupies aparallel subscript position.

Each parallel dimension subscript can be:

• the * symbol followed by an integer constant

• the * symbol followed by an integer scalar variable

• the * symbol followed by a SIZE function call (see sections 10.4.5 and 11.2)

• the * symbol alone (that is, an assumed size dimension)

Unless each dim1 is an integer constant, the size of the vector or matrix is determined only at run-time; the vector or matrix is said to be dynamically-sized.

The * symbol indicates a parallel dimension (that is, the object is a vector or matrix). The non-parallel dimensions in an array declaration (see section 6.2) do not have the * symbol.

The*symbol alone indicates an assumed sizeparallel dimension; that is, a parallel dimension whose size is determined in the declaration of the actual variable elsewhere. A vector or matrix with an assumed size dimension must be in the dummy argument list (see section 10.4.1) of the subprogram in which the declarator appears.

An integer scalar variable used as dim1 has to be of data-length 4 bytes and has to refer either to an item in the dummy argument list (see section 10.4.1) of the subprogram in which the array declarator appears or to entries in a COMMON block in that subprogram, If any parallel dimension is of assumed size the declarator has to refer to an object itself in the dummy argument list; at run-time the actual sizes will be determined from those of the passed matrix or vector. Dynamically-sized vectors and matrices cannot appear in COMMON, DATA or EQUIVALENCE statements or be given initial values with a value list.

FORTRAN-PL US enhanced man 102.01 33

Examples:

INTEGER*1 I1/1/,VEC1(*100),VEC2(*N)

REAL MAT1(*50,*500), MAT2(*SIZE(MAT3, 1) ,*SIZE(MAT3,2)),MAT3(*,*)

MAT3has to be a dummy argument because its dimensions are assumed size (that is, each is denoted by the * symbol alone). N is either a dummy argument or an entry in a COMMON block.

2. In a DIMENSION statement of the form:

DIMENSION declarator1, ... declarator where any declarator1 can be either of:

vector variable declarator matrix variable declarator as defined above.

Note that you specify only the mode of the variable in the DIMENSION statement; you determine the type and data-length of the variable either by a type specification statement see 1(a) above, or implicitly (see section 6.1.1).

You cannot give a variable initial values when declared in this context 3. In a COMMON statement of the form:

COMMON /namei/listi ... /name/list, where each name1 is a COMMON block name.

Eachlist has the form:

item1, item2, ... itemj and each item3 can be any of:

variable name

vector variable declarator matrix variable declarator

If you define the mode in a COMMON statement by a vector or matrix declarator then the name of the object cannot appear in a DIMENSION statement, or as a declarator with dimension subscripts in a type specification statement.

Note that you can specify explicitly only the mode in this context; you determine the type and data-length of the variable either by the appearance of its name (without dimension subscripts) in a type specification statement, or implicitly, using the first letter of its name (see section 6.1.1).

Vectors or matrices in a COMMON statement cannot be dynamically sized; thus the values of the subscripts in the vector variable declarator or matrix variable declarator have to be integer constants.

You cannot give a variable initial values when declared in this context. If a name does not appear in a vector or matrix declarator, it is taken as a scalar. It cannot appear in more than one such declarator in a program unit.

for example:

COMMON/GLOBAL/IMAGE(*512,*512), LINE(*512)

34 manlO2.O1 AMT

Dans le document hA pubs\latex\fpe\edl\...) (Page 43-47)