MODFLOW 6 version 6.9.0.dev0
USGS Modular Hydrologic Model
Loading...
Searching...
No Matches
LoadContext.f90
Go to the documentation of this file.
1!> @brief Load context for IDM generic dynamic loaders.
2!!
3!! LoadContextType classifies each input, builds the in-scope parameter
4!! list for the active block, and manages memory-manager dimension scalars
5!! and array pointers. It is used by all dynamic loaders: ListLoadType,
6!! KeystringLoadType, LayerArrayLoadType, GridArrayLoadType, and
7!! StructArray-based static loads.
8!!
9!<
11
12 use kindmodule, only: dp, i4b, lgp
15 use simvariablesmodule, only: errmsg
16 use simmodule, only: store_error
21
22 implicit none
23 private
24 public :: loadcontexttype
25 public :: readstatevartype
27 public :: rsv_name
28 public :: tslink_id
29 public :: is_keystring_period
30 public :: is_feature_keystring
31 public :: is_advanced
32
33 enum, bind(C)
34 enumerator :: load_undef = 0 !< undefined load type
35 enumerator :: list = 1 !< list load
36 enumerator :: layerarray = 2 !< readasarrays load
37 enumerator :: gridarray = 3 !< readarraygrid load
38 enumerator :: keystring = 4 !< keystring period block load
39 end enum
40
41 !> @brief Read state of a period array (e.g. INRECHARGE)
42 !!
43 !! Set for each period block load.
44 !<
45 enum, bind(C)
46 enumerator :: rs_unset = -1 !< not in use
47 enumerator :: rs_none = 0 !< not given in the most recent period block
48 enumerator :: rs_values = 1 !< values given in the most recent period block
49 enumerator :: rs_series = 2 !< time-array series given in the most recent period block
50 enumerator :: rs_netcdf = 3 !< values read from NetCDF in the most recent period block
51 end enum
52
53 !> @brief Pointer type for read state variable
54 !<
56 integer(I4B), pointer :: invar
57 end type readstatevartype
58
59 interface setptr
60 module procedure setptr_int, setptr_charstr1d, &
62 end interface setptr
63
64 ! addressing modes for an applied keystring setting
65 integer(I4B), parameter, public :: addr_none = 0 !< not an applied setting
66 integer(I4B), parameter, public :: addr_feature = 1 !< addressed by leading id (IFNO/BNDNO)
67 integer(I4B), parameter, public :: addr_node = 2 !< addressed by CELLID
68 integer(I4B), parameter, public :: addr_subindex = 3 !< addressed by (id, subindex)
69
70 !> @brief One descriptor per expanded keystring item, so loaders iterate
71 !! uniformly instead of re-deriving per-mode state.
72 !<
73 type, public :: keystringitemtype
74 type(inputparamdefinitiontype), pointer :: idt => null() !< input definition
75 integer(I4B) :: sa_icol = 0 !< struct-array column (SETTING offset resolved)
76 logical(LGP) :: is_body = .false. !< RECORD body (non-head)
77 integer(I4B) :: head_nbody = 0 !< if a head: number of body members; else 0
78 character(len=LENVARNAME) :: head_setting_varname = '' !< body: owning head's SETTING keyword (dispatch key); '' otherwise
79 logical(LGP) :: idm_managed = .false. !< IDM allocates+applies a permanent array
80 integer(I4B) :: addr_mode = addr_none !< how a row resolves to an index
81 real(dp) :: init_value = dzero !< DZERO (feature/SPC) | DNODATA (node)
82 integer(I4B) :: nfeatures = 0 !< permanent-array length (per-item; LAK lake/outlet)
83 end type keystringitemtype
84
85 !> @brief Input load context for generic dynamic loaders and StructArray
86 !! based static loads. Classifies the input, determines in-scope
87 !! parameters, and manages memory-manager scalars and array pointers.
88 !<
90 ! memory-manager dimension/option scalars and arrays
91 integer(I4B), pointer :: naux => null() !< number of auxiliary variables
92 integer(I4B), pointer :: maxbound => null() !< value associated with named_bound
93 integer(I4B), pointer :: boundnames => null() !< are bound names optioned
94 integer(I4B), pointer :: iprpak => null() !< print input option
95 integer(I4B), pointer :: nbound => null() !< number of bounds in period
96 integer(I4B), pointer :: ncpl => null() !< ncpl associated with model shape
97 integer(I4B), pointer :: nodes => null() !< nodes associated with model shape
98 integer(I4B), dimension(:), pointer, contiguous :: mshape => null() !< model shape
99 type(characterstringtype), dimension(:), pointer, &
100 contiguous :: auxname_cst => null() !< array of auxiliary names
101 type(characterstringtype), dimension(:), pointer, &
102 contiguous :: boundname_cst => null() !< array of bound names
103 real(dp), dimension(:, :), pointer, &
104 contiguous :: auxvar => null() !< auxiliary variable array
105 ! classification
106 integer(I4B) :: loadtype !< load type enum: LIST, LAYERARRAY, GRIDARRAY, KEYSTRING
107 logical(LGP) :: set_scalars = .false. !< .true. when dimension scalars must be set
108 logical(LGP) :: set_mshape = .false. !< .true. when model shape is load dependency
109 logical(LGP) :: is_exchange = .false. !< .true. for exchange contexts
110 logical(LGP) :: is_advanced = .false. !< .true. for an advanced package, any loadtype
111 ! input handle and in-scope params
112 character(len=LENVARNAME) :: blockname !< load block name
113 character(len=LENVARNAME) :: named_bound !< name of dimension variable for maxbound; defaults to MAXBOUND
114 integer(I4B) :: nleading = 0 !< count of leading (pre-keystring) columns
115 character(len=LINELENGTH), dimension(:), allocatable :: params !< in-scope param tagnames
116 type(modflowinputtype) :: mf6_input !< description of input
117 ! keystring-specific (only set for KEYSTRING loads)
118 logical(LGP) :: keystring_by_feature = .false. !< .true. for feature-addressed (IFNO/NUMBER/BNDNO) KEYSTRING loadtype
119 logical(LGP) :: keystring_by_node = .false. !< .true. for CELLID-addressed (e.g. TVK/TVS) KEYSTRING loadtype
120 logical(LGP) :: has_setting_dispatch = .false. !< .true. when keystring_by_feature .or. keystring_by_node
121 type(inputparamdefinitiontype), pointer :: setting_idt => null() !< internal idt for SETTING column
122 integer(I4B) :: nkeystring_items = 0 !< count of expanded keystring items (0 for non-keystring)
123 type(keystringitemtype), allocatable :: keystring_items(:)
124 character(len=LENVARNAME) :: feature_id_varname = '' !< leading id column mf6varname (feature-addressed)
125 contains
126 ! --- public interface ---
127 procedure :: init
128 procedure :: allocate_arrays
129 procedure :: allocate_params
130 procedure :: rsv_alloc
131 procedure :: destroy
132 ! --- internal ---
133 procedure, private :: resolve_context
134 procedure, private :: resolve_loadtype
135 procedure, private :: set_params
136 procedure, private :: keystring_item_names
137 procedure, private :: resolve_dimensions
138 procedure, private :: scale_keystring_maxbound
139 procedure, private :: allocate_param
140 procedure :: check_developmode
141 procedure, private :: in_scope
143 procedure, private :: option_check
145 procedure, private :: resolve_nfeatures
147 procedure, private :: shape_param_is_array
148 end type loadcontexttype
149
150contains
151
152 !> @brief Initialize the load context.
153 !!
154 !! Classifies the input, builds the in-scope parameter list,
155 !! and resolves memory-manager dimension scalars.
156 !<
157 subroutine init(this, mf6_input, blockname, named_bound)
158 use inputoutputmodule, only: upcase
159 class(loadcontexttype) :: this
160 type(modflowinputtype), intent(in) :: mf6_input
161 character(len=*), optional, intent(in) :: blockname
162 character(len=*), optional, intent(in) :: named_bound
163
164 this%mf6_input = mf6_input
165
166 if (present(blockname)) then
167 this%blockname = blockname
168 call upcase(this%blockname)
169 else
170 this%blockname = 'PERIOD'
171 end if
172
173 if (present(named_bound)) then
174 this%named_bound = named_bound
175 call upcase(this%named_bound)
176 else
177 this%named_bound = 'MAXBOUND'
178 end if
179
180 call this%resolve_context()
181 call this%resolve_loadtype()
182 call this%set_params()
183 call this%resolve_dimensions()
184 ! build the per-item descriptor table (keystring only)
185 if (this%loadtype == keystring) call this%build_keystring_items()
186 end subroutine init
187
188 !> @brief Set context flags from input load_scope and component metadata.
189 !<
190 subroutine resolve_context(this)
191 class(loadcontexttype) :: this
192
193 this%set_scalars = .false.
194 this%set_mshape = .false.
195 this%is_exchange = .false.
196
197 select case (this%mf6_input%load_scope)
198 case ('ROOT')
199 ! no memory setup needed for root context
200 case ('SIM')
201 ! only exchange inputs need scalar setup under SIM scope
202 if (this%mf6_input%component_type == 'EXG') then
203 this%set_scalars = .true.
204 this%is_exchange = .true.
205 end if
206 case ('MODEL')
207 this%set_scalars = .true.
208 ! OC and STO are model packages without period block stress data
209 if (this%mf6_input%subcomponent_type /= 'OC' .and. &
210 this%mf6_input%subcomponent_type /= 'STO') then
211 this%set_mshape = .true.
212 end if
213 case default
214 errmsg = 'LoadContext unrecognized load_scope for mempath: '// &
215 trim(this%mf6_input%mempath)
216 call store_error(errmsg, .true.)
217 end select
218 end subroutine resolve_context
219
220 !> @brief Determine loadtype from block and param definitions.
221 !<
222 subroutine resolve_loadtype(this)
225 class(loadcontexttype) :: this
226 type(inputparamdefinitiontype), pointer :: idt, aidt
227 character(len=LINELENGTH), dimension(:), allocatable :: cols
228 integer(I4B) :: n, nparam
229
230 this%loadtype = load_undef
231
232 ! detect aggregate (list/keystring) load type
233 do n = 1, size(this%mf6_input%block_dfns)
234 if (this%mf6_input%block_dfns(n)%blockname == this%blockname) then
235 if (this%mf6_input%block_dfns(n)%aggregate) then
236 if (this%blockname == 'PERIOD' .and. &
237 is_keystring_period(this%mf6_input)) then
238 this%loadtype = keystring
239 else
240 this%loadtype = list
241 end if
242 exit
243 end if
244 end if
245 end do
246
247 this%is_advanced = is_advanced(this%mf6_input)
248
249 ! classify by the KEYSTRING aggregate's own leading column
250 if (this%loadtype == keystring) then
251 aidt => &
252 get_aggregate_definition_type(this%mf6_input%aggregate_dfns, &
253 this%mf6_input%component_type, &
254 this%mf6_input%subcomponent_type, &
255 this%blockname)
256 call idt_parse_rectype(aidt, cols, nparam)
257 if (is_feature_tag(cols(1))) then
258 this%keystring_by_feature = .true.
259 else if (cols(1) == 'CELLID') then
260 this%keystring_by_node = .true.
261 end if
262 if (allocated(cols)) deallocate (cols)
263 this%has_setting_dispatch = &
264 this%keystring_by_feature .or. this%keystring_by_node
265 if (this%has_setting_dispatch) then
266 this%setting_idt => &
267 idt_default(this%mf6_input%component_type, &
268 this%mf6_input%subcomponent_type, &
269 this%blockname, 'SETTING', 'SETTING', 'STRING')
270 end if
271 end if
272
273 ! detect array-based load
274 if (this%loadtype == load_undef) then
275 do n = 1, size(this%mf6_input%param_dfns)
276 idt => this%mf6_input%param_dfns(n)
277 if (idt%blockname == 'OPTIONS') then
278 select case (idt%tagname)
279 case ('READASARRAYS')
280 this%loadtype = layerarray
281 case ('READARRAYGRID')
282 this%loadtype = gridarray
283 case default
284 ! no-op
285 end select
286 end if
287 end do
288 end if
289 end subroutine resolve_loadtype
290
291 !> @brief Resolve dimension scalars and scale keystring maxbound.
292 !<
293 subroutine resolve_dimensions(this)
295 class(loadcontexttype) :: this
296
297 if (this%set_scalars) then
298
299 call setptr(this%nbound, 'NBOUND', this%mf6_input%mempath)
300 call setval(this%naux, 'NAUX', this%mf6_input%mempath)
301 call setval(this%ncpl, 'NCPL', this%mf6_input%mempath)
302 call setval(this%nodes, 'NODES', this%mf6_input%mempath)
303 call setval(this%boundnames, 'BOUNDNAMES', this%mf6_input%mempath)
304 call setval(this%iprpak, 'IPRPAK', this%mf6_input%mempath)
305 call setval(this%maxbound, this%named_bound, this%mf6_input%mempath)
306
307 ! reset nbound
308 this%nbound = 0
309 end if
310
311 if (this%set_mshape .and. &
312 this%blockname == 'PERIOD') then
313 call mem_setptr(this%mshape, 'MODEL_SHAPE', &
314 this%mf6_input%component_mempath)
315
316 if (this%ncpl == 0) then
317 if (size(this%mshape) == 2) then
318 this%ncpl = this%mshape(2)
319 else if (size(this%mshape) == 3) then
320 this%ncpl = this%mshape(2) * this%mshape(3)
321 end if
322 end if
323
324 if (this%nodes == 0) this%nodes = product(this%mshape)
325 if (this%loadtype == keystring) call this%scale_keystring_maxbound()
326 end if
327 end subroutine resolve_dimensions
328
329 !> @brief Scale maxbound (a feature or node count) by the number of
330 !! KEYSTRING items, so every feature can use every setting in one
331 !! period.
332 !<
334 class(loadcontexttype) :: this
335 integer(I4B) :: nkeystring_items
336
337 nkeystring_items = this%nkeystring_items
338
339 if (nkeystring_items > 0) then
340 if (this%maxbound == 0) then
341 if (.not. this%keystring_by_feature) then
342 this%maxbound = this%nodes * nkeystring_items
343 end if
344 ! else: feature-addressed, genuinely zero stays 0
345 else
346 this%maxbound = this%maxbound * nkeystring_items
347 end if
348 end if
349 end subroutine scale_keystring_maxbound
350
351 !> @brief allocate arrays
352 !!
353 !! Call after input parameters are allocated: after load_params() with
354 !! create for array-based loaders, or after all mem_create_vector()
355 !! calls for list-based load.
356 !<
357 subroutine allocate_arrays(this)
359 class(loadcontexttype) :: this
360 integer(I4B), dimension(:, :), pointer, contiguous :: cellid
361 integer(I4B), dimension(:), pointer, contiguous :: nodeulist
362
363 if (this%set_mshape .and. &
364 this%blockname == 'PERIOD') then
365 ! allocate cellid if this is not list input
366 if (this%loadtype == layerarray .or. &
367 this%loadtype == gridarray) then
368 call mem_allocate(cellid, 0, 0, 'CELLID', this%mf6_input%mempath)
369 end if
370
371 ! allocate nodeulist for list and layerarray packages only;
372 ! keystring and advanced packages do not use a flat nodeulist
373 if (this%loadtype /= gridarray .and. &
374 this%loadtype /= keystring) then
375 call mem_allocate(nodeulist, 0, 'NODEULIST', this%mf6_input%mempath)
376 end if
377
378 ! set pointers to aux/bound arrays for non-keystring packages;
379 ! keystring packages manage aux through struct array columns
380 if (this%loadtype /= keystring) then
381 call setptr(this%auxname_cst, 'AUXILIARY', &
382 this%mf6_input%mempath, lenauxname)
383 call setptr(this%boundname_cst, 'BOUNDNAME', &
384 this%mf6_input%mempath, lenboundname)
385 call setptr(this%auxvar, this%mf6_input%mempath)
386 end if
387
388 else if (this%is_exchange) then
389 ! set pointers to arrays
390 call setptr(this%auxname_cst, 'AUXILIARY', &
391 this%mf6_input%mempath, lenauxname)
392 call setptr(this%boundname_cst, 'BOUNDNAME', &
393 this%mf6_input%mempath, lenboundname)
394 call setptr(this%auxvar, this%mf6_input%mempath)
395 end if
396 end subroutine allocate_arrays
397
398 !> @brief allocate a package dynamic input parameter
399 !!
400 !! Called only from allocate_params(), itself called only by the
401 !! LAYERARRAY/GRIDARRAY loaders -- this%loadtype is never LIST here.
402 !<
403 subroutine allocate_param(this, idt)
405 class(loadcontexttype) :: this
406 type(inputparamdefinitiontype), pointer :: idt
407 integer(I4B) :: dimsize
408
409 ! initialize
410 dimsize = 0
411
412 if (this%loadtype == layerarray .or. &
413 this%loadtype == gridarray) then
414 select case (idt%shape)
415 case ('NCPL', 'NAUX NCPL')
416 dimsize = this%ncpl
417 case ('NODES', 'NAUX NODES')
418 dimsize = this%maxbound
419 case default
420 end select
421 end if
422
423 select case (idt%datatype)
424 case ('INTEGER1D')
425 if (this%loadtype == layerarray .or. &
426 this%loadtype == gridarray) then
427 call allocate_int1d(dimsize, idt%mf6varname, &
428 this%mf6_input%mempath)
429 end if
430 case ('DOUBLE1D')
431 if (idt%shape == 'NAUX') then
432 call allocate_dbl2d(this%naux, this%maxbound, &
433 idt%mf6varname, this%mf6_input%mempath)
434 else if (this%loadtype == layerarray .or. &
435 this%loadtype == gridarray) then
436 call allocate_dbl1d(dimsize, idt%mf6varname, &
437 this%mf6_input%mempath)
438 end if
439 case ('DOUBLE2D')
440 if (this%loadtype == layerarray .or. &
441 this%loadtype == gridarray) then
442 call allocate_dbl2d(this%naux, dimsize, idt%mf6varname, &
443 this%mf6_input%mempath)
444 end if
445 case default
446 end select
447 end subroutine allocate_param
448
449 !> @brief Allocate each in-scope parameter in the memory manager.
450 !!
451 !! Call after init() for array-based loaders (LAYERARRAY, GRIDARRAY) that
452 !! need memory-manager storage allocated for every in-scope parameter.
453 !! Loaders access this%params and size(this%params) directly.
454 !<
455 subroutine allocate_params(this)
457 class(loadcontexttype) :: this
458 type(inputparamdefinitiontype), pointer :: idt
459 integer(I4B) :: n
460 do n = 1, size(this%params)
461 idt => get_param_definition_type(this%mf6_input%param_dfns, &
462 this%mf6_input%component_type, &
463 this%mf6_input%subcomponent_type, &
464 this%blockname, this%params(n), '')
465 call this%allocate_param(idt)
466 end do
467 end subroutine allocate_params
468
469 !> @brief Return .true. if an optional parameter is active for this load.
470 !! Required/structural params are handled by the caller; generic
471 !! conditions are checked first, then package-specific ones by
472 !! subcomponent_type.
473 !<
474 function in_scope(this, tagname)
476 class(loadcontexttype) :: this
477 character(len=*), intent(in) :: tagname
478 logical(LGP) :: in_scope
479 type(inputparamdefinitiontype), pointer :: idt
480 character(len=LINELENGTH) :: datatype
481
482 idt => get_param_definition_type(this%mf6_input%param_dfns, &
483 this%mf6_input%component_type, &
484 this%mf6_input%subcomponent_type, &
485 this%blockname, tagname, '')
486 ! required params are always in scope
487 if (idt%required) then
488 in_scope = .true.
489 return
490 else
491 in_scope = .false.
492 end if
493
494 ! structural container types are never loaded as leaf params
495 datatype = idt_datatype(idt)
496 if (datatype == 'KEYSTRING' .or. &
497 datatype == 'RECARRAY' .or. &
498 datatype == 'RECORD') return
499
500 ! advanced packages: every optional leaf param is in scope
501 if (this%is_advanced) then
502 in_scope = .true.
503 return
504 end if
505
506 ! --- generic conditions ---
507 if (tagname == 'AUXVAR' .or. tagname == 'AUX') then
508 in_scope = this%option_check('NAUX', 0)
509 return
510 end if
511
512 if (tagname == 'BOUNDNAME') then
513 in_scope = this%option_check('BOUNDNAMES', 0)
514 return
515 end if
516
517 ! readarray indicator variable (e.g. IRCH, IRET): in scope for LAYERARRAY only
518 if (tagname == 'I'//trim(this%mf6_input%subcomponent_type(1:3))) then
519 in_scope = (this%loadtype == layerarray)
520 return
521 end if
522
523 ! --- package-specific conditions ---
524 select case (this%mf6_input%subcomponent_type)
525 case ('EVT')
526 if (tagname == 'PXDP' .or. tagname == 'PETM') then
527 in_scope = this%option_check('NSEG', 1)
528 else if (tagname == 'PETM0') then
529 in_scope = this%option_check('SURFRATESPEC', 0)
530 end if
531 case ('MVR', 'MVT', 'MVE')
532 if (tagname == 'MNAME' .or. &
533 tagname == 'MNAME1' .or. &
534 tagname == 'MNAME2') then
535 in_scope = this%option_check('MODELNAMES', 0)
536 end if
537 case ('NAM')
538 in_scope = .true.
539 case ('SSM')
540 if (tagname == 'MIXED') in_scope = .true.
541 case ('SPC', 'SPCA')
542 in_scope = .true.
543 case ('SFRTAB')
544 ! MANFRACTION present only when NCOL=3 (2 base columns otherwise)
545 if (tagname == 'MANFRACTION') in_scope = this%option_check('NCOL', 2)
546 case ('LAKTAB')
547 ! BAREA present only for embedded lakes, whose table has 4 columns
548 if (tagname == 'BAREA') in_scope = this%option_check('NCOL', 3)
549 case default
550 ! unrecognized subcomponent with an optional param not handled
551 ! above is a development error -- abort so the gap is visible
552 errmsg = 'LoadContext in_scope needs new case for: '// &
553 trim(this%mf6_input%subcomponent_type)//'/'//trim(tagname)
554 call store_error(errmsg, .true.)
555 end select
556 end function in_scope
557
558 !> @brief Hardcoded per-package dependency for a subindex param
559 !! with no SHAPE of its own -- same category of special-casing as
560 !! in_scope, for a dimension name and subindex field instead.
561 !<
562 function subindex_dependency(this, tagname, dimname, subindex_tagname) &
563 result(found)
564 class(loadcontexttype) :: this
565 character(len=*), intent(in) :: tagname
566 character(len=LENVARNAME), intent(out) :: dimname
567 character(len=LENVARNAME), intent(out) :: subindex_tagname
568 logical(LGP) :: found
569
570 found = .false.
571 dimname = ''
572 subindex_tagname = ''
573 select case (this%mf6_input%subcomponent_type)
574 case ('SFR')
575 if (tagname == 'DIVFLOW') then
576 dimname = 'NDV'
577 subindex_tagname = 'IDV'
578 found = .true.
579 end if
580 end select
581 end function subindex_dependency
582
583 !> @brief Return .true. if a memory-manager integer option variable exceeds a threshold.
584 !<
585 function option_check(this, varname, threshold)
587 class(loadcontexttype) :: this
588 character(len=*), intent(in) :: varname
589 integer(I4B), intent(in) :: threshold
590 logical(LGP) :: option_check
591 integer(I4B) :: isize
592 integer(I4B), pointer :: intptr
593 option_check = .false.
594 call get_isize(varname, this%mf6_input%mempath, isize)
595 if (isize > 0) then
596 call mem_setptr(intptr, varname, this%mf6_input%mempath)
597 if (intptr > threshold) option_check = .true.
598 end if
599 end function option_check
600
601 !> @brief Build the per-item descriptor table, the single source of
602 !! truth for how each keystring item is allocated and applied.
603 !<
604 subroutine build_keystring_items(this)
606 class(loadcontexttype) :: this
607 type(inputparamdefinitiontype), pointer :: idt
608 integer(I4B) :: icol, k, padj, nfeatures, nkeystring_items
609 character(len=LENVARNAME) :: dimname, subindex_tagname
610 logical(LGP) :: found, node
611 character(len=LINELENGTH), allocatable :: item_names(:)
612 integer(I4B), allocatable :: head_nbody(:)
613 logical(LGP), allocatable :: item_is_body(:)
614 character(len=LENVARNAME) :: cur_head !< most recent head's SETTING keyword
615
616 if (.not. this%has_setting_dispatch) return
617
618 ! derive per-item metadata (single computation; not stored as ctx state)
619 call this%keystring_item_names(item_names, head_nbody, item_is_body, &
620 nkeystring_items)
621 if (nkeystring_items < 1) return
622
623 ! generic leading-id address varname (feature-addressed packages,
624 ! advanced or not, e.g. SPC): the leading column's mf6varname.
625 if (this%keystring_by_feature) then
626 idt => get_param_definition_type(this%mf6_input%param_dfns, &
627 this%mf6_input%component_type, &
628 this%mf6_input%subcomponent_type, &
629 this%blockname, this%params(1), '')
630 this%feature_id_varname = trim(idt%mf6varname)
631 end if
632
633 padj = 1 ! SETTING column present whenever has_setting_dispatch
634 node = this%keystring_by_node
635
636 allocate (this%keystring_items(nkeystring_items))
637 nfeatures = this%resolve_nfeatures()
638 cur_head = ''
639
640 do icol = this%nleading + 1, size(this%params)
641 k = icol - this%nleading
642 idt => get_param_definition_type(this%mf6_input%param_dfns, &
643 this%mf6_input%component_type, &
644 this%mf6_input%subcomponent_type, &
645 this%blockname, this%params(icol), '')
646 this%keystring_items(k)%idt => idt
647 this%keystring_items(k)%sa_icol = icol + padj
648 this%keystring_items(k)%is_body = item_is_body(k)
649 this%keystring_items(k)%head_nbody = head_nbody(k)
650
651 ! track the current record head's SETTING keyword; a body dispatches
652 ! on its owning head's keyword (the SETTING token on the input row),
653 ! not on its own mf6varname.
654 if (.not. this%keystring_items(k)%is_body) then
655 if (this%keystring_items(k)%head_nbody > 0) then
656 cur_head = trim(idt%mf6varname) ! opening a RECORD
657 else
658 cur_head = '' ! standalone item; not a record head
659 end if
660 else
661 this%keystring_items(k)%head_setting_varname = trim(cur_head)
662 end if
663
664 ! managed only for DOUBLE + timeseries standalone settings, which
665 ! require a permanent array for cross-period timeseries persistence.
666 this%keystring_items(k)%idm_managed = &
667 (idt%datatype == 'DOUBLE' .and. idt%timeseries .and. &
668 .not. this%keystring_items(k)%is_body)
669
670 if (this%keystring_items(k)%idm_managed) then
671 if (node) then
672 this%keystring_items(k)%addr_mode = addr_node
673 this%keystring_items(k)%init_value = dnodata
674 if (associated(this%nodes)) &
675 this%keystring_items(k)%nfeatures = this%nodes
676 else
677 this%keystring_items(k)%addr_mode = addr_feature
678 this%keystring_items(k)%init_value = dzero
679 this%keystring_items(k)%nfeatures = &
680 this%resolve_item_nfeatures(idt%tagname, idt%shape, nfeatures)
681 end if
682 end if
683
684 ! subindex (SFR DIVFLOW): classify here; df-time fields
685 ! (index_icol/head_icol/offsets/nfeatures) are completed in df().
686 if (this%is_advanced .and. this%keystring_items(k)%is_body) then
687 found = this%subindex_dependency(idt%tagname, dimname, &
688 subindex_tagname)
689 if (found) then
690 this%keystring_items(k)%addr_mode = addr_subindex
691 this%keystring_items(k)%idm_managed = .true.
692 end if
693 end if
694 end do
695 end subroutine build_keystring_items
696
697 !> @brief Resolve the permanent array's feature count. The explicit
698 !! DIMENSIONS dimension (named_bound) is authoritative when present;
699 !! PACKAGEDATA row count is the fallback. Both present and disagreeing
700 !! is an error.
701 !<
702 function resolve_nfeatures(this) result(nfeatures)
705 use simmodule, only: store_error
706 class(loadcontexttype) :: this
707 integer(I4B) :: nfeatures
708 integer(I4B) :: isize, nkeystring_items, nrow, ndim
709 integer(I4B), pointer :: dimval
710 logical(LGP) :: have_dim, have_nrow
711 character(len=LINELENGTH) :: errmsg
712
713 ! read the RAW dimension scalar from the memory manager, not
714 ! this%maxbound (a scaled copy used only for read-array sizing)
715 ndim = 0
716 have_dim = .false.
717 allocate (dimval)
718 dimval = 0
719 call mem_set_value(dimval, this%named_bound, this%mf6_input%mempath, &
720 have_dim, release=.false.)
721 if (have_dim) ndim = dimval
722 deallocate (dimval)
723
724 call get_isize('PACKAGEDATA_IFNO', this%mf6_input%mempath, isize)
725 have_nrow = (isize > 0)
726 nrow = isize
727
728 if (have_dim .and. have_nrow .and. ndim /= nrow) then
729 write (errmsg, '(a,1x,a,1x,i0,1x,a,1x,i0,a)') &
730 'IDM dimension mismatch:', trim(this%named_bound), ndim, &
731 'does not match the PACKAGEDATA row count', nrow, '.'
732 call store_error(errmsg)
733 end if
734
735 if (have_dim) then
736 nfeatures = ndim
737 return
738 else if (have_nrow) then
739 nfeatures = nrow
740 return
741 end if
742
743 ! defensive: only if neither an explicit dimension nor PACKAGEDATA
744 ! is available (not expected for current packages)
745 nfeatures = 0
746 nkeystring_items = this%nkeystring_items
747 if (nkeystring_items > 0 .and. associated(this%maxbound)) then
748 if (this%maxbound > 0) nfeatures = this%maxbound / nkeystring_items
749 end if
750 end function resolve_nfeatures
751
752 !> @brief Per-item feature count from a named dimension, falling back to
753 !! default_nfeatures if unset. Populated-then-released is an error.
754 !<
755 function resolve_item_nfeatures(this, item_tagname, dimname, &
756 default_nfeatures) result(nfeatures)
758 use simmodule, only: store_error
759 class(loadcontexttype) :: this
760 character(len=*), intent(in) :: item_tagname
761 character(len=*), intent(in) :: dimname
762 integer(I4B), intent(in) :: default_nfeatures
763 integer(I4B) :: nfeatures
764 integer(I4B), pointer :: shape_val => null()
765 integer(I4B), dimension(:), pointer, contiguous :: shape_arr => null()
766 integer(I4B) :: isize
767 character(len=LINELENGTH) :: errmsg
768
769 nfeatures = default_nfeatures
770 if (dimname == '') return
771 call get_isize(trim(dimname), this%mf6_input%mempath, isize)
772 if (isize < 0) then
773 nfeatures = 0
774 return
775 else if (isize == 0) then
776 write (errmsg, '(a,1x,a,1x,a)') &
777 'item', trim(item_tagname)//': DIMENSION', &
778 trim(dimname)//' is not defined.'
779 call store_error(errmsg)
780 nfeatures = 0
781 return
782 else if (.not. this%shape_param_is_array(trim(dimname))) then
783 call mem_setptr(shape_val, trim(dimname), this%mf6_input%mempath)
784 nfeatures = shape_val
785 else
786 call mem_setptr(shape_arr, trim(dimname), this%mf6_input%mempath)
787 nfeatures = sum(shape_arr)
788 end if
789 end function resolve_item_nfeatures
790
791 !> @brief Is shape_varname a per-feature array (PACKAGEDATA) rather than
792 !! a package-wide scalar (DIMENSIONS)?
793 !<
794 function shape_param_is_array(this, shape_varname) result(is_array)
795 class(loadcontexttype) :: this
796 character(len=*), intent(in) :: shape_varname
797 logical(LGP) :: is_array
798 integer(I4B) :: i
799
800 is_array = .false.
801 do i = 1, size(this%mf6_input%param_dfns)
802 if (this%mf6_input%param_dfns(i)%component_type == &
803 this%mf6_input%component_type .and. &
804 this%mf6_input%param_dfns(i)%subcomponent_type == &
805 this%mf6_input%subcomponent_type .and. &
806 trim(this%mf6_input%param_dfns(i)%mf6varname) == &
807 trim(shape_varname)) then
808 is_array = &
809 (trim(this%mf6_input%param_dfns(i)%blockname) == 'PACKAGEDATA')
810 exit
811 end if
812 end do
813 end function shape_param_is_array
814
815 !> @brief set set of in scope parameters for package
816 !<
817 subroutine set_params(this)
822 class(loadcontexttype) :: this
823 type(inputparamdefinitiontype), pointer :: idt, aidt
824 character(len=LINELENGTH), dimension(:), allocatable :: param_buf
825 character(len=LINELENGTH), dimension(:), allocatable :: cols
826 character(len=LINELENGTH), allocatable :: item_names(:)
827 integer(I4B), allocatable :: head_nbody(:)
828 logical(LGP), allocatable :: item_is_body(:)
829 integer(I4B) :: keepcnt, iparam, nparam, nkeystring_items, n
830 logical(LGP) :: keep, tag_found
831
832 ! initialize
833 keepcnt = 0
834
835 if (this%loadtype == list .or. &
836 this%loadtype == keystring) then
837 ! get aggregate param definition for period block
838 aidt => &
839 get_aggregate_definition_type(this%mf6_input%aggregate_dfns, &
840 this%mf6_input%component_type, &
841 this%mf6_input%subcomponent_type, &
842 this%blockname)
843 ! split recarray definition
844 call idt_parse_rectype(aidt, cols, nparam)
845 else
846 nparam = size(this%mf6_input%param_dfns)
847 end if
848
849 ! allocate dfn input params
850 do iparam = 1, nparam
851 if (this%loadtype == list .or. &
852 this%loadtype == keystring) then
853 ! use found so keystring placeholders are silently skipped
854 idt => get_param_definition_type(this%mf6_input%param_dfns, &
855 this%mf6_input%component_type, &
856 this%mf6_input%subcomponent_type, &
857 this%blockname, cols(iparam), '', &
858 found=tag_found)
859 else
860 tag_found = .true.
861 idt => this%mf6_input%param_dfns(iparam)
862 end if
863
864 if (.not. tag_found) then
865 keep = .false.
866 else if (idt%blockname /= this%blockname) then
867 keep = .false.
868 else
869 keep = this%in_scope(idt%tagname)
870 end if
871
872 if (keep) then
873 keepcnt = keepcnt + 1
874 call expandarray(param_buf)
875 param_buf(keepcnt) = trim(idt%tagname)
876 end if
877 end do
878
879 ! record leading-column count before item expansion
880 if (this%loadtype == list .or. &
881 this%loadtype == keystring) this%nleading = keepcnt
882
883 ! for keystring packages: append item names (metadata head_nbody/
884 ! item_is_body is derived into the descriptor by build_keystring_items)
885 if (this%loadtype == keystring) then
886 call this%keystring_item_names(item_names, head_nbody, &
887 item_is_body, nkeystring_items)
888 this%nkeystring_items = nkeystring_items
889 do n = 1, nkeystring_items
890 keepcnt = keepcnt + 1
891 call expandarray(param_buf)
892 param_buf(keepcnt) = trim(item_names(n))
893 end do
894 end if
895
896 ! update nparam to total (leading + items)
897 nparam = keepcnt
898
899 ! allocate and fill params
900 allocate (this%params(nparam))
901 do iparam = 1, nparam
902 this%params(iparam) = trim(param_buf(iparam))
903 end do
904
905 ! cleanup
906 if (allocated(param_buf)) deallocate (param_buf)
907 end subroutine set_params
908
909 !> @brief allocate a read state variable
910 !!
911 !! Create a read state variable, e.g. 'INRECHARGE', set to RS_UNSET.
912 !! Loaders update it for each period block (see RS_*).
913 !<
914 function rsv_alloc(this, mf6varname) result(varname)
915 use constantsmodule, only: lenvarname
917 class(loadcontexttype) :: this
918 character(len=*), intent(in) :: mf6varname
919 character(len=LENVARNAME) :: varname
920 integer(I4B), pointer :: intvar
921 varname = rsv_name(mf6varname)
922 call mem_allocate(intvar, varname, this%mf6_input%mempath)
923 intvar = rs_unset
924 end function rsv_alloc
925
926 !> @brief destroy input context object
927 !<
928 subroutine destroy(this)
929 class(loadcontexttype) :: this
930
931 if (associated(this%setting_idt)) then
932 deallocate (this%setting_idt)
933 nullify (this%setting_idt)
934 end if
935
936 if (this%set_scalars) then
937 ! deallocate local
938 deallocate (this%naux)
939 deallocate (this%ncpl)
940 deallocate (this%nodes)
941 deallocate (this%maxbound)
942 deallocate (this%boundnames)
943 deallocate (this%iprpak)
944 end if
945
946 ! nullify
947 nullify (this%naux)
948 nullify (this%nbound)
949 nullify (this%ncpl)
950 nullify (this%nodes)
951 nullify (this%maxbound)
952 nullify (this%boundnames)
953 nullify (this%iprpak)
954 nullify (this%auxname_cst)
955 nullify (this%boundname_cst)
956 nullify (this%auxvar)
957 nullify (this%mshape)
958 end subroutine destroy
959
960 !> @brief Return the KEYSTRING aggregate for the SETTING token in rec_cols, or null().
961 !<
962 function find_setting_aggregate(mf6_input, rec_cols, nrec_col) result(ks_aidt)
963 use inputoutputmodule, only: upcase
965 type(modflowinputtype), intent(in) :: mf6_input
966 character(len=LINELENGTH), intent(in) :: rec_cols(:)
967 integer(I4B), intent(in) :: nrec_col
968 type(inputparamdefinitiontype), pointer :: ks_aidt
969 character(len=LINELENGTH) :: token, tagname
970 integer(I4B) :: m, n, ilen
971 ks_aidt => null()
972 do m = 1, nrec_col
973 token = trim(rec_cols(m))
974 call upcase(token)
975 ilen = len_trim(token)
976 ! minimum 8 chars: a valid XSETTING token is at least 1 char prefix + 7 for 'SETTING'
977 if (ilen < 8) cycle
978 if (token(ilen - 6:ilen) /= 'SETTING') cycle
979 do n = 1, size(mf6_input%aggregate_dfns)
980 tagname = mf6_input%aggregate_dfns(n)%tagname
981 call upcase(tagname)
982 if (trim(tagname) == trim(token)) then
983 ks_aidt => mf6_input%aggregate_dfns(n)
984 if (idt_datatype(ks_aidt) /= 'KEYSTRING') ks_aidt => null()
985 exit
986 end if
987 end do
988 exit
989 end do
990 end function find_setting_aggregate
991
992 !> @brief Append body column names from a RECORD compound entry to item_names.
993 !<
994 subroutine expand_record_body(mf6_input, rec_idt, item_names, nkeystring_items)
995 use inputoutputmodule, only: upcase
998 type(modflowinputtype), intent(in) :: mf6_input
999 type(inputparamdefinitiontype), pointer, intent(in) :: rec_idt
1000 character(len=LINELENGTH), allocatable, intent(inout) :: item_names(:)
1001 integer(I4B), intent(inout) :: nkeystring_items
1002 type(inputparamdefinitiontype), pointer :: sub_idt
1003 character(len=LINELENGTH), allocatable :: sub_cols(:)
1004 character(len=LINELENGTH) :: token, tagname
1005 integer(I4B) :: k, j, nsub_col
1006 call idt_parse_rectype(rec_idt, sub_cols, nsub_col)
1007 do k = 1, nsub_col
1008 token = trim(sub_cols(k))
1009 call upcase(token)
1010 do j = 1, size(mf6_input%param_dfns)
1011 sub_idt => mf6_input%param_dfns(j)
1012 if (sub_idt%blockname /= 'PERIOD') cycle
1013 tagname = sub_idt%tagname
1014 call upcase(tagname)
1015 if (trim(tagname) /= trim(token)) cycle
1016 if (idt_datatype(sub_idt) == 'RECORD') cycle
1017 nkeystring_items = nkeystring_items + 1
1018 call expandarray(item_names)
1019 item_names(nkeystring_items) = trim(sub_idt%tagname)
1020 exit
1021 end do
1022 end do
1023 if (allocated(sub_cols)) deallocate (sub_cols)
1024 end subroutine expand_record_body
1025
1026 !> @brief Return .true. if mf6_input's PERIOD block uses keystring dispatch.
1027 !<
1028 function is_keystring_period(mf6_input) result(res)
1031 type(modflowinputtype), intent(in) :: mf6_input
1032 logical(LGP) :: res, has_period
1033 type(inputparamdefinitiontype), pointer :: aidt, ks_aidt
1034 character(len=LINELENGTH), allocatable :: cols(:)
1035 integer(I4B) :: n, ncol
1036 res = .false.
1037 has_period = .false.
1038 do n = 1, size(mf6_input%block_dfns)
1039 if (mf6_input%block_dfns(n)%blockname == 'PERIOD') then
1040 has_period = .true.
1041 end if
1042 end do
1043 if (.not. has_period) return
1044 aidt => get_aggregate_definition_type(mf6_input%aggregate_dfns, &
1045 mf6_input%component_type, &
1046 mf6_input%subcomponent_type, &
1047 'PERIOD')
1048 call idt_parse_rectype(aidt, cols, ncol)
1049 if (ncol >= 2) then
1050 ks_aidt => find_setting_aggregate(mf6_input, cols, ncol)
1051 if (associated(ks_aidt)) res = .true.
1052 end if
1053 if (allocated(cols)) deallocate (cols)
1054 end function is_keystring_period
1055
1056 !> @brief .true. if mf6_input's PERIOD block is feature-addressed
1057 !! (see is_feature_tag). Block-independent, unlike LoadContextType's own
1058 !! keystring_by_feature, which is only valid for a PERIOD-scoped instance.
1059 !<
1060 function is_feature_keystring(mf6_input) result(res)
1063 type(modflowinputtype), intent(in) :: mf6_input
1064 logical(LGP) :: res
1065 type(inputparamdefinitiontype), pointer :: aidt
1066 character(len=LINELENGTH), allocatable :: cols(:)
1067 integer(I4B) :: ncol
1068 res = .false.
1069 if (.not. is_keystring_period(mf6_input)) return
1070 aidt => get_aggregate_definition_type(mf6_input%aggregate_dfns, &
1071 mf6_input%component_type, &
1072 mf6_input%subcomponent_type, &
1073 'PERIOD')
1074 call idt_parse_rectype(aidt, cols, ncol)
1075 res = is_feature_tag(cols(1))
1076 if (allocated(cols)) deallocate (cols)
1077 end function is_feature_keystring
1078
1079 !> @brief .true. if tagname is a record's leading id column (IFNO and
1080 !! its legacy package-specific aliases). Single source for both
1081 !! resolve_loadtype and is_feature_keystring.
1082 !<
1083 function is_feature_tag(tagname) result(res)
1084 character(len=*), intent(in) :: tagname
1085 logical(LGP) :: res
1086 select case (tagname)
1087 case ('IFNO', 'NUMBER', 'BNDNO', 'RNO', 'LAKENO', 'MAWNO', 'UZFNO')
1088 res = .true.
1089 case default
1090 res = .false.
1091 end select
1092 end function is_feature_tag
1093
1094 !> @brief Return .true. if mf6_input is an advanced package
1095 !<
1096 function is_advanced(mf6_input) result(res)
1097 type(modflowinputtype), intent(in) :: mf6_input
1098 logical(LGP) :: res
1099 res = idm_is_advanced(mf6_input%component_type, mf6_input%subcomponent_type)
1100 end function is_advanced
1101
1102 !> @brief Return keystring item column names, per-head body counts, and
1103 !! body flags. A RECORD group's trailing columns are body members; its head
1104 !! and any direct-dispatch param are not.
1105 !<
1106 subroutine keystring_item_names(this, item_names, head_nbody, &
1107 item_is_body, nkeystring_items)
1108 use inputoutputmodule, only: upcase
1112 class(loadcontexttype) :: this
1113 character(len=LINELENGTH), allocatable, intent(out) :: item_names(:)
1114 integer(I4B), allocatable, intent(out) :: head_nbody(:)
1115 logical(LGP), allocatable, intent(out) :: item_is_body(:)
1116 integer(I4B), intent(out) :: nkeystring_items
1117 type(inputparamdefinitiontype), pointer :: aidt, ks_aidt, idt
1118 character(len=LINELENGTH), allocatable :: rec_cols(:), ks_cols(:)
1119 character(len=LINELENGTH) :: rec_token, tagname
1120 integer(I4B) :: m, n, nrec_col, nks_col, nitems0, k
1121
1122 nkeystring_items = 0
1123
1124 ! get RECARRAY aggregate for period block and parse its column tokens
1125 aidt => get_aggregate_definition_type(this%mf6_input%aggregate_dfns, &
1126 this%mf6_input%component_type, &
1127 this%mf6_input%subcomponent_type, &
1128 this%blockname)
1129 call idt_parse_rectype(aidt, rec_cols, nrec_col)
1130
1131 ! find the KEYSTRING aggregate for the SETTING token
1132 ks_aidt => find_setting_aggregate(this%mf6_input, rec_cols, nrec_col)
1133 if (allocated(rec_cols)) deallocate (rec_cols)
1134 if (.not. associated(ks_aidt)) return
1135
1136 ! parse the KEYSTRING aggregate to get item token list — canonical order
1137 call idt_parse_rectype(ks_aidt, ks_cols, nks_col)
1138
1139 ! walk the keystring token list in aggregate order
1140 do m = 1, nks_col
1141 rec_token = trim(ks_cols(m))
1142 call upcase(rec_token)
1143
1144 ! locate matching param_dfns entry for this token
1145 do n = 1, size(this%mf6_input%param_dfns)
1146 if (this%mf6_input%param_dfns(n)%blockname /= this%blockname) cycle
1147 tagname = this%mf6_input%param_dfns(n)%tagname
1148 call upcase(tagname)
1149 if (trim(tagname) /= trim(rec_token)) cycle
1150
1151 idt => this%mf6_input%param_dfns(n)
1152 if (idt_datatype(idt) == 'RECORD') then
1153 ! compound group: expand body members in RECORD type order
1154 nitems0 = nkeystring_items
1155 call expand_record_body(this%mf6_input, idt, item_names, &
1156 nkeystring_items)
1157 ! first added entry is the KEYWORD head; remaining are body members
1158 do k = nitems0 + 1, nkeystring_items
1159 call expandarray(head_nbody)
1160 call expandarray(item_is_body)
1161 if (k == nitems0 + 1) then
1162 head_nbody(k) = nkeystring_items - nitems0 - 1
1163 item_is_body(k) = .false.
1164 else
1165 head_nbody(k) = 0
1166 item_is_body(k) = .true.
1167 end if
1168 end do
1169 else
1170 ! direct-dispatch param
1171 nkeystring_items = nkeystring_items + 1
1172 call expandarray(item_names)
1173 call expandarray(head_nbody)
1174 call expandarray(item_is_body)
1175 item_names(nkeystring_items) = &
1176 trim(this%mf6_input%param_dfns(n)%tagname)
1177 head_nbody(nkeystring_items) = 0
1178 item_is_body(nkeystring_items) = .false.
1179 end if
1180 exit
1181 end do
1182 end do
1183
1184 if (allocated(ks_cols)) deallocate (ks_cols)
1185 end subroutine keystring_item_names
1186
1187 !> @brief Check whether any in-scope parameter is a development-mode feature.
1188 !<
1189 subroutine check_developmode(this, input_name)
1191 use simvariablesmodule, only: iout
1193 class(loadcontexttype) :: this
1194 character(len=*), intent(in) :: input_name
1195 type(inputparamdefinitiontype), pointer :: idt
1196 character(len=LINELENGTH) :: dev_msg
1197 integer(I4B) :: n
1198
1199 do n = 1, size(this%params)
1200 idt => get_param_definition_type(this%mf6_input%param_dfns, &
1201 this%mf6_input%component_type, &
1202 this%mf6_input%subcomponent_type, &
1203 this%blockname, this%params(n), '')
1204 if (idt%developmode) then
1205 dev_msg = 'Input tag "'//trim(idt%tagname)// &
1206 &'" read from file "'//trim(input_name)// &
1207 &'" is still under development. Install the &
1208 &nightly build or compile from source with IDEVELOPMODE = 1.'
1209 call developmode(dev_msg, iout)
1210 end if
1211 end do
1212 end subroutine check_developmode
1213
1214 !> @brief create read state variable name
1215 !<
1216 function rsv_name(mf6varname) result(varname)
1217 use constantsmodule, only: lenvarname
1218 character(len=*), intent(in) :: mf6varname
1219 character(len=LENVARNAME) :: varname
1220 integer(I4B) :: ilen
1221 character(len=2) :: prefix = 'IN'
1222 ilen = len_trim(mf6varname)
1223 if (ilen > (lenvarname - len(prefix))) then
1224 varname = prefix//mf6varname(1:(lenvarname - len(prefix)))
1225 else
1226 varname = prefix//trim(mf6varname)
1227 end if
1228 end function rsv_name
1229
1230 !> @brief time series link identifier for a static block
1231 !!
1232 !! Return the identifier used to name a static block's time series link
1233 !! variables (TSLINK_<id>, TSLINKVARS_<id>), or an empty string if the
1234 !! block has none.
1235 !<
1236 function tslink_id(blockname) result(id)
1237 character(len=*), intent(in) :: blockname
1238 character(len=2) :: id
1239 select case (blockname)
1240 case ('PACKAGEDATA')
1241 id = 'PD'
1242 case ('OUTLETS')
1243 id = 'OL'
1244 case default
1245 id = ''
1246 end select
1247 end function tslink_id
1248
1249 !> @brief allocate int1d
1250 !<
1251 subroutine allocate_int1d(nrow, varname, mempath)
1253 integer(I4B), intent(in) :: nrow !< integer array number of rows
1254 character(len=*), intent(in) :: varname !< variable name
1255 character(len=*), intent(in) :: mempath !< variable mempath
1256 integer(I4B), dimension(:), pointer, contiguous :: int1d
1257 integer(I4B) :: n
1258 call mem_allocate(int1d, nrow, varname, mempath)
1259 do n = 1, nrow
1260 int1d(n) = izero
1261 end do
1262 end subroutine allocate_int1d
1263
1264 !> @brief allocate dbl1d
1265 !<
1266 subroutine allocate_dbl1d(nrow, varname, mempath)
1268 integer(I4B), intent(in) :: nrow !< integer array number of rows
1269 character(len=*), intent(in) :: varname !< variable name
1270 character(len=*), intent(in) :: mempath !< variable mempath
1271 real(DP), dimension(:), pointer, contiguous :: dbl1d
1272 integer(I4B) :: n
1273 call mem_allocate(dbl1d, nrow, varname, mempath)
1274 do n = 1, nrow
1275 dbl1d(n) = dzero
1276 end do
1277 end subroutine allocate_dbl1d
1278
1279 !> @brief allocate dbl2d
1280 !<
1281 subroutine allocate_dbl2d(ncol, nrow, varname, mempath)
1283 integer(I4B), intent(in) :: ncol !< integer array number of cols
1284 integer(I4B), intent(in) :: nrow !< integer array number of rows
1285 character(len=*), intent(in) :: varname !< variable name
1286 character(len=*), intent(in) :: mempath !< variable mempath
1287 real(DP), dimension(:, :), pointer, contiguous :: dbl2d
1288 integer(I4B) :: n, m
1289 call mem_allocate(dbl2d, ncol, nrow, varname, mempath)
1290 do m = 1, nrow
1291 do n = 1, ncol
1292 dbl2d(n, m) = dzero
1293 end do
1294 end do
1295 end subroutine allocate_dbl2d
1296
1297 !> @brief allocate intptr and update from input context
1298 !!
1299 !<
1300 subroutine setval(intptr, varname, mempath)
1302 integer(I4B), pointer, intent(inout) :: intptr
1303 character(len=*), intent(in) :: varname
1304 character(len=*), intent(in) :: mempath
1305 logical(LGP) :: found
1306 allocate (intptr)
1307 intptr = 0
1308 call mem_set_value(intptr, varname, mempath, found, release=.false.)
1309 end subroutine setval
1310
1311 !> @brief set intptr to varname
1312 !!
1313 !<
1314 subroutine setptr_int(intptr, varname, mempath)
1316 integer(I4B), pointer, intent(inout) :: intptr
1317 character(len=*), intent(in) :: varname
1318 character(len=*), intent(in) :: mempath
1319 integer(I4B) :: isize
1320 call get_isize(varname, mempath, isize)
1321 if (isize > -1) then
1322 call mem_setptr(intptr, varname, mempath)
1323 else
1324 call mem_allocate(intptr, varname, mempath)
1325 intptr = 0
1326 end if
1327 end subroutine setptr_int
1328
1329 !> @brief set charstr1d pointer to varname
1330 !<
1331 subroutine setptr_charstr1d(charstr1d, varname, mempath, strlen)
1333 type(characterstringtype), dimension(:), pointer, &
1334 contiguous, intent(inout) :: charstr1d
1335 character(len=*), intent(in) :: varname
1336 character(len=*), intent(in) :: mempath
1337 integer(I4B), intent(in) :: strlen
1338 integer(I4B) :: isize
1339 call get_isize(varname, mempath, isize)
1340 if (isize > -1) then
1341 call mem_setptr(charstr1d, varname, mempath)
1342 else
1343 call mem_allocate(charstr1d, strlen, 0, varname, mempath)
1344 end if
1345 end subroutine setptr_charstr1d
1346
1347 !> @brief set auxvar pointer
1348 !!
1349 !<
1350 subroutine setptr_auxvar(auxvar, mempath)
1352 real(DP), dimension(:, :), pointer, &
1353 contiguous, intent(inout) :: auxvar
1354 character(len=*), intent(in) :: mempath
1355 integer(I4B) :: isize
1356 call get_isize('AUXVAR', mempath, isize)
1357 if (isize > -1) then
1358 call mem_setptr(auxvar, 'AUXVAR', mempath)
1359 else
1360 call mem_allocate(auxvar, 0, 0, 'AUXVAR', mempath)
1361 end if
1362 end subroutine setptr_auxvar
1363
1364end module loadcontextmodule
subroutine destroy(this)
This module contains simulation constants.
Definition Constants.f90:9
integer(i4b), parameter linelength
maximum length of a standard line
Definition Constants.f90:45
real(dp), parameter dnodata
real no data constant
Definition Constants.f90:95
integer(i4b), parameter lenvarname
maximum length of a variable name
Definition Constants.f90:17
integer(i4b), parameter lenauxname
maximum length of a aux variable
Definition Constants.f90:35
integer(i4b), parameter lenboundname
maximum length of a bound name
Definition Constants.f90:36
integer(i4b), parameter izero
integer constant zero
Definition Constants.f90:51
real(dp), parameter dzero
real constant zero
Definition Constants.f90:65
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
type(inputparamdefinitiontype) function, pointer, public get_aggregate_definition_type(input_definition_types, component_type, subcomponent_type, blockname)
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.
Disable development features in release mode.
subroutine, public developmode(errmsg, iunit)
Terminate if in release mode (guard development features).
logical function, public idm_is_advanced(component, subcomponent)
Input definition module.
subroutine, public upcase(word)
Convert to upper case.
This module defines variable data types.
Definition kind.f90:8
Load context for IDM generic dynamic loaders.
subroutine set_params(this)
set set of in scope parameters for package
subroutine expand_record_body(mf6_input, rec_idt, item_names, nkeystring_items)
Append body column names from a RECORD compound entry to item_names.
subroutine allocate_dbl2d(ncol, nrow, varname, mempath)
allocate dbl2d
subroutine build_keystring_items(this)
Build the per-item descriptor table, the single source of truth for how each keystring item is alloca...
subroutine setptr_auxvar(auxvar, mempath)
set auxvar pointer
logical(lgp) function option_check(this, varname, threshold)
Return .true. if a memory-manager integer option variable exceeds a threshold.
integer(i4b), parameter, public addr_feature
addressed by leading id (IFNO/BNDNO)
character(len=2) function, public tslink_id(blockname)
time series link identifier for a static block
subroutine check_developmode(this, input_name)
Check whether any in-scope parameter is a development-mode feature.
integer(i4b), parameter, public addr_none
not an applied setting
logical(lgp) function, public is_feature_keystring(mf6_input)
.true. if mf6_input's PERIOD block is feature-addressed (see is_feature_tag). Block-independent,...
subroutine allocate_params(this)
Allocate each in-scope parameter in the memory manager.
logical(lgp) function shape_param_is_array(this, shape_varname)
Is shape_varname a per-feature array (PACKAGEDATA) rather than a package-wide scalar (DIMENSIONS)?
subroutine resolve_loadtype(this)
Determine loadtype from block and param definitions.
subroutine allocate_int1d(nrow, varname, mempath)
allocate int1d
subroutine keystring_item_names(this, item_names, head_nbody, item_is_body, nkeystring_items)
Return keystring item column names, per-head body counts, and body flags. A RECORD group's trailing c...
integer(i4b), parameter, public addr_subindex
addressed by (id, subindex)
@ load_undef
undefined load type
@ gridarray
readarraygrid load
@ keystring
keystring period block load
@ layerarray
readasarrays load
type(inputparamdefinitiontype) function, pointer find_setting_aggregate(mf6_input, rec_cols, nrec_col)
Return the KEYSTRING aggregate for the SETTING token in rec_cols, or null().
subroutine allocate_dbl1d(nrow, varname, mempath)
allocate dbl1d
@ rs_series
time-array series given in the most recent period block
@ rs_netcdf
values read from NetCDF in the most recent period block
@ rs_values
values given in the most recent period block
@ rs_none
not given in the most recent period block
@ rs_unset
not in use
logical(lgp) function is_feature_tag(tagname)
.true. if tagname is a record's leading id column (IFNO and its legacy package-specific aliases)....
integer(i4b) function resolve_item_nfeatures(this, item_tagname, dimname, default_nfeatures)
Per-item feature count from a named dimension, falling back to default_nfeatures if unset....
subroutine setval(intptr, varname, mempath)
allocate intptr and update from input context
subroutine allocate_param(this, idt)
allocate a package dynamic input parameter
subroutine resolve_dimensions(this)
Resolve dimension scalars and scale keystring maxbound.
logical(lgp) function, public is_advanced(mf6_input)
Return .true. if mf6_input is an advanced package.
subroutine allocate_arrays(this)
allocate arrays
subroutine setptr_int(intptr, varname, mempath)
set intptr to varname
integer(i4b) function resolve_nfeatures(this)
Resolve the permanent array's feature count. The explicit DIMENSIONS dimension (named_bound) is autho...
subroutine init(this, mf6_input, blockname, named_bound)
Initialize the load context.
subroutine scale_keystring_maxbound(this)
Scale maxbound (a feature or node count) by the number of KEYSTRING items, so every feature can use e...
subroutine resolve_context(this)
Set context flags from input load_scope and component metadata.
logical(lgp) function subindex_dependency(this, tagname, dimname, subindex_tagname)
Hardcoded per-package dependency for a subindex param with no SHAPE of its own – same category of spe...
character(len=lenvarname) function, public rsv_name(mf6varname)
create read state variable name
character(len=lenvarname) function rsv_alloc(this, mf6varname)
allocate a read state variable
logical(lgp) function in_scope(this, tagname)
Return .true. if an optional parameter is active for this load. Required/structural params are handle...
subroutine setptr_charstr1d(charstr1d, varname, mempath, strlen)
set charstr1d pointer to varname
logical(lgp) function, public is_keystring_period(mf6_input)
Return .true. if mf6_input's PERIOD block uses keystring dispatch.
integer(i4b), parameter, public addr_node
addressed by CELLID
subroutine, public get_isize(name, mem_path, isize)
Get the number of elements for this variable.
This module contains the ModflowInputModule.
This module contains simulation methods.
Definition Sim.f90:10
subroutine, public store_error(msg, terminate)
Store an error message.
Definition Sim.f90:94
This module contains simulation variables.
character(len=maxcharlen) errmsg
error message string
integer(i4b) iout
file unit number for simulation output
This class is used to store a single deferred-length character string. It was designed to work in an ...
Input parameter definition. Describes an input parameter.
One descriptor per expanded keystring item, so loaders iterate uniformly instead of re-deriving per-m...
Input load context for generic dynamic loaders and StructArray based static loads....
Pointer type for read state variable.
derived type for storing input definition for a file