Array is an example in Fortran 90 of a compound object (i.e., an object which can have more than one value).
Indices or subscripts must be integers within the range. The smallest and the largest indices or subscripts are referred to as the lower bound and the upper bound, respectively.
where smaller-integer and larger-integer are the lower bound and the upper bound of the extent. Thus, if array indices are in the range of 0 and 11, the extent is 0:11; if array indices are in the range of -3 and 21, the extent is -3:21.smaller-integer : larger-integer
However, if the lower bound of an extent is 1, it can be omitted as well as the colon following it. In our course, complete extents are always used.
where type is the type of the arrays name-1, name-2, ..., name-n, DIMENSION is a required keyword, and extent gives the range of the array indices.type, DIMENSION( extent ) :: name-1, name-2, ..., name-n
For example, suppose we have the following array declarations:
REAL, DIMENSION(-1:1) :: a, Sum INTEGER, DIMENSION(0:100) :: InputData
In the above, the range of array AnswerSheet is 1 and 100, while the range of arrays Score and Mark is -10 and 10.INTEGER, PARAMETER :: MaximumSize = 100 LOGICAL, DIMENSION(1:MaximumSize) :: AnswerSheet INTEGER, PARAMETER :: LowerBound = -10 INTEGER, PARAMETER :: UpperBound = 10 REAL, DIMENSION(LowerBound:UpperBound) :: Score, Mark
where array-name is the name of the array, and integer-expression is an expression whose final result is an integer. The result of integer-expression, which must be an integer in the range of the extent, gives the index or the subscript of the desired array element.array-name ( integer-expression )
Consider array a declared above. Its elements are a(-1), a(0) and a(1). The elements of array InputData are InputData(0), InputData(1), ..., InputData(100). Moreover, if integer variables i and j have values 3 and 8, respectively, InputData(j-i) is equivalent to InputData(5), InputData(i*j) is equivalent to InputData(24), and InputData(j/i) is equivalent to InputData(2).REAL, DIMENSION(-1:1) :: a, Sum INTEGER, DIMENSION(0:100) :: InputData
However, InputData(3.0) is incorrect, since array index or subscript must be integers.
Since indices of an array must be within the lower bound and upper bound of the extent used to declare the array, InputData(20*i+j*j) is equivalent to InputData(124), which is wrong since 124 is larger than the upper bound. Similarly, Sum(i-j) is equivalent to Sum(-5), which is also wrong since -5 is less than the lower bound -1.
The value of the integer-expression used as an index or subscript for an array element must be in the range of the extent used to declare the array.