MODFLOW 6  version 6.9.0.dev0
USGS Modular Hydrologic Model
MemoryAlias.f90
Go to the documentation of this file.
1 !> @brief Previous variable names checked in as deprecated aliases
2 !!
3 !! A package that renames or moves a variable checks in the previous name as
4 !! an alias of the variable, so a program that addresses it through the API
5 !! still resolves, and records the replacement for the API to report.
6 !<
8 
9  use kindmodule, only: dp, i4b, lgp
16 
17  implicit none
18  private
19  public :: mem_alias_deprecated
20  public :: get_deprecated_alias
21  public :: mem_alias_da
22 
23  integer(I4B), parameter :: lenversion = 16 !< maximum length of a version string
24 
26  module procedure &
27  alias_int, &
29  alias_int1d, &
30  alias_int2d, &
31  alias_dbl1d, &
32  alias_dbl2d, &
34  end interface mem_alias_deprecated
35 
36  type(hashtabletype), pointer :: alias_index => null() !< alias address to record number
37  integer(I4B) :: nalias = 0 !< number of recorded aliases
38  character(len=LENMEMADDRESS), dimension(:), allocatable :: replacements !< address of the replacement variable
39  character(len=LENVERSION), dimension(:), allocatable :: versions !< version the alias was deprecated in
40 
41 contains
42 
43  !> @brief Check in a deprecated name for an integer scalar
44  !<
45  subroutine alias_int(sclr, name, mem_path, name2, mem_path2, version)
46  integer(I4B), pointer, intent(in) :: sclr !< the replacement variable
47  character(len=*), intent(in) :: name !< deprecated variable name
48  character(len=*), intent(in) :: mem_path !< path of the deprecated name
49  character(len=*), intent(in) :: name2 !< replacement variable name
50  character(len=*), intent(in) :: mem_path2 !< path of the replacement variable
51  character(len=*), intent(in) :: version !< version the name was deprecated in
52  ! -- local
53  integer(I4B), pointer :: alias => null()
54  !
55  if (.not. associated(sclr)) return
56  !
57  ! -- a scalar has no checkin, so point a new entry at the replacement
58  call mem_allocate(alias, name, mem_path)
59  call mem_reassignptr(alias, name, mem_path, name2, mem_path2)
60  call record_alias(name, mem_path, name2, mem_path2, version)
61  end subroutine alias_int
62 
63  !> @brief Check in a deprecated name for a 1d logical array
64  !<
65  subroutine alias_logical1d(alog, name, mem_path, name2, mem_path2, version)
66  logical(LGP), dimension(:), pointer, contiguous, intent(in) :: alog !< the replacement variable
67  character(len=*), intent(in) :: name !< deprecated variable name
68  character(len=*), intent(in) :: mem_path !< path of the deprecated name
69  character(len=*), intent(in) :: name2 !< replacement variable name
70  character(len=*), intent(in) :: mem_path2 !< path of the replacement variable
71  character(len=*), intent(in) :: version !< version the name was deprecated in
72  !
73  if (.not. associated(alog)) return
74  call mem_checkin(alog, name, mem_path, name2, mem_path2)
75  call record_alias(name, mem_path, name2, mem_path2, version)
76  end subroutine alias_logical1d
77 
78  !> @brief Check in a deprecated name for a 1d integer array
79  !<
80  subroutine alias_int1d(aint, name, mem_path, name2, mem_path2, version)
81  integer(I4B), dimension(:), pointer, contiguous, intent(inout) :: aint !< the replacement variable
82  character(len=*), intent(in) :: name !< deprecated variable name
83  character(len=*), intent(in) :: mem_path !< path of the deprecated name
84  character(len=*), intent(in) :: name2 !< replacement variable name
85  character(len=*), intent(in) :: mem_path2 !< path of the replacement variable
86  character(len=*), intent(in) :: version !< version the name was deprecated in
87  !
88  if (.not. associated(aint)) return
89  call mem_checkin(aint, name, mem_path, name2, mem_path2)
90  call record_alias(name, mem_path, name2, mem_path2, version)
91  end subroutine alias_int1d
92 
93  !> @brief Check in a deprecated name for a 2d integer array
94  !<
95  subroutine alias_int2d(aint, name, mem_path, name2, mem_path2, version)
96  integer(I4B), dimension(:, :), pointer, contiguous, intent(inout) :: aint !< the replacement variable
97  character(len=*), intent(in) :: name !< deprecated variable name
98  character(len=*), intent(in) :: mem_path !< path of the deprecated name
99  character(len=*), intent(in) :: name2 !< replacement variable name
100  character(len=*), intent(in) :: mem_path2 !< path of the replacement variable
101  character(len=*), intent(in) :: version !< version the name was deprecated in
102  !
103  if (.not. associated(aint)) return
104  call mem_checkin(aint, name, mem_path, name2, mem_path2)
105  call record_alias(name, mem_path, name2, mem_path2, version)
106  end subroutine alias_int2d
107 
108  !> @brief Check in a deprecated name for a 1d double precision array
109  !<
110  subroutine alias_dbl1d(adbl, name, mem_path, name2, mem_path2, version)
111  real(DP), dimension(:), pointer, contiguous, intent(inout) :: adbl !< the replacement variable
112  character(len=*), intent(in) :: name !< deprecated variable name
113  character(len=*), intent(in) :: mem_path !< path of the deprecated name
114  character(len=*), intent(in) :: name2 !< replacement variable name
115  character(len=*), intent(in) :: mem_path2 !< path of the replacement variable
116  character(len=*), intent(in) :: version !< version the name was deprecated in
117  !
118  if (.not. associated(adbl)) return
119  call mem_checkin(adbl, name, mem_path, name2, mem_path2)
120  call record_alias(name, mem_path, name2, mem_path2, version)
121  end subroutine alias_dbl1d
122 
123  !> @brief Check in a deprecated name for a 2d double precision array
124  !<
125  subroutine alias_dbl2d(adbl, name, mem_path, name2, mem_path2, version)
126  real(DP), dimension(:, :), pointer, contiguous, intent(inout) :: adbl !< the replacement variable
127  character(len=*), intent(in) :: name !< deprecated variable name
128  character(len=*), intent(in) :: mem_path !< path of the deprecated name
129  character(len=*), intent(in) :: name2 !< replacement variable name
130  character(len=*), intent(in) :: mem_path2 !< path of the replacement variable
131  character(len=*), intent(in) :: version !< version the name was deprecated in
132  !
133  if (.not. associated(adbl)) return
134  call mem_checkin(adbl, name, mem_path, name2, mem_path2)
135  call record_alias(name, mem_path, name2, mem_path2, version)
136  end subroutine alias_dbl2d
137 
138  !> @brief Check in a deprecated name for a 1d character string array
139  !<
140  subroutine alias_charstr1d(acharstr1d, ilen, name, mem_path, name2, &
141  mem_path2, version)
142  type(characterstringtype), dimension(:), &
143  pointer, contiguous, intent(inout) :: acharstr1d !< the replacement variable
144  integer(I4B), intent(in) :: ilen !< string length
145  character(len=*), intent(in) :: name !< deprecated variable name
146  character(len=*), intent(in) :: mem_path !< path of the deprecated name
147  character(len=*), intent(in) :: name2 !< replacement variable name
148  character(len=*), intent(in) :: mem_path2 !< path of the replacement variable
149  character(len=*), intent(in) :: version !< version the name was deprecated in
150  !
151  if (.not. associated(acharstr1d)) return
152  call mem_checkin(acharstr1d, ilen, name, mem_path, name2, mem_path2)
153  call record_alias(name, mem_path, name2, mem_path2, version)
154  end subroutine alias_charstr1d
155 
156  !> @brief Record the replacement and version of a deprecated name
157  !<
158  subroutine record_alias(name, mem_path, name2, mem_path2, version)
159  character(len=*), intent(in) :: name !< deprecated variable name
160  character(len=*), intent(in) :: mem_path !< path of the deprecated name
161  character(len=*), intent(in) :: name2 !< replacement variable name
162  character(len=*), intent(in) :: mem_path2 !< path of the replacement variable
163  character(len=*), intent(in) :: version !< version the name was deprecated in
164  !
165  if (.not. associated(alias_index)) call hash_table_cr(alias_index)
166  nalias = nalias + 1
168  call expandarray(versions)
169  replacements(nalias) = create_mem_address(mem_path2, name2)
170  versions(nalias) = version
171  call alias_index%add(create_mem_address(mem_path, name), nalias)
172  end subroutine record_alias
173 
174  !> @brief Get the replacement and version of a deprecated name
175  !<
176  subroutine get_deprecated_alias(name, mem_path, found, replacement, version)
177  character(len=*), intent(in) :: name !< variable name
178  character(len=*), intent(in) :: mem_path !< path of the variable
179  logical(LGP), intent(out) :: found !< true when the name is deprecated
180  character(len=LENMEMADDRESS), intent(out) :: replacement !< address of the replacement variable
181  character(len=*), intent(out) :: version !< version the name was deprecated in
182  ! -- local
183  integer(I4B) :: i
184  !
185  found = .false.
186  replacement = ''
187  version = ''
188  if (.not. associated(alias_index)) return
189  i = alias_index%get(create_mem_address(mem_path, name))
190  if (i == 0) return
191  found = .true.
192  replacement = replacements(i)
193  version = versions(i)
194  end subroutine get_deprecated_alias
195 
196  !> @brief Clear the recorded aliases
197  !!
198  !! The alias entries themselves are deallocated with the memory manager.
199  !<
200  subroutine mem_alias_da()
201  if (associated(alias_index)) call hash_table_da(alias_index)
202  if (allocated(replacements)) deallocate (replacements)
203  if (allocated(versions)) deallocate (versions)
204  nalias = 0
205  end subroutine mem_alias_da
206 
207 end module memoryaliasmodule
This module contains simulation constants.
Definition: Constants.f90:9
integer(i4b), parameter lenmemaddress
maximum length of the full memory address, including variable name
Definition: Constants.f90:31
A chaining hash map for integers.
Definition: HashTable.f90:7
subroutine, public hash_table_cr(map)
Create a hash table.
Definition: HashTable.f90:46
subroutine, public hash_table_da(map)
Deallocate the hash table.
Definition: HashTable.f90:64
This module defines variable data types.
Definition: kind.f90:8
Previous variable names checked in as deprecated aliases.
Definition: MemoryAlias.f90:7
integer(i4b) nalias
number of recorded aliases
Definition: MemoryAlias.f90:37
subroutine, public mem_alias_da()
Clear the recorded aliases.
subroutine record_alias(name, mem_path, name2, mem_path2, version)
Record the replacement and version of a deprecated name.
subroutine alias_logical1d(alog, name, mem_path, name2, mem_path2, version)
Check in a deprecated name for a 1d logical array.
Definition: MemoryAlias.f90:66
subroutine alias_int2d(aint, name, mem_path, name2, mem_path2, version)
Check in a deprecated name for a 2d integer array.
Definition: MemoryAlias.f90:96
type(hashtabletype), pointer alias_index
alias address to record number
Definition: MemoryAlias.f90:36
subroutine alias_dbl1d(adbl, name, mem_path, name2, mem_path2, version)
Check in a deprecated name for a 1d double precision array.
integer(i4b), parameter lenversion
maximum length of a version string
Definition: MemoryAlias.f90:23
character(len=lenversion), dimension(:), allocatable versions
version the alias was deprecated in
Definition: MemoryAlias.f90:39
subroutine alias_int1d(aint, name, mem_path, name2, mem_path2, version)
Check in a deprecated name for a 1d integer array.
Definition: MemoryAlias.f90:81
subroutine alias_charstr1d(acharstr1d, ilen, name, mem_path, name2, mem_path2, version)
Check in a deprecated name for a 1d character string array.
subroutine alias_dbl2d(adbl, name, mem_path, name2, mem_path2, version)
Check in a deprecated name for a 2d double precision array.
subroutine, public get_deprecated_alias(name, mem_path, found, replacement, version)
Get the replacement and version of a deprecated name.
character(len=lenmemaddress), dimension(:), allocatable replacements
address of the replacement variable
Definition: MemoryAlias.f90:38
subroutine alias_int(sclr, name, mem_path, name2, mem_path2, version)
Check in a deprecated name for an integer scalar.
Definition: MemoryAlias.f90:46
character(len=lenmemaddress) function create_mem_address(mem_path, var_name)
returns the address string of the memory object
This class is used to store a single deferred-length character string. It was designed to work in an ...
Definition: CharString.f90:23