Intel® Fortran Compiler Classic and Intel® Fortran Compiler Developer Guide and Reference

ID 767251
Date 7/13/2023
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

DIMENSION

Statement and 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. It can be any of the following:

  • An explicit-shape specification; for example, a(10,10)

  • An assumed-shape specification; for example, a(:)

  • A deferred-shape specification; for example, a(:,:)

  • An assumed-size specification; for example, a(10,*)

  • An assumed-rank specification; for example, a(..)

  • An implicit-shape specification; for example, a(*)

For more information on array specifications, see Declaration Statements for Arrays.

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.

Description

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, AUTOMATIC, COMMON, POINTER, STATIC, TARGET.

Example

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(8), DIMENSION(5,-2:2) :: A,B,C

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)

You can declare arrays by using type statements and ALLOCATABLE attributes and statements, for example:

  INTEGER A(2,0:2)
  COMPLEX F
  ALLOCATABLE F(:,:)
  REAL(8), ALLOCATABLE, DIMENSION( :, :, : ) :: E

You can declare an implicit-shape constant array by using a type statement and a PARAMETER attribute, for example:

  INTEGER, PARAMETER :: R(*) = [1,2,3]

You can also declare arrays by using type and ALLOCATABLE statements, for example:

  INTEGER A(2,0:2)
  COMPLEX F
  ALLOCATABLE F(:,:)
  REAL(8), ALLOCATABLE, DIMENSION( :, :, : ) :: E

You can specify both the upper and lower dimension bounds. If, for example, one array contains data from experiments numbered 28 through 112, you could dimension the array as follows:

  DIMENSION experiment(28:112) 

Then, to refer to the data from experiment 72, you would reference experiment(72).

Array elements are stored in column-major order: the leftmost subscript is incremented first when the array is mapped into contiguous memory addresses. For example, consider the following statements:

  INTEGER(2) a(2, 0:2)
  DATA a /1, 2, 3, 4, 5, 6/

These are equivalent to:

  INTEGER(2) a
  DIMENSION a(2, 0:2)
  DATA a /1, 2, 3, 4, 5, 6/

If a is placed at location decimal 1000 in memory, the preceding DATA statement produces the following mapping.

Array element

Address (decimal)

Value

a(1,0)

1000

1

a(2,0)

1002

2

a(1,1)

1004

3

a(2,1)

1006

4

a(1,2)

1008

5

a(2,2)

100A

6

The following DIMENSION statement defines an assumed-size array in a subprogram:

  DIMENSION data (19,*) 

At execution time, the array data is given the size of the corresponding array in the calling program.

The following program fragment dimensions two arrays:

   ...
   SUBROUTINE Subr (matrix, rows, vector)
   REAL MATRIX, VECTOR
   INTEGER ROWS
   DIMENSION MATRIX (ROWS,*), VECTOR (10),
  +  LOCAL (2,4,8)
   MATRIX (1,1) = VECTOR (5)
   ...