Declares an allocatable array with deferred shape.
Syntax
The syntax of a type declaration statement with the ALLOCATABLE
attribute is:
type, attrib-list :: entity-list |
- type
is a valid type specification (INTEGER,
REAL, LOGICAL, CHARACTER,
TYPE(type-name),
etc.), as described in Chapter 3 “Data types and data objects”.
- attrib-list
is a comma-separated list of attributes including
ALLOCATABLE and
optionally those attributes compatible with it, namely:
- entity-list
is a comma-separated list of entities. Each entity
is of the form:
array-name [( deferred-shape-spec-list )] |
If ( deferred-shape-spec-list
) is omitted,
it must be specified in another declaration statement.
- array-name
is the name of an array being given the attribute
ALLOCATABLE.
- deferred-shape-spec-list
is a comma-separated list of colons, each colon
representing one dimension. Thus the rank of the array is equal
to the number of colons specified.
The syntax of the ALLOCATABLE
statement is:
ALLOCATABLE [::] array-name [(deferred-shape-spec-list)] |
[,array-name [(deferred-shape-spec-list)]]... |
If (deferred-shape-spec-list)
is omitted from the ALLOCATABLE
statement, it must be specified in another declaration statement,
such as a type or DIMENSION
statement.
The ALLOCATED
intrinsic inquiry function is described in “ALLOCATED(ARRAY)”. It can be used to determine whether an
allocatable array is currently allocated.
Description
The ALLOCATABLE
attribute or statement is used to declare an array whose extents
in all its dimensions will be specified when an ALLOCATE
statement is executed at run-time; for this reason it is known as
"deferred-shape". When an allocatable array is
declared, only its name and rank are given.
Examples
The following statements declare a rank-one deferred-shape
array and illustrate its use with different extents.
! mls is deferred shape. INTEGER, ALLOCATABLE :: mls(:) ALLOCATE (mls (3)) ! Allocate 3 elements. DEALLOCATE (mls) ! mls is no longer allocated ALLOCATE (mls (-n:n)) ! Allocate with different extent |
Related statements
ALLOCATE
and DEALLOCATE
Related concepts
See “Allocatable arrays” for
more information about allocatable arrays and the conditions applying
to their use.
Array pointers provide a more general mechanism for the manipulation
of deferred-shape arrays; see “Array pointers”.