The DIMENSION statement specifies the number of dimensions for an array, including the number of elements in each dimension.
Optionally, the DIMENSION statement initializes items with values.
Parameter |
Description |
a |
Name of an array |
d |
Specifies the dimensions of the array. It is a list of 1 to 7 declarators separated by commas. |
This section contains descriptions for the dimension declarator and the arrays.
The lower and upper limits of each dimension are designated by a dimension declarator. The form of a dimension declarator is:
[ dd1 :] dd2 |
dd1 and dd2 are dimension bound expressions specifying the lower- and upper- bound values. They can be arithmetic expressions of type integer or real. They can be formed using constants, symbolic constants, formal arguments, or variables defined in the COMMON statement. Array references and references to user-defined functions cannot be used in the dimension bound expression. dd2 can also be an asterisk. If dd1 is not specified, a value of one is assumed. The value of dd1 must be less than or equal to dd2.
Nonconstant dimension-bound expressions can be used in a subprogram to define adjustable arrays, but not in a main program.
Noninteger dimension bound expressions are converted to integers before use. Any fractional part is truncated.
If the dimension declarator is an arithmetic expression that contains formal arguments or variables defined in the COMMON statement, then the array is called an adjustable array. In such cases, the dimension is equal to the initial value of the argument upon entry into the subprogram.
The array is called an assumed-size array when the dimension declarator contains an asterisk. In such cases, the upper bound of that dimension is not stipulated. An asterisk can only appear for formal arrays and as the upper bound of the last dimension in an array declarator.
Example 1: Arrays in a main program:
DIMENSION M(4,4), V(1000) ... END
In the above example, M is specified as an array of dimensions 4 ¥4 and V is specified as an array of dimension 1000.
Example 2: An adjustable array in a subroutine:
SUBROUTINE INV( M, N ) DIMENSION M( N, N ) ... END
In the above example, the formal arguments are an array, M, and a variable N. M is specified to be a square array of dimensions N¥ N.
Example 3: Lower and upper bounds:
DIMENSION HELIO (-3:3, 4, 3:9) ... END
In the above example, HELIO is a 3-dimensional array. The first element is HELIO(-3,1,3) and the last element is HELIO(3,4,9).
Example 4: Dummy array with lower and upper bounds:
SUBROUTINE ENHANCE( A, NLO, NHI ) DIMENSION A(NLO : NHI) ... END
PARAMETER ( LO = 1, HI = 9.3 ) DIMENSION A(HI, HI*3 + LO ) ... END
In the above example, A is an array of dimension 9¥28.
Example 6: Adjustable array with noninteger bounds:
SUBROUTINE ENHANCE( A, X, Y ) DIMENSION A(X : Y) ... END
Example 7: Assumed-size arrays:
SUBROUTINE RUN(A,B,N) DIMENSION A(*), B(N,*) ...