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 />

If there is a LOCATION= specifier, the expression in the specification is evaluated and that value is used as<br />

the address of the array or character variable. This permits the programmer to specify a substitute memory<br />

allocator or to map the array or character variable onto a fixed memory location.<br />

Example:<br />

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

.<br />

.<br />

.<br />

ALLOCATE( A(N) )<br />

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

More than one allocatable array or character variable may appear in an ALLOCATE statement, separated by<br />

commas.<br />

Example:<br />

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

.<br />

.<br />

.<br />

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

If the allocation fails and the STAT= specifier was not used, an execution-time error occurs. If the STAT=<br />

specifier is used, the specified variable returns a zero value if the allocation succeeded, and a non-zero<br />

value if the allocation failed.<br />

Example:<br />

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

.<br />

.<br />

.<br />

ALLOCATE( A(N), B(0:4,5), STAT=IALLOC )<br />

IF( IALLOC .NE. 0 ) PRINT *, ’Allocation failure’<br />

An attempt to allocate a previously allocated array or character variable results in an execution-time error.<br />

If the LOCATION= specifier was not used, the array or character variable must be deallocated first before it<br />

can be allocated a second time (see the DEALLOCATE statement).<br />

An absolute memory location may be specified using the LOCATION= specifier.<br />

Example:<br />

CHARACTER*1 SCREEN(:,:)<br />

N = 80*25<br />

*$IFDEF __386__<br />

ALLOCATE( SCREEN(0:1,0:N-1), LOCATION=’B8000’x )<br />

*$ELSE<br />

ALLOCATE( SCREEN(0:1,0:N-1), LOCATION=’B8000000’x )<br />

*$ENDIF<br />

DO I = 0, N-1<br />

SCREEN(0,I) = ’*’<br />

ENDDO<br />

END<br />

The above example maps the array SCREEN onto the IBM PC colour monitor screen memory and then fills<br />

the screen with asterisks (16-bit real-mode only). The character is stored in SCREEN(0,I) and the<br />

14 ALLOCATE Statement

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

Saved successfully!

Ooh no, something went wrong!