FORTRAN 77 Language Reference


An array is a named collection of elements of the same type. It is a nonempty sequence of data and occupies a group of contiguous storage locations. An array has a name, a set of elements, and a type.

An array name is a symbolic name for the whole sequence of data.

An array element is one member of the sequence of data. Each storage location holds one element of the array.

An array element name is an array name qualified by a subscript. See "Array Subscripts " for details.

You can declare an array in any of the following statements:

Array Declarators

An array declarator specifies the name and properties of an array.

The syntax of an array declarator is:

a (  d [, d ] ...  )


A dimension declarator has the form:

[ dl:] du


An array must appear only once in an array declarator within a program unit (main program, subroutine, function, or block common). The compiler flags multiple or duplicate array declarations within the same unit as errors.

The number of dimensions in an array is the number of dimension declarators. The minimum number of dimensions is one; the maximum is seven. For an assumed-size array, the last dimension can be an asterisk.

The lower bound indicates the first element of the dimension, and the upper bound indicates the last element of the dimension. In a one-dimensional array, these are the first and last elements of the array.

Example: Array declarator, lower and upper bounds:

	REAL V(-5:5)

In the above example, V is an array of real numbers, with 1 dimension and 11 elements. The first element is V(-5); the last element is V(5).

Example: Default lower bound of 1:

	REAL V(1000)

In the above example, V is an array of real numbers, with 1 dimension and 1000 elements. The first element is V(1); the last element is V(1000).

Example: Arrays can have as many as 7 dimensions:

	REAL TAO(2,2,3,4,5,6,10)

Example: Lower bounds other than one:

	REAL A(3:5, 7, 3:5), B(0:2)

Example: Character arrays:

	CHARACTER M(3,4)*7, V(9)*4

The array M has 12 elements, each of which consists of 7 characters.

The array V has 9 elements, each of which consists of 4 characters.

The following restrictions on bounds apply:

Adjustable Arrays

An adjustable array is an array that is a dummy argument or local array@ with one or more of its dimensions or bounds as an expression of integer variables that are either themselves dummy arguments, or are in a common block.

You can declare adjustable arrays in the usual DIMENSION or type statements. In f77, you can also declare adjustable arrays in a RECORD statement, if that RECORD statement is not inside a structure declaration block.

Example: Adjustable arrays;

	REAL A(3:5, L, M:N), B(N+1:2*N) ! These arrays are dummy args
	REAL C(N+1,2*N)  !  This array is local

The restrictions are:

If the array is local to the routine, memory is allocated on entry to the routine and deallocated on return to the caller.@

Assumed-Size Arrays

An assumed-size array is an array that is a dummy argument, and which has an asterisk as the upper bound of the last dimension.

You can declare assumed-size arrays in the usual DIMENSION, COMMON, or type statements.

Ihe following f77 extensions allow you to:@

Example: Assumed-size with the upper bound of the last dimension an asterisk:

	  INTEGER A(5, *), B(*), C(0:1, 2:*)

An assumed-size array cannot be used in an I/O list.

Array Names with No Subscripts

An array name with no subscripts indicates the entire array. It can appear in any of the following statements:

In an EQUIVALENCE statement, the array name without subscripts indicates the first element of the array.

Array Subscripts

An array element name is an array name qualified by a subscript.

Form of a Subscript

A subscript is a parenthesized list of subscript expressions. There must be one subscript expression for each dimension of the array.

The form of a subscript is:

( s [, s ] )

where s is a subscript expression. The parentheses are part of the subscript.

Example: Declare a two-by-three array with the declarator:

	REAL M(2,3)

With the above declaration, you can assign a value to a particular element, as follows:

	M(1,2) = 0.0

The above code assigns 0.0 to the element in row 1, column 2, of array M.

Subscript Expressions

Subscript expressions have the following properties and restrictions:

In the above example, the fourth element of V is set to zero.

Subscript expressions cannot exceed the range of INTEGER*4 in 32-bit environments. It is not controlled, but if the subscript expression is not in the range (-2147483648, 2147483647), then the results are unpredictable. When compiled for 64-bit environments, INTEGER*8 subscript expressions are allowed.

Array Ordering

Array elements are usually considered as being arranged with the first subscript as the row number and the second subscript as the column number. This corresponds to traditional mathematical nxm matrix notation:





















Element ai,j is located in row i, column j.

For example:

	INTEGER*4 A(3,2) 

The elements of A are conceptually arranged in 3 rows and 2 columns:

A(1,1) A(1,2)
A(2,1) A(2,2)
A(3,1) A(3,2)

Array elements are stored in column-major order.

Example: For the array A, they are located in memory as follows:


The inner (leftmost) subscript changes more rapidly.