XL Fortran for AIX 8.1

Language Reference


Arrays

An array is an ordered sequence of scalar data. All the elements of an array have the same type and type parameters.

A whole array is denoted by the name of the array:

! In this declaration, the array is given a type and dimension
REAL, DIMENSION(3) :: A
! In these expressions, each element is evaluated in each expression
PRINT *, A, A+5, COS(A)

A whole array is either a named constant or a variable.

Bounds of a Dimension

Each dimension in an array has an upper and lower bound, which determine the range of values that can be used as subscripts for that dimension. The bound of a dimension can be positive, negative, or zero.

+-------------------------------IBM Extension--------------------------------+

In XL Fortran, the bound of a dimension can be positive, negative or zero within the range -(2**31) to 2**31-1. The range for bounds in 64-bit mode is -(2**63) to 2**63-1.

+----------------------------End of IBM Extension----------------------------+

If any lower bound is greater than the corresponding upper bound, the array is a zero-sized array, which has no elements but still has the properties of an array. The lower and upper bounds of such a dimension are one and zero, respectively.

When the bounds are specified in array declarators:

Related Information:

Specification Expressions
LBOUND(ARRAY, DIM)
UBOUND(ARRAY, DIM)

Extent of a Dimension

The extent of a dimension is the number of elements in that dimension, computed as the value of the upper bound minus the value of the lower bound, plus one.

INTEGER, DIMENSION :: X(5)     ! Extent = 5
REAL :: Y(2:4,3:6)             ! Extent in 1st dimension = 3
                               ! Extent in 2nd dimension = 4

The minimum extent is zero, in a dimension where the lower bound is greater than the upper bound.

+-------------------------------IBM Extension--------------------------------+

The theoretical maximum number of elments in an array is 2**31-1 elements in 32-bit mode, or 2**63-1 elements in XL Fortran 64-bit mode. Hardware addressing considerations make it impractical to declare any combination of data objects whose total size (in bytes) exceeds this value.

+----------------------------End of IBM Extension----------------------------+

Different array declarators that are associated by common, equivalence, or argument association can have different ranks and extents.

Rank, Shape, and Size of an Array

The rank of an array is the number of dimensions it has:

INTEGER, DIMENSION (10) :: A     ! Rank = 1
REAL, DIMENSION (-5:5,100) :: B  ! Rank = 2

According to Fortran 95, an array can have from one to seven dimensions.

+-------------------------------IBM Extension--------------------------------+

An array can have from one to twenty dimensions in XL Fortran.

+----------------------------End of IBM Extension----------------------------+

A scalar is considered to have rank zero.

The shape of an array is derived from its rank and extents. It can be represented as a rank-one array where each element is the extent of the corresponding dimension:

INTEGER, DIMENSION (10,10) :: A          ! Shape = (/ 10, 10 /)
REAL, DIMENSION (-5:4,1:10,10:19) :: B   ! Shape = (/ 10, 10, 10 /)

The size of an array is the number of elements in it, equal to the product of the extents of all dimensions:

INTEGER A(5)              ! Size = 5
REAL B(-1:0,1:3,4)        ! Size = 2 * 3 * 4 = 24

Related Information


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]