5.6 DIMENSION Attribute and Statement

The DIMENSION attribute specifies that an object is an array, and defines the shape of the array.

The DIMENSION attribute can be specified in a type declaration statement or a DIMENSION statement, and takes one of the following forms:

Type Declaration Statement:

type, [att-ls,] DIMENSION (a-spec) [, att-ls] :: a[(a-spec)] [, a[(a-spec)]]...

Statement:

DIMENSION [::] a(a-spec) [, a(a-spec)]...

type
Is a data type specifier.

att-ls
Is an optional list of attribute specifiers.

a-spec
Is an array specification.

In a type declaration statement, any array specification following an array overrides any array specification following DIMENSION.

a
Is the name of the array being declared.

Rules and Behavior

The DIMENSION attribute allocates a number of storage elements to each array named, one storage element to each array element in each dimension. The size of each storage element is determined by the data type of the array.

The total number of storage elements assigned to an array is equal to the number produced by multiplying together the number of elements in each dimension in the array specification. For example, the following statement defines ARRAY as having 16 real elements of 4 bytes each and defines MATRIX as having 125 integer elements of 4 bytes each:

DIMENSION ARRAY(4,4), MATRIX(5,5,5)

An array can also be declared in the following statements: ALLOCATABLE, POINTER, TARGET, and COMMON.

Examples

The following examples show type declaration statements specifying the DIMENSION attribute:

REAL, DIMENSION(10, 10) :: A, B, C(10, 15)  ! Specification following C
                                            ! overrides the one following
                                            ! DIMENSION
REAL, ALLOCATABLE, DIMENSION(:) :: E

The following are examples of the DIMENSION statement:

DIMENSION BOTTOM(12,24,10)
DIMENSION X(5,5,5), Y(4,85), Z(100)
DIMENSION MARK(4,4,4,4)

SUBROUTINE APROC(A1,A2,N1,N2,N3)
DIMENSION A1(N1:N2), A2(N3:*)

CHARACTER(LEN = 20) D
DIMENSION A(15), B(15, 40), C(-5:8, 7), D(15)

For More Information:


Previous Page Next Page Table of Contents