Specifies that an array is an allocatable array with a deferred
shape. The shape of an allocatable array is determined when an
ALLOCATE statement is executed, dynamically allocating space for
the array.
The ALLOCATABLE attribute can be specified in a type declaration
statement or an ALLOCATABLE statement, and takes one of the
following forms:
Type Declaration Statement:
type, [att-ls,] ALLOCATABLE [,att-ls] :: a[(d-spec)] [,a[(d-spec)]]...
Statement:
ALLOCATABLE [::] a[(d-spec)] [,a[(d-spec)]]...
type Is a data type specifier.
att-ls Is an optional list of attribute specifiers.
a Is the name of the allocatable array; it must
not be a dummy argument or function result.
d-spec Is a deferred-shape specification (: [,:]...).
Each colon represents a dimension of the array.
If the array is given the DIMENSION attribute elsewhere in the
program, it must be declared as a deferred-shape array.
When the allocatable array is no longer needed, it can be
deallocated by execution of a DEALLOCATE statement.
During program execution, the allocation status of an allocatable
array is one of the following:
o Not currently allocated
The array was never allocated or the last operation performed
on it was a deallocation. Deallocation is performed:
- Explicitly, by using a DEALLOCATE statement.
- By default, when the allocatable array is a local variable
of a procedure that does not have the SAVE attribute and is
terminated by an END or RETURN statement.
An array that is not currently allocated must not be referenced
or defined.
o Currently allocated
The array was allocated by an ALLOCATE statement. Such an
array can be referenced, defined, or deallocated.
An allocatable array cannot be specified in a COMMON, EQUIVALENCE,
DATA, or NAMELIST statement.
Allocatable arrays are not saved by default. If you want to retain
the values of an allocatable array across procedure calls, you must
specify the SAVE attribute for the array.
The ALLOCATABLE attribute is compatible with the AUTOMATIC,
DIMENSION (with deferred shape), PRIVATE, PUBLIC, SAVE, STATIC,
TARGET, and VOLATILE attributes.
EXAMPLES:
The following example shows a type declaration statement specifying
the ALLOCATABLE attribute:
REAL, ALLOCATABLE :: Z(:, :, :)
The following is an example of the ALLOCATABLE statement:
REAL A, B(:)
ALLOCATABLE :: A(:,:), B