 |
» |
|
|
 |
An
object is declared as an array if its declaration includes an array
specifier. An array specifier is enclosed in parentheses and defines
the rank (number of dimensions), or the rank and shape, of the array
and may either follow the DIMENSION
keyword in a type declaration statement or may follow the declaration
of a name. See Chapter 3 and 10 for descriptions of the statements
that can be used to declare arrays. Syntax |  |
In Fortran 90, an array specifier is used to classify
an array as explicit-shape, assumed-shape, deferred-shape, or assumed-size;
these different classes of array are discussed later under the section
“Array categories”. The syntax of an array specifier is: - array-spec
is either a comma separated list of one of the following: or the following: - explicit-shape-spec
[lower-bound :] upper-bound |
- assumed-shape-spec
- deferred-shape-spec
: - assumed-size-spec
[explicit-shape-spec-list,] [lower-bound :] * |
Each
set of bounds defines one dimension of the array, and the number
of sets of bounds defines the rank of the array. If a lower bound
is not specified then the default lower bound for that dimension
is 1. Examples of array specifiers |  |
The following declarations illustrate various forms of an
array specifier. ! x and p have explicit shape, in this example |
! the bounds are constantINTEGER :: ibuff |
! ibuff and obuff are assumed-shape arrays |
INTEGER :: cnts (mdim,ndim) |
! an array with an explicit shape, the bounds |
COMPLEX, ALLOCATABLE, DIMENSION (:,:) :: coords |
! declares an array with deferred shape |
REAL, POINTER :: ptr(:,:,:) |
! a pointer with deferred shape and a rank of |
CHARACTER*5 :: text(10,*) |
! the array text has an assumed size |
Array element storage
order |  |
The sequence in which elements
in an array are stored in memory (the array element order)
is important in certain circumstances, such as: Input and output list items Argument association involving assumed-size or explicit-shape
arrays Certain intrinsic functions (for example, RESHAPE,
TRANSFER, PACK,
and UNPACK) Array constants in array constructors Storage
association (for example, as entailed by use of the COMMON
or EQUIVALENCE
statements)
Array elements are stored in column major order —
that is, the order is columnwise: the subscripts along the first
dimension vary most rapidly, and the subscripts along the last dimension
vary most slowly. Thus the order of the elements in an array declared
with the bounds (3,2)
is (1,1), (2,1),
(3,1), (1,2),
(2,2), (3,2). In general, for an array a
declared as DIMENSION a(1:u1, 1:u2, 1:u3 |
the position of array element a(s1,s2,s3)
is given by the formula s1 + (s2-1) x u1 + (s3-1) x u1 x u2 |
If
the array has more dimensions, the formula is extended accordingly,
as implied by its structure. If the lower bound of any dimension
is not 1, then the formula has to be elaborated slightly, but the
general form is unaffected. Notice that the upper bound of the rightmost dimension (u3)
does not appear. An assumed-size array, described below, is characterized
in its declaration by the rightmost upper bound being given as an
asterisk (*).
This is possible because its value is not needed in order to compute
the position of any array element.
|