Allocate an allocatable array. If the array is already allocated, memory is reallocated to the given size, unless no size change will occur. The allocated memory is NOT initialized to any value, so be sure to do so afterwards if you call allocate.
Does not overload the intrinsic allocate function. This way, calling allocate makes the user aware that checks are being made, and memory will be re-allocated.
Checks for an error during allocation, and will stop the code if there is one.
The allocate interface can be given the size of the new array only. e.g. call allocate(array1D, 10) Or the lower bound and the size can be given. e.g. call allocate(array1D, 0, 12) is akin to allocate(array1D(0:11)).
Example usage
use variableKind use m_allocate, only: allocate real(r64),allocatable :: a1D(:), a2D(:,:), a3D(:,:,:) call allocate(a1D, 20) call allocate(a2D, [20,20]) call allocate(a3D, [20,20,20]) write(*,'(a)') 'Shape of a3D is [20,20,20]? '//all(shape(a3D) == [20,20,20]) call allocate(a1D, -10, 20) call allocate(a2D, [-10,-10], [20,20]) call allocate(a3D, [-10,-10,-10], [20,20,20]) write(*,'(a)') 'Lower bound of a3D is [-10,-10,-10]? '//all(lbound(a3D) == [-10,-10,-10]) write(*,'(a)') 'Shape of a3D is [20,20,20]? '//all(shape(a3D) == [20,20,20])
Interfaced with allocate
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=r32), | intent(inout), | allocatable | :: | this(:) | 1D array |
|
integer(kind=i32), | intent(in) | :: | n | Allocation size |
Interfaced with allocate
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=r32), | intent(inout), | allocatable | :: | this(:,:) | 2D array |
|
integer(kind=i32), | intent(in) | :: | n(2) | Allocation size |
Interfaced with allocate
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=r32), | intent(inout), | allocatable | :: | this(:,:,:) | 3D array |
|
integer(kind=i32), | intent(in) | :: | n(3) | Allocation size |
Interfaced with allocate
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=r32), | intent(inout), | allocatable | :: | this(:) | 1D array |
|
integer(kind=i32), | intent(in) | :: | lb | Lower index |
||
integer(kind=i32), | intent(in) | :: | n | Allocation size |
Interfaced with allocate
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=r32), | intent(inout), | allocatable | :: | this(:,:) | 2D array |
|
integer(kind=i32), | intent(in) | :: | lb(2) | Lower index |
||
integer(kind=i32), | intent(in) | :: | n(2) | Allocation size |
Interfaced with allocate
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=r32), | intent(inout), | allocatable | :: | this(:,:,:) | 3D array |
|
integer(kind=i32), | intent(in) | :: | lb(3) | Lower index |
||
integer(kind=i32), | intent(in) | :: | n(3) | Allocation size |
Interfaced with allocate
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=r64), | intent(inout), | allocatable | :: | this(:) | 1D array |
|
integer(kind=i32), | intent(in) | :: | n | Allocation size |
Interfaced with allocate
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=r64), | intent(inout), | allocatable | :: | this(:,:) | 2D array |
|
integer(kind=i32), | intent(in) | :: | n(2) | Allocation size |
Interfaced with allocate
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=r64), | intent(inout), | allocatable | :: | this(:,:,:) | 3D array |
|
integer(kind=i32), | intent(in) | :: | n(3) | Allocation size |
Interfaced with allocate
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=r64), | intent(inout), | allocatable | :: | this(:) | 1D array |
|
integer(kind=i32), | intent(in) | :: | lb | Lower index |
||
integer(kind=i32), | intent(in) | :: | n | Allocation size |
Interfaced with allocate
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=r64), | intent(inout), | allocatable | :: | this(:,:) | 2D array |
|
integer(kind=i32), | intent(in) | :: | lb(2) | Lower index |
||
integer(kind=i32), | intent(in) | :: | n(2) | Allocation size |
Interfaced with allocate
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=r64), | intent(inout), | allocatable | :: | this(:,:,:) | 3D array |
|
integer(kind=i32), | intent(in) | :: | lb(3) | Lower index |
||
integer(kind=i32), | intent(in) | :: | n(3) | Allocation size |
Interfaced with allocate
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=i32), | intent(inout), | allocatable | :: | this(:) | 1D array |
|
integer(kind=i32), | intent(in) | :: | n | Allocation size |
Interfaced with allocate
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=i32), | intent(inout), | allocatable | :: | this(:,:) | 2D array |
|
integer(kind=i32), | intent(in) | :: | n(2) | Allocation size |
Interfaced with allocate
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=i32), | intent(inout), | allocatable | :: | this(:,:,:) | 3D array |
|
integer(kind=i32), | intent(in) | :: | n(3) | Allocation size |
Interfaced with allocate
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=i32), | intent(inout), | allocatable | :: | this(:) | 1D array |
|
integer(kind=i32), | intent(in) | :: | lb | Lower index |
||
integer(kind=i32), | intent(in) | :: | n | Allocation size |
Interfaced with allocate
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=i32), | intent(inout), | allocatable | :: | this(:,:) | 2D array |
|
integer(kind=i32), | intent(in) | :: | lb(2) | Lower index |
||
integer(kind=i32), | intent(in) | :: | n(2) | Allocation size |
Interfaced with allocate
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=i32), | intent(inout), | allocatable | :: | this(:,:,:) | 3D array |
|
integer(kind=i32), | intent(in) | :: | lb(3) | Lower index |
||
integer(kind=i32), | intent(in) | :: | n(3) | Allocation size |
Interfaced with allocate
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=i64), | intent(inout), | allocatable | :: | this(:) | 1D array |
|
integer(kind=i32), | intent(in) | :: | n | Allocation size |
Interfaced with allocate
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=i64), | intent(inout), | allocatable | :: | this(:,:) | 2D array |
|
integer(kind=i32), | intent(in) | :: | n(2) | Allocation size |
Interfaced with allocate
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=i64), | intent(inout), | allocatable | :: | this(:,:,:) | 3D array |
|
integer(kind=i32), | intent(in) | :: | n(3) | Allocation size |
Interfaced with allocate
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=i64), | intent(inout), | allocatable | :: | this(:) | 1D array |
|
integer(kind=i32), | intent(in) | :: | lb | Lower index |
||
integer(kind=i32), | intent(in) | :: | n | Allocation size |
Interfaced with allocate
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=i64), | intent(inout), | allocatable | :: | this(:,:) | 2D array |
|
integer(kind=i32), | intent(in) | :: | lb(2) | Lower index |
||
integer(kind=i32), | intent(in) | :: | n(2) | Allocation size |
Interfaced with allocate
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=i64), | intent(inout), | allocatable | :: | this(:,:,:) | 3D array |
|
integer(kind=i32), | intent(in) | :: | lb(3) | Lower index |
||
integer(kind=i32), | intent(in) | :: | n(3) | Allocation size |
Interfaced with allocate
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
complex(kind=r32), | intent(inout), | allocatable | :: | this(:) | 1D array |
|
integer(kind=i32), | intent(in) | :: | n | Allocation size |
Interfaced with allocate
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
complex(kind=r32), | intent(inout), | allocatable | :: | this(:,:) | 2D array |
|
integer(kind=i32), | intent(in) | :: | n(2) | Allocation size |
Interfaced with allocate
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
complex(kind=r32), | intent(inout), | allocatable | :: | this(:,:,:) | 3D array |
|
integer(kind=i32), | intent(in) | :: | n(3) | Allocation size |
Interfaced with allocate
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
complex(kind=r32), | intent(inout), | allocatable | :: | this(:) | 1D array |
|
integer(kind=i32), | intent(in) | :: | lb | Lower index |
||
integer(kind=i32), | intent(in) | :: | n | Allocation size |
Interfaced with allocate
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
complex(kind=r32), | intent(inout), | allocatable | :: | this(:,:) | 2D array |
|
integer(kind=i32), | intent(in) | :: | lb(2) | Lower index |
||
integer(kind=i32), | intent(in) | :: | n(2) | Allocation size |
Interfaced with allocate
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
complex(kind=r32), | intent(inout), | allocatable | :: | this(:,:,:) | 3D array |
|
integer(kind=i32), | intent(in) | :: | lb(3) | Lower index |
||
integer(kind=i32), | intent(in) | :: | n(3) | Allocation size |
Interfaced with allocate
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
complex(kind=r64), | intent(inout), | allocatable | :: | this(:) | 1D array |
|
integer(kind=i32), | intent(in) | :: | n | Allocation size |
Interfaced with allocate
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
complex(kind=r64), | intent(inout), | allocatable | :: | this(:,:) | 2D array |
|
integer(kind=i32), | intent(in) | :: | n(2) | Allocation size |
Interfaced with allocate
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
complex(kind=r64), | intent(inout), | allocatable | :: | this(:,:,:) | 3D array |
|
integer(kind=i32), | intent(in) | :: | n(3) | Allocation size |
Interfaced with allocate
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
complex(kind=r64), | intent(inout), | allocatable | :: | this(:) | 1D array |
|
integer(kind=i32), | intent(in) | :: | lb | Lower index |
||
integer(kind=i32), | intent(in) | :: | n | Allocation size |
Interfaced with allocate
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
complex(kind=r64), | intent(inout), | allocatable | :: | this(:,:) | 2D array |
|
integer(kind=i32), | intent(in) | :: | lb(2) | Lower index |
||
integer(kind=i32), | intent(in) | :: | n(2) | Allocation size |
Interfaced with allocate
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
complex(kind=r64), | intent(inout), | allocatable | :: | this(:,:,:) | 3D array |
|
integer(kind=i32), | intent(in) | :: | lb(3) | Lower index |
||
integer(kind=i32), | intent(in) | :: | n(3) | Allocation size |
Interfaced with allocate
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
logical, | intent(inout), | allocatable | :: | this(:) | 1D array |
|
integer(kind=i32), | intent(in) | :: | n | Allocation size |
Interfaced with allocate
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
logical, | intent(inout), | allocatable | :: | this(:,:) | 2D array |
|
integer(kind=i32), | intent(in) | :: | n(2) | Allocation size |
Interfaced with allocate
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
logical, | intent(inout), | allocatable | :: | this(:,:,:) | 3D array |
|
integer(kind=i32), | intent(in) | :: | n(3) | Allocation size |
Interfaced with allocate
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
logical, | intent(inout), | allocatable | :: | this(:) | 1D array |
|
integer(kind=i32), | intent(in) | :: | lb | Lower index |
||
integer(kind=i32), | intent(in) | :: | n | Allocation size |
Interfaced with allocate
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
logical, | intent(inout), | allocatable | :: | this(:,:) | 2D array |
|
integer(kind=i32), | intent(in) | :: | lb(2) | Lower index |
||
integer(kind=i32), | intent(in) | :: | n(2) | Allocation size |
Interfaced with allocate
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
logical, | intent(inout), | allocatable | :: | this(:,:,:) | 3D array |
|
integer(kind=i32), | intent(in) | :: | lb(3) | Lower index |
||
integer(kind=i32), | intent(in) | :: | n(3) | Allocation size |