MODFLOW 6 version 6.9.0.dev0
USGS Modular Hydrologic Model
Loading...
Searching...
No Matches
DefinitionSelect.f90
Go to the documentation of this file.
1!> @brief This module contains the DefinitionSelectModule
2!!
3!! This module contains the routines for getting parameter
4!! definitions, aggregate definitions, and block definitions
5!! for the different package types.
6!!
7!<
9
10 use kindmodule, only: i4b, lgp
11 use simvariablesmodule, only: errmsg
15
16 implicit none
17 private
21 public :: idt_parse_rectype
22 public :: idt_datatype
23 public :: idt_default
24
25contains
26
27 !> @brief allocate and set RECARRAY, KEYSTRING or RECORD param list
28 !<
29 subroutine idt_parse_rectype(idt, cols, ncol)
32 type(inputparamdefinitiontype), pointer, intent(in) :: idt
33 character(len=LINELENGTH), dimension(:), allocatable, &
34 intent(inout) :: cols
35 integer(I4B), intent(inout) :: ncol
36 character(len=:), allocatable :: parse_str
37 character(len=LINELENGTH), dimension(:), allocatable :: param_cols
38 integer(I4B) :: param_ncol, n
39
40 ! initialize
41 if (allocated(cols)) deallocate (cols)
42 ncol = 0
43
44 ! split definition
45 parse_str = trim(idt%datatype)//' '
46 call parseline(parse_str, param_ncol, param_cols)
47
48 if (param_ncol > 1) then
49 if (param_cols(1) == 'RECARRAY' .or. &
50 param_cols(1) == 'KEYSTRING' .or. &
51 param_cols(1) == 'RECORD') then
52 ! exclude 1st column
53 allocate (cols(param_ncol - 1))
54 do n = 2, param_ncol
55 cols(n - 1) = param_cols(n)
56 end do
57 ! set ncol
58 ncol = param_ncol - 1
59 end if
60 end if
61
62 ! cleanup
63 if (allocated(param_cols)) deallocate (param_cols)
64 if (allocated(parse_str)) deallocate (parse_str)
65 end subroutine idt_parse_rectype
66
67 !> @brief return input definition type datatype
68 !<
69 function idt_datatype(idt) result(datatype)
71 type(inputparamdefinitiontype), pointer, intent(in) :: idt
72 character(len=LINELENGTH) :: datatype
73 if (idt%datatype(1:9) == 'KEYSTRING') then
74 datatype = 'KEYSTRING'
75 else if (idt%datatype(1:8) == 'RECARRAY') then
76 datatype = 'RECARRAY'
77 else if (idt%datatype(1:6) == 'RECORD') then
78 datatype = 'RECORD'
79 else
80 datatype = idt%datatype
81 end if
82 end function idt_datatype
83
84 !> @brief Return parameter definition
85 !<
86 function get_param_definition_type(input_definition_types, &
87 component_type, subcomponent_type, &
88 blockname, tagname, filename, &
89 found) &
90 result(idt)
93 type(inputparamdefinitiontype), dimension(:), intent(in), target :: &
94 input_definition_types
95 character(len=*), intent(in) :: component_type !< component type, such as GWF or GWT
96 character(len=*), intent(in) :: subcomponent_type !< subcomponent type, such as DIS or NPF
97 character(len=*), intent(in) :: blockname !< name of the block
98 character(len=*), intent(in) :: tagname !< name of the input tag
99 character(len=*), intent(in) :: filename !< input filename
100 logical(LGP), optional, intent(out) :: found !< is tagname found in search mempath
101 type(inputparamdefinitiontype), pointer :: idt !< corresponding InputParameterDefinitionType for this tag
102 type(inputparamdefinitiontype), pointer :: tmp_ptr
103 character(len=LINELENGTH) :: component
104 integer(I4B) :: i
105
106 if (idm_utl_type(component_type, subcomponent_type)) then
107 component = 'UTL'
108 else
109 component = component_type
110 end if
111
112 nullify (idt)
113 do i = 1, size(input_definition_types)
114 tmp_ptr => input_definition_types(i)
115 if (tmp_ptr%component_type == component .and. &
116 tmp_ptr%subcomponent_type == subcomponent_type .and. &
117 tmp_ptr%blockname == blockname .and. &
118 tmp_ptr%tagname == tagname) then
119 idt => input_definition_types(i)
120 exit
121 end if
122 end do
123
124 if (present(found)) then
125 found = associated(idt)
126 else if (.not. associated(idt)) then
127 write (errmsg, '(a,a,a,a,a)') &
128 'Input file tag not found: "', trim(tagname), &
129 '" in block "', trim(blockname), &
130 '".'
131 call store_error(errmsg)
132 call store_error_filename(filename)
133 end if
134 end function get_param_definition_type
135
136 !> @brief Return aggregate definition
137 !<
138 function get_aggregate_definition_type(input_definition_types, component_type, &
139 subcomponent_type, blockname) result(idt)
140 use constantsmodule, only: linelength
142 type(inputparamdefinitiontype), dimension(:), intent(in), target :: &
143 input_definition_types
144 character(len=*), intent(in) :: component_type !< component type, such as GWF or GWT
145 character(len=*), intent(in) :: subcomponent_type !< subcomponent type, such as DIS or NPF
146 character(len=*), intent(in) :: blockname !< name of the block
147 type(inputparamdefinitiontype), pointer :: idt !< corresponding InputParameterDefinitionType for this block
148 type(inputparamdefinitiontype), pointer :: tmp_ptr
149 character(len=LINELENGTH) :: component
150 integer(I4B) :: i
151
152 if (idm_utl_type(component_type, subcomponent_type)) then
153 component = 'UTL'
154 else
155 component = component_type
156 end if
157
158 nullify (idt)
159 do i = 1, size(input_definition_types)
160 tmp_ptr => input_definition_types(i)
161 if (tmp_ptr%component_type == component .and. &
162 tmp_ptr%subcomponent_type == subcomponent_type .and. &
163 tmp_ptr%blockname == blockname) then
164 idt => input_definition_types(i)
165 exit
166 end if
167 end do
168
169 if (.not. associated(idt)) then
170 write (errmsg, '(a,a,a,a,a,a,a)') &
171 'Idm aggregate definition not found: ', trim(blockname), &
172 '. Component="', trim(component_type), &
173 '", subcomponent="', trim(subcomponent_type), '".'
174 call store_error(errmsg, .true.)
175 end if
177
178 !> @brief Return aggregate definition
179 !!
180 !! Split a component RECORD datatype definition whose second element matches
181 !! tagname into an array of character tokens
182 !<
183 subroutine split_record_dfn_tag1(input_definition_types, component_type, &
184 subcomponent_type, tagname, nwords, words)
186 type(inputparamdefinitiontype), dimension(:), intent(in), target :: &
187 input_definition_types
188 character(len=*), intent(in) :: component_type !< component type, such as GWF or GWT
189 character(len=*), intent(in) :: subcomponent_type !< subcomponent type, such as DIS or NPF
190 character(len=*), intent(in) :: tagname !< name of the input tag
191 integer(I4B), intent(inout) :: nwords
192 character(len=40), dimension(:), allocatable, intent(inout) :: words
193 type(inputparamdefinitiontype), pointer :: tmp_ptr
194 integer(I4B) :: i
195 character(len=:), allocatable :: parse_str
196
197 ! initialize to deallocated
198 if (allocated(words)) deallocate (words)
199
200 ! return all tokens of multi-record type that matches the first
201 ! tag following the expected first token "RECORD"
202 do i = 1, size(input_definition_types)
203
204 ! initialize
205 nwords = 0
206
207 ! set ptr to current definition
208 tmp_ptr => input_definition_types(i)
209
210 ! match for definition to split
211 if (tmp_ptr%component_type == component_type .and. &
212 tmp_ptr%subcomponent_type == subcomponent_type .and. &
213 idt_datatype(tmp_ptr) == 'RECORD') then
214
215 ! set split string
216 parse_str = trim(input_definition_types(i)%datatype)//' '
217
218 ! split
219 call parseline(parse_str, nwords, words)
220
221 ! check for match and manage memory
222 if (nwords >= 2) then
223 if (words(1) == 'RECORD' .and. words(2) == tagname) then
224 exit
225 end if
226 end if
227
228 ! deallocate
229 if (allocated(parse_str)) deallocate (parse_str)
230 if (allocated(words)) deallocate (words)
231 end if
232 end do
233 end subroutine split_record_dfn_tag1
234
235 !> @brief Return aggregate definition
236 !!
237 !! Split a component RECORD datatype definition whose second and third
238 !! elements match tagnames into an array of character tokens
239 !<
240 subroutine split_record_dfn_tag2(input_definition_types, component_type, &
241 subcomponent_type, tagname, tag2, nwords, &
242 words)
244 type(inputparamdefinitiontype), dimension(:), intent(in), target :: &
245 input_definition_types
246 character(len=*), intent(in) :: component_type !< component type, such as GWF or GWT
247 character(len=*), intent(in) :: subcomponent_type !< subcomponent type, such as DIS or NPF
248 character(len=*), intent(in) :: tagname !< name of the input tag
249 character(len=*), intent(in) :: tag2
250 integer(I4B), intent(inout) :: nwords
251 character(len=40), dimension(:), allocatable, intent(inout) :: words
252 type(inputparamdefinitiontype), pointer :: tmp_ptr
253 integer(I4B) :: i
254 character(len=:), allocatable :: parse_str
255
256 ! initialize to deallocated
257 if (allocated(words)) deallocate (words)
258
259 ! return all tokens of multi-record type that matches the first
260 ! tag following the expected first token "RECORD"
261 do i = 1, size(input_definition_types)
262
263 ! initialize
264 nwords = 0
265
266 ! set ptr to current definition
267 tmp_ptr => input_definition_types(i)
268
269 ! match for definition to split
270 if (tmp_ptr%component_type == component_type .and. &
271 tmp_ptr%subcomponent_type == subcomponent_type .and. &
272 idt_datatype(tmp_ptr) == 'RECORD') then
273
274 ! set split string
275 parse_str = trim(input_definition_types(i)%datatype)//' '
276
277 ! split
278 call parseline(parse_str, nwords, words)
279
280 ! check for match and manage memory
281 if (nwords >= 2) then
282 if (words(1) == 'RECORD' .and. &
283 words(2) == tagname .and. &
284 words(3) == tag2) then
285 exit
286 end if
287 end if
288
289 ! deallocate
290 if (allocated(parse_str)) deallocate (parse_str)
291 if (allocated(words)) deallocate (words)
292 end if
293 end do
294 end subroutine split_record_dfn_tag2
295
296 !> @brief return allocated input definition type
297 !<
298 function idt_default(component_type, subcomponent_type, blockname, tagname, &
299 mf6varname, datatype) result(idt)
300 ! -- modules
301 ! -- dummy
302 character(len=*), intent(in) :: component_type
303 character(len=*), intent(in) :: subcomponent_type
304 character(len=*), intent(in) :: blockname
305 character(len=*), intent(in) :: tagname
306 character(len=*), intent(in) :: mf6varname
307 character(len=*), intent(in) :: datatype
308 ! -- result
309 type(inputparamdefinitiontype), pointer :: idt
310
311 allocate (idt)
312
313 idt%component_type = trim(component_type)
314 idt%subcomponent_type = trim(subcomponent_type)
315 idt%blockname = trim(blockname)
316 idt%tagname = trim(tagname)
317 idt%mf6varname = trim(mf6varname)
318 idt%datatype = trim(datatype)
319 idt%shape = ''
320 idt%required = .true.
321 idt%developmode = .false.
322 idt%in_record = .false.
323 idt%preserve_case = .false.
324 idt%layered = .false.
325 idt%timeseries = .false.
326 end function idt_default
327
328end module definitionselectmodule
This module contains simulation constants.
Definition Constants.f90:9
integer(i4b), parameter linelength
maximum length of a standard line
Definition Constants.f90:45
This module contains the DefinitionSelectModule.
type(inputparamdefinitiontype) function, pointer, public idt_default(component_type, subcomponent_type, blockname, tagname, mf6varname, datatype)
return allocated input definition type
subroutine, public split_record_dfn_tag1(input_definition_types, component_type, subcomponent_type, tagname, nwords, words)
Return aggregate definition.
type(inputparamdefinitiontype) function, pointer, public get_aggregate_definition_type(input_definition_types, component_type, subcomponent_type, blockname)
Return aggregate definition.
subroutine, public split_record_dfn_tag2(input_definition_types, component_type, subcomponent_type, tagname, tag2, nwords, words)
Return aggregate definition.
subroutine, public idt_parse_rectype(idt, cols, ncol)
allocate and set RECARRAY, KEYSTRING or RECORD param list
character(len=linelength) function, public idt_datatype(idt)
return input definition type datatype
type(inputparamdefinitiontype) function, pointer, public get_param_definition_type(input_definition_types, component_type, subcomponent_type, blockname, tagname, filename, found)
Return parameter definition.
Input definition module.
subroutine, public parseline(line, nwords, words, inunit, filename)
Parse a line into words.
This module defines variable data types.
Definition kind.f90:8
This module contains simulation methods.
Definition Sim.f90:10
subroutine, public store_error(msg, terminate)
Store an error message.
Definition Sim.f90:94
subroutine, public store_error_filename(filename, terminate)
Store the erroring file name.
Definition Sim.f90:208
This module contains simulation variables.
character(len=maxcharlen) errmsg
error message string
This module contains the SourceCommonModule.
logical(lgp) function, public idm_utl_type(component, subcomponent)
is utility type
Input block definition. Describes an input block.
Input parameter definition. Describes an input parameter.