MOM6
mom_safe_alloc Module Reference

Detailed Description

Convenience functions for safely allocating memory without accidentally reallocating pointer and causing memory leaks.

Data Types

interface  safe_alloc_alloc
 Allocate a 2-d or 3-d allocatable array. More...
 
interface  safe_alloc_ptr
 Allocate a pointer to a 1-d, 2-d or 3-d array. More...
 

Functions/Subroutines

subroutine safe_alloc_ptr_1d (ptr, i1, i2)
 Allocate a pointer to a 1-d array. More...
 
subroutine safe_alloc_ptr_2d_2arg (ptr, ni, nj)
 Allocate a pointer to a 2-d array based on its dimension sizes. More...
 
subroutine safe_alloc_ptr_3d_3arg (ptr, ni, nj, nk)
 Allocate a pointer to a 3-d array based on its dimension sizes. More...
 
subroutine safe_alloc_ptr_2d (ptr, is, ie, js, je)
 Allocate a pointer to a 2-d array based on its index starting and ending values. More...
 
subroutine safe_alloc_ptr_3d (ptr, is, ie, js, je, nk)
 Allocate a pointer to a 3-d array based on its index starting and ending values. More...
 
subroutine safe_alloc_ptr_3d_6arg (ptr, is, ie, js, je, ks, ke)
 Allocate a pointer to a 3-d array based on its index starting and ending values. More...
 
subroutine safe_alloc_allocatable_2d (ptr, is, ie, js, je)
 Allocate a 2-d allocatable array based on its index starting and ending values. More...
 
subroutine safe_alloc_allocatable_3d (ptr, is, ie, js, je, nk)
 Allocate a 3-d allocatable array based on its index starting and ending values and k-index size. More...
 
subroutine safe_alloc_allocatable_3d_6arg (ptr, is, ie, js, je, ks, ke)
 Allocate a 3-d allocatable array based on its 6 index starting and ending values. More...
 

Function/Subroutine Documentation

◆ safe_alloc_allocatable_2d()

subroutine mom_safe_alloc::safe_alloc_allocatable_2d ( real, dimension(:,:), allocatable  ptr,
integer, intent(in)  is,
integer, intent(in)  ie,
integer, intent(in)  js,
integer, intent(in)  je 
)
private

Allocate a 2-d allocatable array based on its index starting and ending values.

Parameters
ptrAn allocatable array to allocate
[in]isThe start index to allocate for the 1st dimension
[in]ieThe end index to allocate for the 1st dimension
[in]jsThe start index to allocate for the 2nd dimension
[in]jeThe end index to allocate for the 2nd dimension

Definition at line 117 of file MOM_safe_alloc.F90.

117  real, dimension(:,:), allocatable :: ptr !< An allocatable array to allocate
118  integer, intent(in) :: is !< The start index to allocate for the 1st dimension
119  integer, intent(in) :: ie !< The end index to allocate for the 1st dimension
120  integer, intent(in) :: js !< The start index to allocate for the 2nd dimension
121  integer, intent(in) :: je !< The end index to allocate for the 2nd dimension
122  if (.not.allocated(ptr)) then
123  allocate(ptr(is:ie,js:je))
124  ptr(:,:) = 0.0
125  endif

◆ safe_alloc_allocatable_3d()

subroutine mom_safe_alloc::safe_alloc_allocatable_3d ( real, dimension(:,:,:), allocatable  ptr,
integer, intent(in)  is,
integer, intent(in)  ie,
integer, intent(in)  js,
integer, intent(in)  je,
integer, intent(in)  nk 
)
private

Allocate a 3-d allocatable array based on its index starting and ending values and k-index size.

Parameters
ptrAn allocatable array to allocate
[in]isThe start index to allocate for the 1st dimension
[in]ieThe end index to allocate for the 1st dimension
[in]jsThe start index to allocate for the 2nd dimension
[in]jeThe end index to allocate for the 2nd dimension
[in]nkThe size to allocate for the 3rd dimension

Definition at line 131 of file MOM_safe_alloc.F90.

131  real, dimension(:,:,:), allocatable :: ptr !< An allocatable array to allocate
132  integer, intent(in) :: is !< The start index to allocate for the 1st dimension
133  integer, intent(in) :: ie !< The end index to allocate for the 1st dimension
134  integer, intent(in) :: js !< The start index to allocate for the 2nd dimension
135  integer, intent(in) :: je !< The end index to allocate for the 2nd dimension
136  integer, intent(in) :: nk !< The size to allocate for the 3rd dimension
137  if (.not.allocated(ptr)) then
138  allocate(ptr(is:ie,js:je,nk))
139  ptr(:,:,:) = 0.0
140  endif

◆ safe_alloc_allocatable_3d_6arg()

subroutine mom_safe_alloc::safe_alloc_allocatable_3d_6arg ( real, dimension(:,:,:), allocatable  ptr,
integer, intent(in)  is,
integer, intent(in)  ie,
integer, intent(in)  js,
integer, intent(in)  je,
integer, intent(in)  ks,
integer, intent(in)  ke 
)
private

Allocate a 3-d allocatable array based on its 6 index starting and ending values.

Parameters
ptrAn allocatable array to allocate
[in]isThe start index to allocate for the 1st dimension
[in]ieThe end index to allocate for the 1st dimension
[in]jsThe start index to allocate for the 2nd dimension
[in]jeThe end index to allocate for the 2nd dimension
[in]ksThe start index to allocate for the 3rd dimension
[in]keThe end index to allocate for the 3rd dimension

Definition at line 145 of file MOM_safe_alloc.F90.

145  real, dimension(:,:,:), allocatable :: ptr !< An allocatable array to allocate
146  integer, intent(in) :: is !< The start index to allocate for the 1st dimension
147  integer, intent(in) :: ie !< The end index to allocate for the 1st dimension
148  integer, intent(in) :: js !< The start index to allocate for the 2nd dimension
149  integer, intent(in) :: je !< The end index to allocate for the 2nd dimension
150  integer, intent(in) :: ks !< The start index to allocate for the 3rd dimension
151  integer, intent(in) :: ke !< The end index to allocate for the 3rd dimension
152  if (.not.allocated(ptr)) then
153  allocate(ptr(is:ie,js:je,ks:ke))
154  ptr(:,:,:) = 0.0
155  endif

◆ safe_alloc_ptr_1d()

subroutine mom_safe_alloc::safe_alloc_ptr_1d ( real, dimension(:), pointer  ptr,
integer, intent(in)  i1,
integer, intent(in), optional  i2 
)
private

Allocate a pointer to a 1-d array.

Parameters
ptrA pointer to allocate
[in]i1The size of the array, or its starting index if i2 is present
[in]i2The ending index of the array

Definition at line 36 of file MOM_safe_alloc.F90.

36  real, dimension(:), pointer :: ptr !< A pointer to allocate
37  integer, intent(in) :: i1 !< The size of the array, or its starting index if i2 is present
38  integer, optional, intent(in) :: i2 !< The ending index of the array
39  if (.not.associated(ptr)) then
40  if (present(i2)) then
41  allocate(ptr(i1:i2))
42  else
43  allocate(ptr(i1))
44  endif
45  ptr(:) = 0.0
46  endif

◆ safe_alloc_ptr_2d()

subroutine mom_safe_alloc::safe_alloc_ptr_2d ( real, dimension(:,:), pointer  ptr,
integer, intent(in)  is,
integer, intent(in)  ie,
integer, intent(in)  js,
integer, intent(in)  je 
)
private

Allocate a pointer to a 2-d array based on its index starting and ending values.

Parameters
ptrA pointer to allocate
[in]isThe start index to allocate for the 1st dimension
[in]ieThe end index to allocate for the 1st dimension
[in]jsThe start index to allocate for the 2nd dimension
[in]jeThe end index to allocate for the 2nd dimension

Definition at line 74 of file MOM_safe_alloc.F90.

74  real, dimension(:,:), pointer :: ptr !< A pointer to allocate
75  integer, intent(in) :: is !< The start index to allocate for the 1st dimension
76  integer, intent(in) :: ie !< The end index to allocate for the 1st dimension
77  integer, intent(in) :: js !< The start index to allocate for the 2nd dimension
78  integer, intent(in) :: je !< The end index to allocate for the 2nd dimension
79  if (.not.associated(ptr)) then
80  allocate(ptr(is:ie,js:je))
81  ptr(:,:) = 0.0
82  endif

◆ safe_alloc_ptr_2d_2arg()

subroutine mom_safe_alloc::safe_alloc_ptr_2d_2arg ( real, dimension(:,:), pointer  ptr,
integer, intent(in)  ni,
integer, intent(in)  nj 
)
private

Allocate a pointer to a 2-d array based on its dimension sizes.

Parameters
ptrA pointer to allocate
[in]niThe size of the 1st dimension of the array
[in]njThe size of the 2nd dimension of the array

Definition at line 51 of file MOM_safe_alloc.F90.

51  real, dimension(:,:), pointer :: ptr !< A pointer to allocate
52  integer, intent(in) :: ni !< The size of the 1st dimension of the array
53  integer, intent(in) :: nj !< The size of the 2nd dimension of the array
54  if (.not.associated(ptr)) then
55  allocate(ptr(ni,nj))
56  ptr(:,:) = 0.0
57  endif

◆ safe_alloc_ptr_3d()

subroutine mom_safe_alloc::safe_alloc_ptr_3d ( real, dimension(:,:,:), pointer  ptr,
integer, intent(in)  is,
integer, intent(in)  ie,
integer, intent(in)  js,
integer, intent(in)  je,
integer, intent(in)  nk 
)
private

Allocate a pointer to a 3-d array based on its index starting and ending values.

Parameters
ptrA pointer to allocate
[in]isThe start index to allocate for the 1st dimension
[in]ieThe end index to allocate for the 1st dimension
[in]jsThe start index to allocate for the 2nd dimension
[in]jeThe end index to allocate for the 2nd dimension
[in]nkThe size to allocate for the 3rd dimension

Definition at line 87 of file MOM_safe_alloc.F90.

87  real, dimension(:,:,:), pointer :: ptr !< A pointer to allocate
88  integer, intent(in) :: is !< The start index to allocate for the 1st dimension
89  integer, intent(in) :: ie !< The end index to allocate for the 1st dimension
90  integer, intent(in) :: js !< The start index to allocate for the 2nd dimension
91  integer, intent(in) :: je !< The end index to allocate for the 2nd dimension
92  integer, intent(in) :: nk !< The size to allocate for the 3rd dimension
93  if (.not.associated(ptr)) then
94  allocate(ptr(is:ie,js:je,nk))
95  ptr(:,:,:) = 0.0
96  endif

◆ safe_alloc_ptr_3d_3arg()

subroutine mom_safe_alloc::safe_alloc_ptr_3d_3arg ( real, dimension(:,:,:), pointer  ptr,
integer, intent(in)  ni,
integer, intent(in)  nj,
integer, intent(in)  nk 
)
private

Allocate a pointer to a 3-d array based on its dimension sizes.

Parameters
ptrA pointer to allocate
[in]niThe size of the 1st dimension of the array
[in]njThe size of the 2nd dimension of the array
[in]nkThe size of the 3rd dimension of the array

Definition at line 62 of file MOM_safe_alloc.F90.

62  real, dimension(:,:,:), pointer :: ptr !< A pointer to allocate
63  integer, intent(in) :: ni !< The size of the 1st dimension of the array
64  integer, intent(in) :: nj !< The size of the 2nd dimension of the array
65  integer, intent(in) :: nk !< The size of the 3rd dimension of the array
66  if (.not.associated(ptr)) then
67  allocate(ptr(ni,nj,nk))
68  ptr(:,:,:) = 0.0
69  endif

◆ safe_alloc_ptr_3d_6arg()

subroutine mom_safe_alloc::safe_alloc_ptr_3d_6arg ( real, dimension(:,:,:), pointer  ptr,
integer, intent(in)  is,
integer, intent(in)  ie,
integer, intent(in)  js,
integer, intent(in)  je,
integer, intent(in)  ks,
integer, intent(in)  ke 
)
private

Allocate a pointer to a 3-d array based on its index starting and ending values.

Parameters
ptrA pointer to allocate
[in]isThe start index to allocate for the 1st dimension
[in]ieThe end index to allocate for the 1st dimension
[in]jsThe start index to allocate for the 2nd dimension
[in]jeThe end index to allocate for the 2nd dimension
[in]ksThe start index to allocate for the 3rd dimension
[in]keThe end index to allocate for the 3rd dimension

Definition at line 101 of file MOM_safe_alloc.F90.

101  real, dimension(:,:,:), pointer :: ptr !< A pointer to allocate
102  integer, intent(in) :: is !< The start index to allocate for the 1st dimension
103  integer, intent(in) :: ie !< The end index to allocate for the 1st dimension
104  integer, intent(in) :: js !< The start index to allocate for the 2nd dimension
105  integer, intent(in) :: je !< The end index to allocate for the 2nd dimension
106  integer, intent(in) :: ks !< The start index to allocate for the 3rd dimension
107  integer, intent(in) :: ke !< The end index to allocate for the 3rd dimension
108  if (.not.associated(ptr)) then
109  allocate(ptr(is:ie,js:je,ks:ke))
110  ptr(:,:,:) = 0.0
111  endif