next up previous contents index
Next: Using Arrays Up: Arrays Previous: Arrays

Declaring Arrays

  Arrays can have up to seven dimensions; the lower bound of each dimension is one unless declared otherwise. There is no limit on the upper bound provided it is not less than the lower bound. Arrays which are dummy arguments of a procedure may have their dimension bounds specified by integer variables which are arguments of the procedure; in all other cases each dimension bound must be an integer constant expression. This fixes the size of the array at compile-time.   Type, DIMENSION, and COMMON statements may all be used to declare arrays, but COMMON statements have a specialised use (described in section 12). The DIMENSION statement has a similar form to a type statement but only declares the bounds of an array without determining its data type. It is usually simpler and neater to use a type statement which specifies both at once:
CHARACTER COLUMN(5)*25, TITLE*80
Note that when declaring character arrays the string length follows the list of array bounds. The character array COLUMN has 5 elements each of which is 25 characters long; TITLE is, of course, just a variable 80 characters long. Although a default string length can be set for an entire type statement, it is not possible to set a default array size in a similar way.

It is generally good practice to use named constants to specify array bounds as this facilitates later modifications:

 
      PARAMETER (MAXIM = 15) 
      INTEGER POINTS(MAXIM) 
      COMPLEX  SERIES(2**MAXIM)
These arrays all have a lower bound of one. A different lower bound can be specified for any dimension as shown below. The lower and upper bounds are separated by a colon:
 
      REAL TAX(1985:1990), PAY(12,1985:1990) 
      LOGICAL TRIPLE(-1:1, -1:1, -1:1, -1:1)
TAX has 6 elements from TAX(1985) to TAX(1990).
PAY has 72 elements from PAY(1,1985) to PAY(12,1990).
TRIPLE has 81 elements from BIN(-1,-1.-1.-1) to BIN(1,1,1,1).

Although Fortran itself sets no limits to the sizes of arrays that can be defined, the finite capacity of the hardware is likely to do so. In virtual memory operating systems it is possible to use arrays larger than physical memory: those parts of the array not in active use are held on backing store such as a disc file.


next up previous contents index
Next: Using Arrays Up: Arrays Previous: Arrays
Helen Rowlands
8/27/1998