24.11.2014 Views

Open Watcom FORTRAN 77 Language Reference

Open Watcom FORTRAN 77 Language Reference

Open Watcom FORTRAN 77 Language Reference

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Language</strong> <strong>Reference</strong><br />

The following example illustrates a <strong>Open</strong> <strong>Watcom</strong> <strong>FORTRAN</strong> <strong>77</strong> extension.<br />

Example:<br />

REAL A(2,10),B(20),C(2,2,5)<br />

EQUIVALENCE (A(5),B(1)),(B(1),C(1))<br />

In the above example, a single subscript is specified for arrays A and C. The following table shows the<br />

mapping of a 2-dimensional array onto a 1-dimensional array.<br />

A(1,1) == A(1)<br />

A(2,1) == A(2)<br />

A(1,2) == A(3)<br />

A(2,2) == A(4)<br />

A(1,3) == A(5)<br />

A(2,3) == A(6)<br />

.<br />

.<br />

.<br />

In the above table, "==" is read as "is equivalent to". In <strong>FORTRAN</strong>, arrays are stored in "column major"<br />

format (i.e., arrays are stored column by column rather than row by row).<br />

Example:<br />

CHARACTER*5 A, D<br />

EQUIVALENCE (A(3:5), D(1:3))<br />

In this example, the last 3 characters of A occupy the same character storage units as the first 3 characters of<br />

D.<br />

There are certain restrictions on EQUIVALENCE statements. It is not possible to equivalence a storage unit<br />

to 2 different storage units. This is illustrated by the following example.<br />

Example:<br />

* Illegally equivalencing a storage unit to<br />

* 2 different storage units.<br />

DIMENSION A(2)<br />

EQUIVALENCE (A(1),B),(A(2),B)<br />

B has been given 2 different storage units.<br />

It is also not possible to specify that consecutive storage units be non-consecutive. For example,<br />

Example:<br />

* Illegally equivalencing consecutive storage units to<br />

* non-consecutive storage units.<br />

DIMENSION A(2),B(2)<br />

EQUIVALENCE (A(1),B(2)),(A(2),B(1))<br />

A(1) and A(2) are consecutive but B(1) and B(2) are not.<br />

The <strong>FORTRAN</strong> <strong>77</strong> standard specifies that character and numeric data cannot be equivalenced; <strong>Open</strong><br />

<strong>Watcom</strong> <strong>FORTRAN</strong> <strong>77</strong> allows character and numeric data to be equivalenced.<br />

72 EQUIVALENCE Statement

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!