An array declarator specifies the name and properties of an array.
The syntax of an array declarator is:
a ( d [, d ] ... )
where:
a is the name of the array
d is a dimension declarator
A dimension declarator has the form:
[ dl:] du
where:
dl is the lower dimension bound
du is the upper dimension bound
An array must appear only once in an array declarator within a program unit (main program, subroutine, function, or block common). The compiler flags multiple or duplicate array declarations within the same unit as errors.
The number of dimensions in an array is the number of dimension declarators. The minimum number of dimensions is one; the maximum is seven. For an assumed-size array, the last dimension can be an asterisk.
The lower bound indicates the first element of the dimension, and the upper bound indicates the last element of the dimension. In a one-dimensional array, these are the first and last elements of the array.
Example: Array declarator, lower and upper bounds:
REAL V(-5:5)
In the above example, V is an array of real numbers, with 1 dimension and 11 elements. The first element is V(-5); the last element is V(5).
Example: Default lower bound of 1:
REAL V(1000)
In the above example, V is an array of real numbers, with 1 dimension and 1000 elements. The first element is V(1); the last element is V(1000).
Example: Arrays can have as many as 7 dimensions:
REAL TAO(2,2,3,4,5,6,10)
Example: Lower bounds other than one:
REAL A(3:5, 7, 3:5), B(0:2)
CHARACTER M(3,4)*7, V(9)*4
The array M has 12 elements, each of which consists of 7 characters.
The array V has 9 elements, each of which consists of 4 characters.
The following restrictions on bounds apply:
Both the upper and the lower bounds can be negative, zero, or positive.
The upper bound must be greater than or equal to the lower bound.
If only one bound is specified, it is the upper, and the lower is one.
In assumed-size arrays, the upper bound of the last dimension is an asterisk.
Each bound is an integer expression, and each operand of the expression is a constant, a dummy argument, or a variable in a common block. No array references or user-defined functions are allowed.
An adjustable array is an array that is a dummy argument or local array@ with one or more of its dimensions or bounds as an expression of integer variables that are either themselves dummy arguments, or are in a common block.
You can declare adjustable arrays in the usual DIMENSION or type statements. In f77, you can also declare adjustable arrays in a RECORD statement, if that RECORD statement is not inside a structure declaration block.
SUBROUTINE POPUP ( A, B, N ) COMMON / DEFS / M, L REAL A(3:5, L, M:N), B(N+1:2*N) ! These arrays are dummy args REAL C(N+1,2*N) ! This array is local
The restrictions are:
The size of an adjustable array cannot exceed the size of the corresponding actual argument.
In the first caller of the call sequence, the corresponding array must be dimensioned with constants.
You cannot declare an adjustable array in COMMON.
If the array is local to the routine, memory is allocated on entry to the routine and deallocated on return to the caller.@
An assumed-size array is an array that is a dummy argument, and which has an asterisk as the upper bound of the last dimension.
You can declare assumed-size arrays in the usual DIMENSION, COMMON, or type statements.
Ihe following f77 extensions allow you to:@
declare assumed-size arrays in a RECORD statement, if that RECORD statement is not inside a structure declaration block.
use an assumed-size array as a unit identifier for an internal file in an I/O statement.
use an assumed-size array as a runtime format specifier in an I/O statement.
Example: Assumed-size with the upper bound of the last dimension an asterisk:
SUBROUTINE PULLDOWN ( A, B, C ) INTEGER A(5, *), B(*), C(0:1, 2:*)
An assumed-size array cannot be used in an I/O list.