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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>FORTRAN</strong> Statements<br />

character attribute (unchanged in this example) is stored in SCREEN(1,I). The column major ordering<br />

of arrays must be taken into consideration when mapping an array onto a fixed area of memory.<br />

The following example is similar but uses an allocatable character variable.<br />

Example:<br />

CHARACTER*(*) SCREEN<br />

INTEGER SCRSIZE, I<br />

PARAMETER ( SCRSIZE = 80*25*2 )<br />

*$IFDEF __386__<br />

ALLOCATE( SCREEN*SCRSIZE, LOCATION=’B8000’X )<br />

*$ELSE<br />

ALLOCATE( SCREEN*SCRSIZE, LOCATION=’B8000000’X )<br />

*$ENDIF<br />

DO I = 1, SCRSIZE, 2<br />

SCREEN(I:I) = ’*’<br />

ENDDO<br />

END<br />

A user-defined memory allocator may be specified using the LOCATION= specifier.<br />

Example:<br />

CHARACTER*1 BUFFER(:)<br />

N = 128<br />

ALLOCATE( BUFFER(0:N-1), LOCATION=MYALLOC(N) )<br />

.<br />

.<br />

.<br />

END<br />

Perhaps a better way to check for a successful allocation, in this case, would be the following.<br />

Example:<br />

CHARACTER*1 BUFFER(:)<br />

N = 128<br />

LOC = MYALLOC( N )<br />

IF( LOC .EQ. 0 ) STOP<br />

ALLOCATE( BUFFER(0:N-1), LOCATION=LOC )<br />

.<br />

.<br />

.<br />

END<br />

For more information on arrays, see the chapter entitled "Arrays" on page 159.<br />

ALLOCATE Statement 15

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

Saved successfully!

Ooh no, something went wrong!