Fortran 90

3.3 Allocatable Arrays
Fortran 90 allows for dynamic memory allocation by use of the ALLOCATE statement. In this way chunks of temporary memory can be allocated and deallocated as required. An allocatable array can be declared using the ALLOCATABLE attribute as follows,
 PROGRAM simulate
 IMPLICIT NONE
 INTEGER :: n
 INTEGER, DIMENSION(:,:), ALLOCATABLE :: a
This specifies the array name and rank, but leaves the array bounds undefined until later, when (for example) the array size is read in,
 PRINT *,'Enter n:'
 READ *,n
 IF(.NOT.ALLOCATED(a)) ALLOCATE( a(n,2*n) )
When the array is no longer needed, its memory allocation can be freed using
 DEALLOCATE(a)