5.7.1 Making Arrays Equivalent

When you make an element of one array equivalent to an element of another array, the EQUIVALENCE statement also sets equivalences between the other elements of the two arrays. Thus, if the first elements of two equal-sized arrays are made equivalent, both arrays share the same storage. If the third element of a 7-element array is made equivalent to the first element of another array, the last five elements of the first array overlap the first five elements of the second array.

Two or more elements of the same array should not be associated with each other in one or more EQUIVALENCE statements. For example, you cannot use an EQUIVALENCE statement to associate the first element of one array with the first element of another array, and then attempt to associate the fourth element of the first array with the seventh element of the other array.

Consider the following valid example:


These statements cause the entire array TABLE to share part of the storage allocated to TRIPLE. Table 5-3 shows how these statements align the arrays:

Table 5-3 Equivalence of Array Storage

Array TRIPLE   Array TABLE 
Array Element  Element Number  Array Element  Element Number 
TRIPLE(2,2,1)  TABLE(1,1) 
TRIPLE(1,1,2)  TABLE(2,1) 
TRIPLE(2,1,2)  TABLE(1,2) 
TRIPLE(1,2,2)  TABLE(2,2) 

Each of the following statements also aligns the two arrays as shown in Table 5-3:


You can also make arrays equivalent with nonunity lower bounds. For example, an array defined as A(2:3,4) is a sequence of eight values. A reference to A(2,2) refers to the third element in the sequence. To make array A(2:3,4) share storage with array B(2:4,4), you can use the following statement:

EQUIVALENCE(A(3,4), B(2,4))

The entire array A shares part of the storage allocated to array B. Table 5-4 shows how these statements align the arrays. The arrays can also be aligned by the following statements:

EQUIVALENCE(B(3,2), A(2,2))

Table 5-4 Equivalence of Arrays with Nonunity Lower Bounds

Array B   Array A 
Array Element  Element Number   Array Element  Element Number 
B(4,1)  A(2,1) 
B(2,2)  A(3,1) 
B(3,2)  A(2,2) 
B(4,2)  A(3,2) 
B(2,3)  A(2,3) 
B(3,3)  A(3,3) 
B(4,3)  A(2,4) 
B(2,4)  10  A(3,4) 
B(3,4)  11     
B(4,4)  12     

Only in the EQUIVALENCE statement can you identify an array element with a single subscript (the linear element number), even though the array was defined as multidimensional. For example, the following statements align the two arrays as shown in Table 5-4:

DIMENSION B(2:4,1:4), A(2:3,1:4)

Previous Page Next Page Table of Contents