Statement and Attribute: 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:
Description
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.
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.
See Also
Type declaration statements, Compatible attributes, DEALLOCATE, Arrays, Allocation of Allocatable Arrays, SAVE
Examples
!Method for creating and allocating deferred-shape arrays.
INTEGER, ALLOCATABLE :: matrix(:,:)
REAL, ALLOCATABLE :: vector(:)
...
ALLOCATE(matrix(3,5),vector(-2:N+2))
...
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