FORTRAN Reference Manual

Language Elements
FORTRAN Reference Manual528615-001
2-16
Array References
Array References
You can reference an entire array using the array name, or you can reference a
specific array element using the array name followed by a subscript. A reference to an
array element takes the following form:
name ( e [, e ]... )
where name is the symbolic name of the array and e is an integer subscript
expression. For example:
CUSTOMERS (2,3,100)
You must specify a value for each dimension of an array when you reference an
element of that array. The following reference is invalid because it specifies only two
dimensions of a three-dimensional array:
REAL inventory(10,31,365)
inventory (1,1) = 234.52
If you refer to an entire array, FORTRAN accesses the elements in the order indicated
in Figure 2-2 on page 2-18.
A subscript can contain function references, but the evaluation of the function must not
alter the value of any other subscript expression in the array. In the following example,
the subscript used in the reference to EVEN NUMBERS includes the variable J:
DIMENSION even numbers (100)
DO 20 j = 1,100
even numbers (j) = j * 2
20 CONTINUE
You can calculate the storage location of an array element using the formulas in
Table 2-5.
Table 2-5. Calculating Array Element Storage Locations (page 1 of 2)
Dimensions Position of Array Element
11 + (s
1
- j
1
)
21 + (s
1
- j
1
) + (s
2
- j
2
) * n
1
31 + (s
1
- j
1
) + (s
2
- j
2
) * n
1
+ (s
3
- j
3
) * n
1
* n
2
41 + (s
1
- j
1
) + (s
2
- j
2
) * n
1
+ (s
3
- j
3
) * n
1
* n
2
+ (s
4
- j
4
) * n
1
* n
2
* n
3
. .
..
..
71 + (s
1
- j
1
) + (s
2
- j
2
) * n
1
+ (s
3
- j
3
) * n
1
* n
2
+ (s
4
- j
4
) * n
1
* n
2
* n
3
+ (s
5
-
j
5
) * n
1
* n
2
* n
3
* n
4
+ (s
6
- j
6
) * n
1
* n
2
* n
3
* n
4
* n
5
+ (s
7
- j
7
) * n
1
* n
2
* n
3
* n
4
* n
5
* n
6