Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP Fortran Compiler for HP-UX: HP Fortran Programmer's Reference > Chapter 4 Arrays

Array fundamentals

» 

Technical documentation

Complete book in PDF
» Feedback
Content starts here

 » Table of Contents

 » Glossary

 » Index

An array consists of a set of elements, each of which is a scalar and has the same type and type parameter as declared for the array. Elements are organized into dimensions. Fortran 90 allows arrays up to seven dimensions. The number of dimensions in an array determines its rank.

Dimensions have an upper bound and a lower bound. The total number of elements in a dimension—its extent—is calculated by the formula:

upper-bound - lower-bound + 1

The size of an array is the product of its extents. If the extent of any dimension is zero, the array contains no elements and is a zero-sized array.

Elements within an array are referenced by subscripts—one for each dimension. A subscript is a specification expression and is enclosed in parentheses. As an extension, HP Fortran allows a subscript expression of type real; the expression is converted to type integer after it has been evaluated.

The shape of an array is determined by its rank and by the extents of each dimension of the array. An array’s shape may be expressed as a vector where each element is the extent of the corresponding dimension. For example, given the declaration:

REAL, DIMENSION(10,2,5) :: x

the shape of x can be represented by the vector [10, 2, 5].

Two arrays are conformable if they have the same shape, although the lower and upper bounds of the corresponding dimensions need not be the same. A scalar is conformable with any array.

A whole array is an array referenced by its name only, as in the following statements:

REAL, DIMENSION(10) :: x, y, z
PRINT *, x
x = y + z

The array element order used by HP Fortran for storing arrays is column-major order; that is, the subscripts along the first dimension vary most rapidly, and the subscripts along the last dimension vary most slowly. For example, given the declaration:

INTEGER, DIMENSION(3,2) :: a

the order of the elements would be:

a(1,1)
a(2,1)
a(3,1)
a(1,2)
a(2,2)
a(3,2)

The following array declarations illustrate some of the concepts presented in this section:

! The rank of a1 is 1 as it only has one dimension, the extent of
! the single dimension is 10, and the size of a1 is also 10.
! a1 has a shape represented by the vector [10].
REAL, DIMENSION(10) :: a1

! a2 is declared with two dimensions and consequently has a rank
! of 2, the extents of the dimensions are 2 and 4
! respectively,and the size of a2 is 8.
! The array’s shape can be represented by the vector [2, 4].
INTEGER, DIMENSION(2,4) :: a2

! a3 has a rank of 3, the extent of the first two dimensions is
! 5,and the extent of the third dimension is zero. The size of
! a3 is the product of all the extents and is therefore zero.
! The shape of a3 can be represented by the vector [5, 5, 0].
LOGICAL, DIMENSION(5,5,0) :: a3

! a and b are conformable, c and d are conformable. The shape of
! a and b can be represented by the vector [3, 4]. The shape of
! c and d can be represented by the vector [6, 8].
REAL, DIMENSION :: a(3,4), b(3,4), c(6,8), d(-2:3,10:17)
Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© Hewlett-Packard Development Company, L.P.