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.

Arrays<br />

3. If the corresponding actual argument is a character array name, character array element or a<br />

substrung character array element which begins at character t of an array with c characters then<br />

the size of the dummy array is INT(( c + 1 − t ) / e) where e is the size of an element of the<br />

dummy array.<br />

If the assumed-size array has dimension n then the product of the first n − 1 dimensions must be less than or<br />

equal to the size of the array as determined by one of the preceding rules. The value of the assumed<br />

dimension is the largest integer such that the product of all of the dimensions is less than or equal to the size<br />

of the dummy array. In the following example, A(4,*) is an assumed-size array declarator.<br />

Example:<br />

DIMENSION B(10)<br />

.<br />

.<br />

.<br />

CALL SQUARE( B )<br />

.<br />

.<br />

.<br />

END<br />

SUBROUTINE SQUARE( A )<br />

DIMENSION A(4,*)<br />

.<br />

.<br />

.<br />

END<br />

By rule 1, the upper bound of the size of A is 10. We now look for the largest integer n such that 4 * n is<br />

less than or equal to 10. Clearly, n is 2. A is therefore a 2-dimensional array with 4 rows and 2 columns.<br />

4.4.4 Allocatable Array Declarator<br />

An allocatable array declarator is one that contains no dimension bound expressions. It is called an<br />

allocatable array declarator because the dimension bounds are specified at run-time in an ALLOCATE<br />

statement.<br />

Example:<br />

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

.<br />

.<br />

.<br />

ALLOCATE( A(N) )<br />

ALLOCATE( B(0:4,5) )<br />

In the previous example, A(:) is a one-dimensional allocatable array declarator and B(:,:) is a<br />

two-dimensional allocatable array declarator. The first ALLOCATE statement is used to allocate the array A<br />

with bounds 1:N. The second ALLOCATE statement is used to allocate the array B with bounds 0:4 in<br />

the first dimension and 1:5 in the second dimension.<br />

Classifying Array Declarators by Dimension Declarator 163

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

Saved successfully!

Ooh no, something went wrong!