4.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. So, if the first elements of two equal-sized arrays are made equivalent, both arrays share the same storage space. 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:

DIMENSION TABLE (2,2), TRIPLE (2,2,2)
EQUIVALENCE (TABLE(2,2), TRIPLE(1,2,2))

As a result of these statements, the entire array TABLE would share part of the storage space allocated to TRIPLE. Table 4-1 shows how these statements align the arrays.

Table 4-1 Equivalence of Array Storage

Array TRIPLE  Array TABLE 
Array Element  Element Number  Array Element  Element Number 
TRIPLE(1,1,1)     
TRIPLE(2,1,1)     
TRIPLE(1,2,1)     
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) 
TRIPLE(2,2,2)     

Each of the following statements also aligns the two arrays as shown in Table 4-1:

EQUIVALENCE (TABLE, TRIPLE(2,2,1))
EQUIVALENCE (TRIPLE(1,1,2), TABLE(2,1))

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 space allocated to array B. Table 4-2 shows how these statements align the arrays.

Each of the following statements also aligns the arrays as shown in Table 4-2:

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

Table 4-2 Equivalence of Arrays with Nonunity Lower Bounds

Array B  Array A 
Array Element  Element Number  Array Element  Element Number 
B(2,1)     
B(3,1)     
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 a multidimensional array. For example, the following statements align the two arrays as shown in Table 4-2:

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


Previous Page Next Page Table of Contents