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

2.4 ALLOCATE Statement<br />

ALLOCATE (array([l:]u[,[l:]u,...])[,...][,LOCATION=loc])<br />

or<br />

ALLOCATE (array([l:]u[,[l:]u,...])[,...][,STAT=ierr])<br />

or<br />

ALLOCATE (char*len)<br />

where:<br />

array<br />

l<br />

u<br />

char<br />

len<br />

is the name of an allocatable array.<br />

is an integer expression that sets the lower bound of the array dimension.<br />

is an integer expression that sets the upper bound of the array dimension.<br />

is the name of an allocatable character variable.<br />

is an integer expression that sets the length of the character variable.<br />

LOCATION = loc<br />

loc is an integer expression that specifies the location of the allocated memory.<br />

STAT = ierr<br />

ierr is an allocation status specifier. The integer variable or integer array element ierr is<br />

defined with 0 if the allocation succeeded, 1 if the allocation failed, and 2 if the array is<br />

already allocated. The STAT= specifier may not be used with the LOCATION= specifier.<br />

Allocatable arrays and character variables may be dynamically allocated and deallocated at execution time.<br />

An array must have been declared allocatable by specifying its dimensions using colons only. No array<br />

bounds are specified.<br />

Example:<br />

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

In the above example, A is declared to be a one-dimensional allocatable array and B is declared to be a<br />

two-dimensional allocatable array.<br />

A character variable must have been declared allocatable by specifying its size as (*).<br />

Example:<br />

CHARACTER C*(*)<br />

For an allocatable array, the ALLOCATE statement establishes the lower and upper bounds of each array<br />

dimension and calculates the amount of memory required for the array.<br />

For an allocatable character variable, the ALLOCATE statement establishes the number of characters in the<br />

character variable and thus the size of the character variable.<br />

If there is no LOCATION= specifier, it then attempts to dynamically allocate memory for the array or<br />

character variable. The success of the allocation can be checked by using the STAT= specifier.<br />

ALLOCATE Statement 13

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

Saved successfully!

Ooh no, something went wrong!