previous up next print clean
Next: Structures Up: FORTRAN90 BASICS Previous: FORTRAN90 BASICS

Dynamic Allocation

There are two main types of allocatable arrays available in Fortran90, the
allocatable and pointer arrays. Allocatable arrays must be allocated in the main program, and so while they may be passed back and forth to subroutines, they may not be function results. Giving up use of functions means giving up overloaded and user-defined operators, so we make very little use of arrays of this type.

The other main type of allocatable array is the pointer array. The name probably strikes a certain amount of suspicious fear into pointer-wary Fortran programmers. However, Fortran90's use of pointers is in general simpler to understand and keep track of than that of C or C++. Fortran pointers are referenced and used in exactly the same way as the objects they point to. No confusion.

Either way, allocatable arrays are declared with the dimension attribute in addition to the usual real, integer, etc. Allocatable arrays also get the allocatable attribute, pointer arrays the pointer attribute. Conveniently enough, the actual allocation syntax is just like that understood by SEP's fortran preprocessors SAW and SAT.

integer		:: n1,n2,n3
real, allocatable, dimension(:,:,:):: alloc_array  !3D allocatable array
real, pointer, dimension(:,:)	   :: p_array	!2D pointer array

allocate(p_array(n1,n2))
allocate(alloc_array(n1,n2,n3))


previous up next print clean
Next: Structures Up: FORTRAN90 BASICS Previous: FORTRAN90 BASICS
Stanford Exploration Project
11/12/1997