A typical INTERLEAVE statement might look like
INTERLEAVE NAME(1),DEDUCT(1,),RTYP(1,2),RADR(1,2)
and, following the following DIMENSION statement,
DIM NAME(10),DEDUCT(10,3),RTYP(10,2),RADR(10,2)
would cause the elements of these four arrays to be stored in memory in the following order:
NAME(1),DEDUCT(1,1),DEDUCT(1,2),DEDUCT(1,3),RTYP(1,1),RADR(1 ,1),RTYP(1,2),RADR(1,2), NAME(2),DEDUCT(2,1),DEDUCT(2,2),DEDUCT(2,3),RTYP(2,1),RADR(2 ,1),RTYP(2,2),RADR(2,2), NAME(3)... ...RADR(10,2)
The general rule in placing array elements with an INTERLEAVE statement is that any unnumbered subscripts are varied over their full range before moving to the next variable in the list. Once the end of the list is reached, the subscript with the highest reference number is incremented until it reaches the end of its range, then the next lower, and so on.
If an exclamation mark occurs within an INTERLEAVE statement instead of a comma as a separator, it creates a pseudo end-of-list for the highest reference number reached to that point, and that reference number may be re-used. Except for such re-use, wherever an reference number is used, it must be used along an array dimension having the same length for each array in relation to which it is used. Thus, for example, reference number 1 is used with dimensions taken to length 10 in the example above, and reference number 2 with dimensions having length 2.
The semicolon can appear in an INTERLEAVE statement. At the end, preceding a variable name, it declares that variable of CHARACTER*n type, where n is the length of each entry in the completed structure; also, parts of an INTERLEAVE statement can be enclosed in parentheses, and a semicolon within them creates a CHARACTER variable encompassing what preceded it in the parentheses.
Reference numbers are needed in the variables thus created (they do not need to be dimensioned elsewhere) when there are multiple records of the same type in the structure. So,
INTERLEAVE NAME(1),DEDUCT(1,), (RTYP(1,2),RADR(1,2);RES(1,2));ALL(1)
causes each element of RES to contain one element each of RTYP and RADR, and each element of ALL contains one element of NAME, three of DEDUCT, two each of RTYP and RADR.
It is not necessary for INTERLEAVE to create an array of records; a single record may also be created, for example,
INTERLEAVE NAME,DEDUCT(),(RTYP(1),RADR(1);RES(1));ALL
is permitted.
Note that the function performed by the ";ALL" at the end of the INTERLEAVE statement could also be performed manually by declaring ALL to be a CHARACTER variable of the appropriate length, and then equivalencing it to NAME. However, making such code hardware-independent would require a long expression to appear as the length specification in the CHARACTER declaration statement.
Note that variables such as ALL in the example above have no special type, but instead have the type CHARACTER*n for the appropriate value of n.
The INTERLEAVE statement accomplishes the same task as the STRUCTURE statement, except that the names of structure elements do not contain periods, or the name of the parent structure in which they are included, and also it does not create a new variable type.
Thus, the statements
CHARACTER*40 UNAME(5) INTEGER UIX(5,3) LOGICAL UFLAG(5,3) INTERLEAVE UNAME(1),UIX(1,2),UFLAG(1,2);UBUFF(1)
achieve somewhat the same result as
STRUCTURE (CHARACTER*40) NAME, (STRUCTURE ((INTEGER) IDX, (LOGICAL) FLAG)) V(3); U(5)
with U.NAME(i) corresponding to UNAME(i), U.V.IDX(i,j) corresponding to UIX(i,j), U.V.FLAG(i,j) corresponding to UFLAG(i,j), and U(i) corresponding to UBUFF(i). However, U has a structured type, while the type of UBUFF is CHARACTER*n with n the appropriate length.
Note that the ordering of subscripts corresponds to the ordering of names; U.V.FLAG has the dimensions (5,3), not (3,5).