Intel® Fortran Compiler 16.0 User and Reference Guide

ALLOCATABLE

Statement and Attribute: Specifies that an object 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. Character objects may have deferred length which is determined when the object is allocated.

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)] [[coarray-spec]][, a[(d-spec)] [[coarray-spec]]...

Statement:

ALLOCATABLE [::] a[(d-spec)] [[coarray-spec]][, a[(d-spec)] [[coarray-spec]]...

type

Is a data type specifier.

att-ls

Is an optional list of attribute specifiers.

a

Is the name of the allocatable object.

d-spec

Is a deferred-shape specification (: [, :] ...), where each colon represents a dimension of the array or a deferred-coshape specification.

coarray-spec

Is a deferred-coshape specification. The left bracket and right bracket are required.

Description

A character object declaration uses LEN=: to indicate it is deferred length.

If the array is given the DIMENSION attribute elsewhere in the program, it must be declared as a deferred-shape array.

When the allocatable object is no longer needed, it can be deallocated by execution of a DEALLOCATE statement.

An allocatable object cannot be specified in a COMMON, EQUIVALENCE, DATA, or NAMELIST statement.

Allocatable objects are not saved by default. If you want to retain the values of an allocatable object across procedure calls, you must specify the SAVE attribute for the object.

Example

  ! Method for creating and allocating deferred-shape objects.

    INTEGER, ALLOCATABLE :: matrix(:,:)
    REAL, ALLOCATABLE    :: vector(:)
    CHARACTER, ALLOCATABLE :: c1
    CHARACTER(LEN=:), ALLOCATABLE :: c2, c3(:)

    ALLOCATE(matrix(3,5),vector(-2:N+2))
    ALLOCATE(c1)
    ALLOCATE(character(len=5) :: c2)
    ALLOCATE(character(len=3) :: c3(2:4))
    ...

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

See Also