MODFLOW 6 version 6.9.0.dev0
USGS Modular Hydrologic Model
Loading...
Searching...
No Matches
LoadMf6File.f90
Go to the documentation of this file.
1!> @brief This module contains the LoadMf6FileModule
2!!
3!! This module contains the input data model routines for
4!! loading static data from a MODFLOW 6 input file using the
5!! block parser.
6!!
7!<
9
10 use kindmodule, only: dp, i4b, lgp
11 use simvariablesmodule, only: errmsg
12 use simmodule, only: store_error
36
37 implicit none
38 private
39 public :: loadmf6filetype
40 public :: read_control_record
41
42 !> @brief Fortran workaround for allocatable arrays of pointers; wraps a StructArray pointer for deferred TS linking.
43 !<
45 type(structarraytype), pointer :: sa => null()
46 end type staticsatype
47
48 !> @brief Static parser based input loader
49 !!
50 !! This type defines a static input context loader
51 !! for traditional mf6 ascii input files.
52 !!
53 !<
55 type(blockparsertype), pointer :: parser !< ascii block parser
56 integer(I4B), dimension(:), pointer, contiguous :: mshape => null() !< model shape
57 type(structarraytype), pointer :: structarray => null() !< structarray for loading list input
58 type(staticsatype), allocatable :: ts_sas(:) !< saved structarrays for deferred TS linking
59 type(modflowinputtype) :: mf6_input !< description of input
60 type(ncpackagevarstype), pointer :: nc_vars => null()
61 character(len=LINELENGTH) :: filename !< name of ascii input file
62 character(len=LINELENGTH), dimension(:), allocatable :: block_tags !< read block tags
63 logical(LGP) :: ts_active !< is timeseries active
64 logical(LGP) :: export !< is array export active
65 logical(LGP) :: readasarrays
66 logical(LGP) :: readarraygrid
67 integer(I4B) :: inamedbound
68 integer(I4B) :: iauxiliary
69 integer(I4B) :: iout !< inunit for list log
70 contains
71 procedure :: load
72 procedure :: init
73 procedure :: load_block
74 procedure :: finalize
75 procedure :: parse_block
76 procedure :: block_post_process
77 procedure :: parse_io_tag
78 procedure :: parse_record_tag
79 procedure :: load_tag
80 procedure :: block_index_dfn
82 procedure :: save_ts_sa
83 procedure :: ts_sa_count
84 procedure :: get_ts_sa
85 procedure :: alloc_tslink
86 procedure :: cleanup
87 end type loadmf6filetype
88
89contains
90
91 !> @brief load all static input blocks
92 !!
93 !! Invoke this routine to load all static input blocks
94 !! in single call.
95 !!
96 !<
97 subroutine load(this, parser, mf6_input, nc_vars, filename, iout)
98 class(loadmf6filetype) :: this
99 type(blockparsertype), target, intent(inout) :: parser
100 type(modflowinputtype), intent(in) :: mf6_input
101 type(ncpackagevarstype), pointer, intent(in) :: nc_vars
102 character(len=*), intent(in) :: filename
103 integer(I4B), intent(in) :: iout
104 integer(I4B) :: iblk
105
106 ! initialize static load
107 call this%init(parser, mf6_input, filename, iout)
108
109 ! set netcdf vars
110 this%nc_vars => nc_vars
111
112 ! process blocks
113 do iblk = 1, size(this%mf6_input%block_dfns)
114 ! don't load dynamic input data
115 if (this%mf6_input%block_dfns(iblk)%blockname == 'PERIOD') exit
116 ! load the block
117 call this%load_block(iblk)
118 end do
119
120 ! finalize static load
121 call this%finalize()
122 end subroutine load
123
124 !> @brief init
125 !!
126 !! init / finalize are only used when load_block() will be called
127 !!
128 !<
129 subroutine init(this, parser, mf6_input, filename, iout)
130 class(loadmf6filetype) :: this
131 type(blockparsertype), target, intent(inout) :: parser
132 type(modflowinputtype), intent(in) :: mf6_input
133 character(len=*), intent(in) :: filename
134 integer(I4B), intent(in) :: iout
135 integer(I4B) :: isize
136
137 this%parser => parser
138 this%mf6_input = mf6_input
139 this%filename = filename
140 this%ts_active = .false.
141 this%export = .false.
142 this%readasarrays = .false.
143 this%readarraygrid = .false.
144 this%inamedbound = 0
145 this%iauxiliary = 0
146 this%iout = iout
147
148 call get_isize('MODEL_SHAPE', mf6_input%component_mempath, isize)
149 if (isize > 0) then
150 call mem_setptr(this%mshape, 'MODEL_SHAPE', mf6_input%component_mempath)
151 end if
152
153 ! init ts stuctarray list
154 allocate (this%ts_sas(0))
155
156 ! log lst file header
157 call idm_log_header(this%mf6_input%component_name, &
158 this%mf6_input%subcomponent_name, this%iout)
159 end subroutine init
160
161 !> @brief load a single block
162 !!
163 !! Assumed in order load of single (next) block. If a
164 !! StructArray object is allocated to load this block
165 !! it persists until this routine (or finalize) is
166 !! called again.
167 !!
168 !<
169 subroutine load_block(this, iblk)
171 class(loadmf6filetype) :: this
172 integer(I4B), intent(in) :: iblk
173
174 ! reset structarray if it was created for previous block
175 if (associated(this%structarray)) then
176 ! destroy the structured array reader
177 call destructstructarray(this%structarray)
178 end if
179
180 allocate (this%block_tags(0))
181 ! load the block
182 call this%parse_block(iblk, .false.)
183 ! post process block
184 call this%block_post_process(iblk)
185 ! cleanup
186 deallocate (this%block_tags)
187 end subroutine load_block
188
189 !> @brief finalize
190 !!
191 !! init / finalize are only used when load_block() will be called
192 !!
193 !<
194 subroutine finalize(this)
196 class(loadmf6filetype) :: this
197 ! cleanup
198 if (associated(this%structarray)) then
199 ! destroy the structured array reader
200 call destructstructarray(this%structarray)
201 end if
202 ! close logging block
203 call idm_log_close(this%mf6_input%component_name, &
204 this%mf6_input%subcomponent_name, this%iout)
205 end subroutine finalize
206
207 !> @brief Post parse block handling
208 !!
209 !<
210 subroutine block_post_process(this, iblk)
212 class(loadmf6filetype) :: this
213 integer(I4B), intent(in) :: iblk
214 type(inputparamdefinitiontype), pointer :: idt
215 integer(I4B) :: iparam
216 integer(I4B), pointer :: intptr
217
218 ! update state based on read tags
219 do iparam = 1, size(this%block_tags)
220 select case (this%mf6_input%block_dfns(iblk)%blockname)
221 case ('OPTIONS')
222 if (this%block_tags(iparam) == 'AUXILIARY') then
223 this%iauxiliary = 1
224 else if (this%block_tags(iparam) == 'BOUNDNAMES') then
225 this%inamedbound = 1
226 else if (this%block_tags(iparam) == 'READASARRAYS') then
227 this%readasarrays = .true.
228 else if (this%block_tags(iparam) == 'READARRAYGRID') then
229 this%readarraygrid = .true.
230 else if (this%block_tags(iparam) == 'TS6_FILENAME') then
231 this%ts_active = .true.
232 else if (this%block_tags(iparam) == 'EXPORT_ARRAY_ASCII') then
233 this%export = .true.
234 end if
235 case default
236 end select
237 end do
238
239 ! update input context allocations based on dfn set and input
240 select case (this%mf6_input%block_dfns(iblk)%blockname)
241 case ('OPTIONS')
242 ! allocate naux and set to 0 if not allocated
243 do iparam = 1, size(this%mf6_input%param_dfns)
244 idt => this%mf6_input%param_dfns(iparam)
245 if (idt%blockname == 'OPTIONS' .and. &
246 idt%tagname == 'AUXILIARY') then
247 if (this%iauxiliary == 0) then
248 call mem_allocate(intptr, 'NAUX', this%mf6_input%mempath)
249 intptr = 0
250 end if
251 exit
252 end if
253 end do
254 case ('DIMENSIONS')
255 ! set model shape if discretization dimensions have been read
256 if (this%mf6_input%pkgtype(1:3) == 'DIS') then
257 call set_model_shape(this%mf6_input%pkgtype, this%filename, &
258 this%mf6_input%component_mempath, &
259 this%mf6_input%mempath, this%mshape)
260 end if
261 case default
262 end select
263 end subroutine block_post_process
264
265 !> @brief parse block
266 !!
267 !<
268 recursive subroutine parse_block(this, iblk, recursive_call)
271 class(loadmf6filetype) :: this
272 integer(I4B), intent(in) :: iblk
273 logical(LGP), intent(in) :: recursive_call !< true if recursive call
274 logical(LGP) :: isblockfound
275 logical(LGP) :: endofblock
276 logical(LGP) :: supportopenclose
277 integer(I4B) :: ierr
278 logical(LGP) :: found, required
279 type(memorytype), pointer :: mt
280 character(len=LINELENGTH) :: tag
281 type(inputparamdefinitiontype), pointer :: idt
282
283 ! disu vertices/cell2d blocks are contingent on NVERT dimension
284 if (this%mf6_input%pkgtype == 'DISU6' .or. &
285 this%mf6_input%pkgtype == 'DISV1D6' .or. &
286 this%mf6_input%pkgtype == 'DISV2D6') then
287 if (this%mf6_input%block_dfns(iblk)%blockname == 'VERTICES' .or. &
288 this%mf6_input%block_dfns(iblk)%blockname == 'CELL2D') then
289 call get_from_memorystore('NVERT', this%mf6_input%mempath, mt, found, &
290 .false.)
291 if (.not. found) return
292 if (mt%intsclr == 0) return
293 end if
294 end if
295
296 ! block open/close support
297 supportopenclose = (this%mf6_input%block_dfns(iblk)%blockname /= 'GRIDDATA')
298
299 ! parser search for block
300 required = this%mf6_input%block_dfns(iblk)%required .and. .not. recursive_call
301 call this%parser%GetBlock(this%mf6_input%block_dfns(iblk)%blockname, &
302 isblockfound, ierr, &
303 supportopenclose=supportopenclose, &
304 blockrequired=required)
305 ! process block
306 if (isblockfound) then
307 if (this%mf6_input%block_dfns(iblk)%aggregate) then
308 ! process block recarray type, set of variable 1d/2d types
309 call this%parse_structarray_block(iblk)
310 else
311 do
312 ! process each line in block
313 call this%parser%GetNextLine(endofblock)
314 if (endofblock) exit
315 ! process line as tag(s)
316 call this%parser%GetStringCaps(tag)
318 this%mf6_input%param_dfns, &
319 this%mf6_input%component_type, &
320 this%mf6_input%subcomponent_type, &
321 this%mf6_input%block_dfns(iblk)%blockname, &
322 tag, this%filename)
323 if (idt%in_record) then
324 call this%parse_record_tag(iblk, idt, .false.)
325 else
326 call this%load_tag(iblk, idt)
327 end if
328 end do
329 end if
330 end if
331
332 ! recurse if block is reloadable and was just read
333 if (this%mf6_input%block_dfns(iblk)%block_variable) then
334 if (isblockfound) then
335 call this%parse_block(iblk, .true.)
336 end if
337 end if
338 end subroutine parse_block
339
340 subroutine parse_io_tag(this, iblk, pkgtype, which, tag)
342 class(loadmf6filetype) :: this
343 integer(I4B), intent(in) :: iblk
344 character(len=*), intent(in) :: pkgtype
345 character(len=*), intent(in) :: which
346 character(len=*), intent(in) :: tag
347 type(inputparamdefinitiontype), pointer :: idt !< input data type object describing this record
348 ! matches, read and load file name
349 idt => &
350 get_param_definition_type(this%mf6_input%param_dfns, &
351 this%mf6_input%component_type, &
352 this%mf6_input%subcomponent_type, &
353 this%mf6_input%block_dfns(iblk)%blockname, &
354 tag, this%filename)
355 ! load io tag
356 call load_io_tag(this%parser, idt, this%mf6_input%mempath, which, this%iout)
357 call expandarray(this%block_tags)
358 this%block_tags(size(this%block_tags)) = trim(idt%tagname)
359 end subroutine parse_io_tag
360
361 recursive subroutine parse_record_tag(this, iblk, inidt, recursive_call)
365 class(loadmf6filetype) :: this
366 integer(I4B), intent(in) :: iblk
367 type(inputparamdefinitiontype), pointer, intent(in) :: inidt
368 logical(LGP), intent(in) :: recursive_call !< true if recursive call
369 type(inputparamdefinitiontype), pointer :: idt
370 character(len=40), dimension(:), allocatable :: words
371 integer(I4B) :: n, istart, nwords
372 character(len=LINELENGTH) :: tag
373
374 nullify (idt)
375 istart = 1
376
377 if (recursive_call) then
378 call split_record_dfn_tag1(this%mf6_input%param_dfns, &
379 this%mf6_input%component_type, &
380 this%mf6_input%subcomponent_type, &
381 inidt%tagname, nwords, words)
382 call this%load_tag(iblk, inidt)
383 istart = 3
384 else
385 call this%parser%GetStringCaps(tag)
386 if (tag /= '') then
387 call split_record_dfn_tag2(this%mf6_input%param_dfns, &
388 this%mf6_input%component_type, &
389 this%mf6_input%subcomponent_type, &
390 inidt%tagname, tag, nwords, words)
391 if (nwords == 4 .and. &
392 (tag == 'FILEIN' .or. &
393 tag == 'FILEOUT')) then
394 call this%parse_io_tag(iblk, words(2), words(3), words(4))
395 nwords = 0
396 else
398 this%mf6_input%param_dfns, &
399 this%mf6_input%component_type, &
400 this%mf6_input%subcomponent_type, &
401 this%mf6_input%block_dfns(iblk)%blockname, &
402 tag, this%filename)
403 ! avoid namespace collisions (CIM)
404 if (tag /= 'PRINT_FORMAT') call this%load_tag(iblk, inidt)
405 call this%load_tag(iblk, idt)
406 istart = 4
407 end if
408 else
409 call this%load_tag(iblk, inidt)
410 nwords = 0
411 end if
412 end if
413
414 if (istart > 1 .and. nwords == 0) then
415 write (errmsg, '(5a)') &
416 '"', trim(this%mf6_input%block_dfns(iblk)%blockname), &
417 '" block input record that includes keyword "', trim(inidt%tagname), &
418 '" is not properly formed.'
419 call store_error(errmsg)
420 call this%parser%StoreErrorUnit()
421 end if
422
423 do n = istart, nwords
425 this%mf6_input%param_dfns, &
426 this%mf6_input%component_type, &
427 this%mf6_input%subcomponent_type, &
428 this%mf6_input%block_dfns(iblk)%blockname, &
429 words(n), this%filename)
430 if (idt_datatype(idt) == 'RECORD') then
431 call this%parser%GetStringCaps(tag)
433 this%mf6_input%param_dfns, &
434 this%mf6_input%component_type, &
435 this%mf6_input%subcomponent_type, &
436 this%mf6_input%block_dfns(iblk)%blockname, &
437 tag, this%filename)
438 call this%parse_record_tag(iblk, idt, .true.)
439 exit
440 else
441 if (idt%tagname /= 'FORMAT') then
442 call this%parser%GetStringCaps(tag)
443 if (tag == '') then
444 exit
445 else if (idt%tagname /= tag) then
446 write (errmsg, '(5a)') 'Expecting record input tag "', &
447 trim(idt%tagname), '" but instead found "', trim(tag), '".'
448 call store_error(errmsg)
449 call this%parser%StoreErrorUnit()
450 end if
451 end if
452 call this%load_tag(iblk, idt)
453 end if
454 end do
455
456 if (allocated(words)) deallocate (words)
457 end subroutine parse_record_tag
458
459 !> @brief load input keyword
460 !! Load input associated with tag key into the memory manager.
461 !<
462 subroutine load_tag(this, iblk, idt)
465 class(loadmf6filetype) :: this
466 integer(I4B), intent(in) :: iblk
467 type(inputparamdefinitiontype), pointer, intent(in) :: idt !< input data type object describing this record
468 character(len=LINELENGTH) :: dev_msg
469
470 ! check if input param is developmode
471 if (idt%developmode) then
472 dev_msg = 'Input tag "'//trim(idt%tagname)// &
473 &'" read from file "'//trim(this%filename)// &
474 &'" is still under development. Install the &
475 &nightly build or compile from source with IDEVELOPMODE = 1.'
476 call developmode(dev_msg, this%iout)
477 end if
478
479 ! allocate and load data type
480 select case (idt%datatype)
481 case ('KEYWORD')
482 call load_keyword_type(this%parser, idt, this%mf6_input%mempath, this%iout)
483 ! check/set as dev option
484 if (idt%tagname(1:4) == 'DEV_' .and. &
485 this%mf6_input%block_dfns(iblk)%blockname == 'OPTIONS') then
486 call this%parser%DevOpt()
487 end if
488 case ('STRING')
489 if (idt%shape == 'NAUX') then
490 call load_auxvar_names(this%parser, idt, this%mf6_input%mempath, &
491 this%iout)
492 else
493 call load_string_type(this%parser, idt, this%mf6_input%mempath, this%iout)
494 end if
495 case ('INTEGER')
496 call load_integer_type(this%parser, idt, this%mf6_input%mempath, this%iout)
497 case ('INTEGER1D')
498 call load_integer1d_type(this%parser, idt, this%mf6_input, this%mshape, &
499 this%export, this%nc_vars, this%filename, &
500 this%iout)
501 case ('INTEGER2D')
502 call load_integer2d_type(this%parser, idt, this%mf6_input, this%mshape, &
503 this%export, this%nc_vars, this%filename, &
504 this%iout)
505 case ('INTEGER3D')
506 call load_integer3d_type(this%parser, idt, this%mf6_input, this%mshape, &
507 this%export, this%nc_vars, this%filename, &
508 this%iout)
509 case ('DOUBLE')
510 call load_double_type(this%parser, idt, this%mf6_input%mempath, this%iout)
511 case ('DOUBLE1D')
512 call load_double1d_type(this%parser, idt, this%mf6_input, this%mshape, &
513 this%export, this%nc_vars, this%filename, this%iout)
514 case ('DOUBLE2D')
515 call load_double2d_type(this%parser, idt, this%mf6_input, this%mshape, &
516 this%export, this%nc_vars, this%filename, this%iout)
517 case ('DOUBLE3D')
518 call load_double3d_type(this%parser, idt, this%mf6_input, this%mshape, &
519 this%export, this%nc_vars, this%filename, this%iout)
520 case default
521 write (errmsg, '(a,a)') 'Failure reading data for tag: ', trim(idt%tagname)
522 call store_error(errmsg)
523 call this%parser%StoreErrorUnit()
524 end select
525
526 call expandarray(this%block_tags)
527 this%block_tags(size(this%block_tags)) = trim(idt%tagname)
528 end subroutine load_tag
529
530 function block_index_dfn(this, iblk) result(idt)
531 class(loadmf6filetype) :: this
532 integer(I4B), intent(in) :: iblk
533 type(inputparamdefinitiontype) :: idt !< input data type object describing this record
534 character(len=LENVARNAME) :: varname
535 integer(I4B) :: ilen
536 character(len=3) :: block_suffix = 'NUM'
537
538 ! assign first column as the block number
539 ilen = len_trim(this%mf6_input%block_dfns(iblk)%blockname)
540
541 if (ilen > (lenvarname - len(block_suffix))) then
542 varname = &
543 this%mf6_input%block_dfns(iblk)% &
544 blockname(1:(lenvarname - len(block_suffix)))//block_suffix
545 else
546 varname = trim(this%mf6_input%block_dfns(iblk)%blockname)//block_suffix
547 end if
548
549 idt%component_type = trim(this%mf6_input%component_type)
550 idt%subcomponent_type = trim(this%mf6_input%subcomponent_type)
551 idt%blockname = trim(this%mf6_input%block_dfns(iblk)%blockname)
552 idt%tagname = varname
553 idt%mf6varname = varname
554 idt%datatype = 'INTEGER'
555 end function block_index_dfn
556
557 !> @brief parse a structured array record into memory manager
558 !!
559 !! A structarray is similar to a numpy recarray. It it used to
560 !! load a list of data in which each column in the list may be a
561 !! different type. Each column in the list is stored as a 1d
562 !! vector.
563 !!
564 !<
565 subroutine parse_structarray_block(this, iblk)
568 class(loadmf6filetype) :: this
569 integer(I4B), intent(in) :: iblk
570 type(loadcontexttype) :: ctx
571 character(len=LINELENGTH), dimension(:), allocatable :: param_names
572 type(inputparamdefinitiontype), pointer :: idt !< input data type object describing this record
573 type(inputparamdefinitiontype), pointer :: shape_idt
574 type(inputparamdefinitiontype), target :: blockvar_idt
575 integer(I4B) :: blocknum
576 integer(I4B), pointer :: nrow
577 integer(I4B), dimension(:), pointer, contiguous :: int1d
578 integer(I4B) :: nrows, nrowsread
579 integer(I4B) :: mem_rank, isize
580 integer(I4B) :: ibinary, oc_inunit
581 integer(I4B) :: icol, iparam
582 integer(I4B) :: ncol, nparam
583 logical(LGP) :: shape_found
584 logical(LGP) :: is_sum_shape
585 character(len=LINELENGTH) :: shape_name
586 integer(I4B), pointer :: pkgdata_maxbound
587
588 nrows = -1
589
590 ! initialize load context
591 call ctx%init(this%mf6_input, blockname= &
592 this%mf6_input%block_dfns(iblk)%blockname)
593 ! set in-scope params directly from context
594 param_names = ctx%params
595 nparam = size(ctx%params)
596 call ctx%check_developmode(this%filename)
597 ! set input definition for this block
598 idt => &
599 get_aggregate_definition_type(this%mf6_input%aggregate_dfns, &
600 this%mf6_input%component_type, &
601 this%mf6_input%subcomponent_type, &
602 this%mf6_input%block_dfns(iblk)%blockname)
603 ! if block is reloadable read the block number
604 if (this%mf6_input%block_dfns(iblk)%block_variable) then
605 blocknum = this%parser%GetInteger()
606 else
607 blocknum = 0
608 end if
609
610 ! set ncol
611 ncol = nparam
612 ! add col if block is reloadable
613 if (blocknum > 0) ncol = ncol + 1
614 ! use shape to set the max num of rows
615 if (idt%shape /= '') then
616 ! "SUM(name)" means total rows = sum of a per-feature array (e.g.
617 ! LAK's CONNECTIONDATA: NLAKECONN summed across all lakes); this
618 ! notation is declared explicitly in the dfn, not inferred
619 is_sum_shape = .false.
620 shape_name = idt%shape
621 if (idt%shape(1:4) == 'SUM(') then
622 is_sum_shape = .true.
623 shape_name = idt%shape(5:len_trim(idt%shape) - 1)
624 end if
625 shape_idt => &
626 get_param_definition_type(this%mf6_input%param_dfns, &
627 this%mf6_input%component_type, &
628 this%mf6_input%subcomponent_type, &
629 'DIMENSIONS', shape_name, this%filename, &
630 found=shape_found)
631 if (.not. shape_found) then
632 ! also allow a per-row PACKAGEDATA field (e.g. LAK's NLAKECONN)
633 shape_idt => &
634 get_param_definition_type(this%mf6_input%param_dfns, &
635 this%mf6_input%component_type, &
636 this%mf6_input%subcomponent_type, &
637 'PACKAGEDATA', shape_name, this%filename, &
638 found=shape_found)
639 end if
640 if (shape_found) then
641 call get_isize(shape_idt%mf6varname, this%mf6_input%mempath, isize)
642 if (isize < 0) then
643 if (shape_idt%required) then
644 write (errmsg, '(3a)') 'Required dimension "', &
645 trim(shape_name), '" not found.'
646 call store_error(errmsg)
647 call this%parser%StoreErrorUnit()
648 end if
649 else
650 ! cross-check the dfn's declared SUM(...)/plain shape against the
651 ! variable's actual rank, so a mismatch errors instead of
652 ! silently mis-using a scalar/array pointer
653 call get_mem_rank(shape_idt%mf6varname, this%mf6_input%mempath, &
654 mem_rank)
655 if (is_sum_shape .and. mem_rank == 1) then
656 call mem_setptr(int1d, shape_idt%mf6varname, this%mf6_input%mempath)
657 nrows = sum(int1d)
658 nullify (int1d)
659 else if (.not. is_sum_shape .and. mem_rank == 0) then
660 ! scalar shape variable (e.g. NLAKES, MAXBOUND) — use value directly
661 call mem_setptr(nrow, shape_idt%mf6varname, this%mf6_input%mempath)
662 nrows = nrow
663 else
664 write (errmsg, '(5a)') 'Shape variable "', trim(shape_name), &
665 '" rank does not match its declared shape "', &
666 trim(idt%shape), '".'
667 call store_error(errmsg)
668 call this%parser%StoreErrorUnit()
669 end if
670 end if
671 end if
672 ! -- else: shape variable not found; nrows stays at its initial -1, so
673 ! the block falls back to deferred sizing
674 end if
675
676 ! create a structured array; use a larger deferred init for blocks with no
677 ! explicit shape, which include APT based advanced packages.
678 if (nrows < 0) then
679 this%structarray => constructstructarray(this%mf6_input, ncol, nrows, &
680 blocknum, this%mf6_input%mempath, &
681 this%mf6_input%component_mempath, &
682 size_init=64)
683 else
684 this%structarray => constructstructarray(this%mf6_input, ncol, nrows, &
685 blocknum, this%mf6_input%mempath, &
686 this%mf6_input%component_mempath)
687 end if
688 ! create structarray vectors for each column
689 do icol = 1, ncol
690 ! if block is reloadable, block number is first column
691 if (blocknum > 0) then
692 if (icol == 1) then
693 blockvar_idt = this%block_index_dfn(iblk)
694 idt => blockvar_idt
695 call this%structarray%mem_create_vector(icol, idt)
696 ! continue as this column managed by internally SA object
697 cycle
698 end if
699 ! set indexes (where first column is blocknum)
700 iparam = icol - 1
701 else
702 ! set indexes (no blocknum column)
703 iparam = icol
704 end if
705 ! set pointer to input definition for this 1d vector
706 idt => &
707 get_param_definition_type(this%mf6_input%param_dfns, &
708 this%mf6_input%component_type, &
709 this%mf6_input%subcomponent_type, &
710 this%mf6_input%block_dfns(iblk)%blockname, &
711 param_names(iparam), this%filename)
712 ! allocate variable in memory manager
713 call this%structarray%mem_create_vector(icol, idt)
714 end do
715
716 ! finish context setup after allocating vectors
717 call ctx%allocate_arrays()
718
719 ! read the block control record
720 ibinary = read_control_record(this%parser, oc_inunit, this%iout)
721
722 if (ibinary == 1) then
723 ! read from binary
724 nrowsread = this%structarray%read_from_binary(oc_inunit, this%iout)
725 call this%parser%terminateblock()
726 close (oc_inunit)
727 else
728 ! read from ascii
729 nrowsread = this%structarray%read_from_parser(this%parser, this%ts_active, &
730 this%iout, this%filename)
731 end if
732
733 ! record which rows of time series capable columns are linked
734 call this%alloc_tslink(iblk)
735
736 ! save structarray for deferred TS linking in df() if any strlocs were stored
737 if (ibinary == 0 .and. this%ts_active) call this%save_ts_sa()
738
739 ! an advanced package's PACKAGEDATA row count is published as
740 ! MAXBOUND, the feature count the PERIOD block's load context needs
741 if (this%mf6_input%block_dfns(iblk)%blockname == 'PACKAGEDATA' .and. &
742 is_feature_keystring(this%mf6_input) .and. ctx%is_advanced) then
743 call get_isize('MAXBOUND', this%mf6_input%mempath, isize)
744 if (isize < 0) then
745 call mem_allocate(pkgdata_maxbound, 'MAXBOUND', this%mf6_input%mempath)
746 pkgdata_maxbound = nrowsread
747 end if
748 end if
749
750 ! clean up
751 call ctx%destroy()
752 end subroutine parse_structarray_block
753
754 !> @brief Return number of saved static StructArrays with deferred TS strlocs
755 !<
756 function ts_sa_count(this) result(n)
757 class(loadmf6filetype), intent(in) :: this
758 integer(I4B) :: n
759 n = size(this%ts_sas)
760 end function ts_sa_count
761
762 !> @brief Return the n-th saved static StructArray pointer
763 !<
764 function get_ts_sa(this, n) result(sa)
765 class(loadmf6filetype), intent(in) :: this
766 integer(I4B), intent(in) :: n
767 type(structarraytype), pointer :: sa
768 sa => this%ts_sas(n)%sa
769 end function get_ts_sa
770
771 !> @brief load type keyword
772 !<
773 subroutine load_keyword_type(parser, idt, memoryPath, iout)
774 type(blockparsertype), intent(inout) :: parser !< block parser
775 type(inputparamdefinitiontype), intent(in) :: idt !< input data type object describing this record
776 character(len=*), intent(in) :: memoryPath !< memorypath to put loaded information
777 integer(I4B), intent(in) :: iout !< unit number for output
778 integer(I4B), pointer :: intvar
779 call mem_allocate(intvar, idt%mf6varname, memorypath)
780 intvar = 1
781 call idm_log_var(intvar, idt%tagname, memorypath, idt%datatype, iout)
782 end subroutine load_keyword_type
783
784 !> @brief load type string
785 !<
786 subroutine load_string_type(parser, idt, memoryPath, iout)
787 use constantsmodule, only: lenbigline
788 type(blockparsertype), intent(inout) :: parser !< block parser
789 type(inputparamdefinitiontype), intent(in) :: idt !< input data type object describing this record
790 character(len=*), intent(in) :: memoryPath !< memorypath to put loaded information
791 integer(I4B), intent(in) :: iout !< unit number for output
792 character(len=LINELENGTH), pointer :: cstr
793 character(len=LENBIGLINE), pointer :: bigcstr
794 integer(I4B) :: ilen
795 select case (idt%shape)
796 case ('LENBIGLINE')
797 ilen = lenbigline
798 call mem_allocate(bigcstr, ilen, idt%mf6varname, memorypath)
799 call parser%GetString(bigcstr, (.not. idt%preserve_case))
800 call idm_log_var(bigcstr, idt%tagname, memorypath, iout)
801 case default
802 ilen = linelength
803 call mem_allocate(cstr, ilen, idt%mf6varname, memorypath)
804 call parser%GetString(cstr, (.not. idt%preserve_case))
805 call idm_log_var(cstr, idt%tagname, memorypath, iout)
806 end select
807 end subroutine load_string_type
808
809 !> @brief load io tag
810 !<
811 subroutine load_io_tag(parser, idt, memoryPath, which, iout)
814 type(blockparsertype), intent(inout) :: parser !< block parser
815 type(inputparamdefinitiontype), intent(in) :: idt !< input data type object describing this record
816 character(len=*), intent(in) :: memoryPath !< memorypath to put loaded information
817 character(len=*), intent(in) :: which
818 integer(I4B), intent(in) :: iout !< unit number for output
819 character(len=LINELENGTH) :: cstr
820 type(characterstringtype), dimension(:), pointer, contiguous :: charstr1d
821 integer(I4B) :: ilen, isize, idx
822 ilen = linelength
823 if (which == 'FILEIN') then
824 call get_isize(idt%mf6varname, memorypath, isize)
825 if (isize < 0) then
826 call mem_allocate(charstr1d, ilen, 1, idt%mf6varname, memorypath)
827 idx = 1
828 else
829 call mem_setptr(charstr1d, idt%mf6varname, memorypath)
830 call mem_reallocate(charstr1d, ilen, isize + 1, idt%mf6varname, &
831 memorypath)
832 idx = isize + 1
833 end if
834 call parser%GetString(cstr, (.not. idt%preserve_case))
835 charstr1d(idx) = cstr
836 else if (which == 'FILEOUT') then
837 call load_string_type(parser, idt, memorypath, iout)
838 end if
839 end subroutine load_io_tag
840
841 !> @brief load aux variable names
842 !!
843 !<
844 subroutine load_auxvar_names(parser, idt, memoryPath, iout)
846 use inputoutputmodule, only: urdaux
848 type(blockparsertype), intent(inout) :: parser !< block parser
849 type(inputparamdefinitiontype), intent(in) :: idt !< input data type object describing this record
850 character(len=*), intent(in) :: memoryPath !< memorypath to put loaded information
851 integer(I4B), intent(in) :: iout !< unit number for output
852 character(len=:), allocatable :: line
853 character(len=LENAUXNAME), dimension(:), allocatable :: caux
854 integer(I4B) :: lloc
855 integer(I4B) :: istart
856 integer(I4B) :: istop
857 integer(I4B) :: i
858 character(len=LENPACKAGENAME) :: text = ''
859 integer(I4B), pointer :: intvar
860 type(characterstringtype), dimension(:), &
861 pointer, contiguous :: acharstr1d !< variable for allocation
862 call mem_allocate(intvar, idt%shape, memorypath)
863 intvar = 0
864 call parser%GetRemainingLine(line)
865 lloc = 1
866 call urdaux(intvar, parser%iuactive, iout, lloc, &
867 istart, istop, caux, line, text)
868 call mem_allocate(acharstr1d, lenauxname, intvar, idt%mf6varname, memorypath)
869 do i = 1, intvar
870 acharstr1d(i) = caux(i)
871 end do
872 deallocate (line)
873 deallocate (caux)
874 end subroutine load_auxvar_names
875
876 !> @brief load type integer
877 !<
878 subroutine load_integer_type(parser, idt, memoryPath, iout)
879 type(blockparsertype), intent(inout) :: parser !< block parser
880 type(inputparamdefinitiontype), intent(in) :: idt !< input data type object describing this record
881 character(len=*), intent(in) :: memoryPath !< memorypath to put loaded information
882 integer(I4B), intent(in) :: iout !< unit number for output
883 integer(I4B), pointer :: intvar
884 call mem_allocate(intvar, idt%mf6varname, memorypath)
885 intvar = parser%GetInteger()
886 call idm_log_var(intvar, idt%tagname, memorypath, idt%datatype, iout)
887 end subroutine load_integer_type
888
889 !> @brief load type 1d integer
890 !<
891 subroutine load_integer1d_type(parser, idt, mf6_input, mshape, export, &
892 nc_vars, input_fname, iout)
895 type(blockparsertype), intent(inout) :: parser !< block parser
896 type(inputparamdefinitiontype), intent(in) :: idt !< input data type object describing this record
897 type(modflowinputtype), intent(in) :: mf6_input !< description of input
898 integer(I4B), dimension(:), contiguous, pointer, intent(in) :: mshape !< model shape
899 logical(LGP), intent(in) :: export !< export to ascii layer files
900 type(ncpackagevarstype), pointer, intent(in) :: nc_vars
901 character(len=*), intent(in) :: input_fname !< ascii input file name
902 integer(I4B), intent(in) :: iout !< unit number for output
903 integer(I4B), dimension(:), pointer, contiguous :: int1d
904 integer(I4B) :: nlay
905 integer(I4B) :: nvals
906 integer(I4B), dimension(:), allocatable :: array_shape
907 integer(I4B), dimension(:), allocatable :: layer_shape
908 character(len=LINELENGTH) :: keyword
909
910 ! Check if it is a full grid sized array (NODES), otherwise use
911 ! idt%shape to construct shape from variables in memoryPath
912 if (idt%shape == 'NODES') then
913 nvals = product(mshape)
914 else
915 call get_shape_from_string(idt%shape, array_shape, mf6_input%mempath)
916 nvals = array_shape(1)
917 end if
918
919 ! allocate memory for the array
920 call mem_allocate(int1d, nvals, idt%mf6varname, mf6_input%mempath)
921
922 ! read keyword
923 keyword = ''
924 call parser%GetStringCaps(keyword)
925
926 ! check for "NETCDF" and "LAYERED"
927 if (keyword == 'NETCDF') then
928 call netcdf_read_array(int1d, mshape, idt, mf6_input, nc_vars, &
929 input_fname, iout)
930 else if (keyword == 'LAYERED' .and. idt%layered) then
931 call get_layered_shape(mshape, nlay, layer_shape)
932 call read_int1d_layered(parser, int1d, idt%mf6varname, nlay, layer_shape)
933 else
934 call read_int1d(parser, int1d, idt%mf6varname)
935 end if
936
937 ! log information on the loaded array to the list file
938 call idm_log_var(int1d, idt%tagname, mf6_input%mempath, iout)
939
940 ! create export file for griddata parameters if optioned
941 if (export) then
942 if (idt%blockname == 'GRIDDATA') then
943 call idm_export(int1d, idt%tagname, mf6_input%mempath, idt%shape, iout)
944 end if
945 end if
946 end subroutine load_integer1d_type
947
948 !> @brief load type 2d integer
949 !<
950 subroutine load_integer2d_type(parser, idt, mf6_input, mshape, export, &
951 nc_vars, input_fname, iout)
954 type(blockparsertype), intent(inout) :: parser !< block parser
955 type(inputparamdefinitiontype), intent(in) :: idt !< input data type object describing this record
956 type(modflowinputtype), intent(in) :: mf6_input !< description of input
957 integer(I4B), dimension(:), contiguous, pointer, intent(in) :: mshape !< model shape
958 logical(LGP), intent(in) :: export !< export to ascii layer files
959 type(ncpackagevarstype), pointer, intent(in) :: nc_vars
960 character(len=*), intent(in) :: input_fname !< ascii input file name
961 integer(I4B), intent(in) :: iout !< unit number for output
962 integer(I4B), dimension(:, :), pointer, contiguous :: int2d
963 integer(I4B) :: nlay
964 integer(I4B) :: nsize1, nsize2
965 integer(I4B), dimension(:), allocatable :: array_shape
966 integer(I4B), dimension(:), allocatable :: layer_shape
967 character(len=LINELENGTH) :: keyword
968
969 ! determine the array shape from the input data definition (idt%shape),
970 ! which looks like "NCOL, NROW, NLAY"
971 call get_shape_from_string(idt%shape, array_shape, mf6_input%mempath)
972 nsize1 = array_shape(1)
973 nsize2 = array_shape(2)
974
975 ! create a new 3d memory managed variable
976 call mem_allocate(int2d, nsize1, nsize2, idt%mf6varname, mf6_input%mempath)
977
978 ! read keyword
979 keyword = ''
980 call parser%GetStringCaps(keyword)
981
982 ! check for "NETCDF" and "LAYERED"
983 if (keyword == 'NETCDF') then
984 call netcdf_read_array(int2d, mshape, idt, mf6_input, nc_vars, &
985 input_fname, iout)
986 else if (keyword == 'LAYERED' .and. idt%layered) then
987 call get_layered_shape(mshape, nlay, layer_shape)
988 call read_int2d_layered(parser, int2d, idt%mf6varname, nlay, layer_shape)
989 else
990 call read_int2d(parser, int2d, idt%mf6varname)
991 end if
992
993 ! log information on the loaded array to the list file
994 call idm_log_var(int2d, idt%tagname, mf6_input%mempath, iout)
995
996 ! create export file for griddata parameters if optioned
997 if (export) then
998 if (idt%blockname == 'GRIDDATA') then
999 call idm_export(int2d, idt%tagname, mf6_input%mempath, idt%shape, iout)
1000 end if
1001 end if
1002 end subroutine load_integer2d_type
1003
1004 !> @brief load type 3d integer
1005 !<
1006 subroutine load_integer3d_type(parser, idt, mf6_input, mshape, export, &
1007 nc_vars, input_fname, iout)
1010 type(blockparsertype), intent(inout) :: parser !< block parser
1011 type(inputparamdefinitiontype), intent(in) :: idt !< input data type object describing this record
1012 type(modflowinputtype), intent(in) :: mf6_input !< description of input
1013 integer(I4B), dimension(:), contiguous, pointer, intent(in) :: mshape !< model shape
1014 logical(LGP), intent(in) :: export !< export to ascii layer files
1015 type(ncpackagevarstype), pointer, intent(in) :: nc_vars
1016 character(len=*), intent(in) :: input_fname !< ascii input file name
1017 integer(I4B), intent(in) :: iout !< unit number for output
1018 integer(I4B), dimension(:, :, :), pointer, contiguous :: int3d
1019 integer(I4B) :: nlay
1020 integer(I4B) :: nsize1, nsize2, nsize3
1021 integer(I4B), dimension(:), allocatable :: array_shape
1022 integer(I4B), dimension(:), allocatable :: layer_shape
1023 integer(I4B), dimension(:), pointer, contiguous :: int1d_ptr
1024 character(len=LINELENGTH) :: keyword
1025
1026 ! determine the array shape from the input data definition (idt%shape),
1027 ! which looks like "NCOL, NROW, NLAY"
1028 call get_shape_from_string(idt%shape, array_shape, mf6_input%mempath)
1029 nsize1 = array_shape(1)
1030 nsize2 = array_shape(2)
1031 nsize3 = array_shape(3)
1032
1033 ! create a new 3d memory managed variable
1034 call mem_allocate(int3d, nsize1, nsize2, nsize3, idt%mf6varname, &
1035 mf6_input%mempath)
1036
1037 ! read keyword
1038 keyword = ''
1039 call parser%GetStringCaps(keyword)
1040
1041 ! check for "NETCDF" and "LAYERED"
1042 if (keyword == 'NETCDF') then
1043 call netcdf_read_array(int3d, mshape, idt, mf6_input, nc_vars, &
1044 input_fname, iout)
1045 else if (keyword == 'LAYERED' .and. idt%layered) then
1046 call get_layered_shape(mshape, nlay, layer_shape)
1047 call read_int3d_layered(parser, int3d, idt%mf6varname, nlay, &
1048 layer_shape)
1049 else
1050 int1d_ptr(1:nsize1 * nsize2 * nsize3) => int3d(:, :, :)
1051 call read_int1d(parser, int1d_ptr, idt%mf6varname)
1052 end if
1053
1054 ! log information on the loaded array to the list file
1055 call idm_log_var(int3d, idt%tagname, mf6_input%mempath, iout)
1056
1057 ! create export file for griddata parameters if optioned
1058 if (export) then
1059 if (idt%blockname == 'GRIDDATA') then
1060 call idm_export(int3d, idt%tagname, mf6_input%mempath, idt%shape, iout)
1061 end if
1062 end if
1063 end subroutine load_integer3d_type
1064
1065 !> @brief load type double
1066 !<
1067 subroutine load_double_type(parser, idt, memoryPath, iout)
1068 type(blockparsertype), intent(inout) :: parser !< block parser
1069 type(inputparamdefinitiontype), intent(in) :: idt !< input data type object describing this record
1070 character(len=*), intent(in) :: memoryPath !< memorypath to put loaded information
1071 integer(I4B), intent(in) :: iout !< unit number for output
1072 real(DP), pointer :: dblvar
1073 call mem_allocate(dblvar, idt%mf6varname, memorypath)
1074 dblvar = parser%GetDouble()
1075 call idm_log_var(dblvar, idt%tagname, memorypath, iout)
1076 end subroutine load_double_type
1077
1078 !> @brief load type 1d double
1079 !<
1080 subroutine load_double1d_type(parser, idt, mf6_input, mshape, export, &
1081 nc_vars, input_fname, iout)
1084 type(blockparsertype), intent(inout) :: parser !< block parser
1085 type(inputparamdefinitiontype), intent(in) :: idt !< input data type object describing this record
1086 type(modflowinputtype), intent(in) :: mf6_input !< description of input
1087 integer(I4B), dimension(:), contiguous, pointer, intent(in) :: mshape !< model shape
1088 logical(LGP), intent(in) :: export !< export to ascii layer files
1089 type(ncpackagevarstype), pointer, intent(in) :: nc_vars
1090 character(len=*), intent(in) :: input_fname !< ascii input file name
1091 integer(I4B), intent(in) :: iout !< unit number for output
1092 real(DP), dimension(:), pointer, contiguous :: dbl1d
1093 integer(I4B) :: nlay
1094 integer(I4B) :: nvals
1095 integer(I4B), dimension(:), allocatable :: array_shape
1096 integer(I4B), dimension(:), allocatable :: layer_shape
1097 character(len=LINELENGTH) :: keyword
1098
1099 ! Check if it is a full grid sized array (NODES)
1100 if (idt%shape == 'NODES') then
1101 nvals = product(mshape)
1102 else
1103 call get_shape_from_string(idt%shape, array_shape, mf6_input%mempath)
1104 nvals = array_shape(1)
1105 end if
1106
1107 ! allocate memory for the array
1108 call mem_allocate(dbl1d, nvals, idt%mf6varname, mf6_input%mempath)
1109
1110 ! read keyword
1111 keyword = ''
1112 call parser%GetStringCaps(keyword)
1113
1114 ! check for "NETCDF" and "LAYERED"
1115 if (keyword == 'NETCDF') then
1116 call netcdf_read_array(dbl1d, mshape, idt, mf6_input, nc_vars, &
1117 input_fname, iout)
1118 else if (keyword == 'LAYERED' .and. idt%layered) then
1119 call get_layered_shape(mshape, nlay, layer_shape)
1120 call read_dbl1d_layered(parser, dbl1d, idt%mf6varname, nlay, layer_shape)
1121 else
1122 call read_dbl1d(parser, dbl1d, idt%mf6varname)
1123 end if
1124
1125 ! log information on the loaded array to the list file
1126 call idm_log_var(dbl1d, idt%tagname, mf6_input%mempath, iout)
1127
1128 ! create export file for griddata parameters if optioned
1129 if (export) then
1130 if (idt%blockname == 'GRIDDATA') then
1131 call idm_export(dbl1d, idt%tagname, mf6_input%mempath, idt%shape, iout)
1132 end if
1133 end if
1134 end subroutine load_double1d_type
1135
1136 !> @brief load type 2d double
1137 !<
1138 subroutine load_double2d_type(parser, idt, mf6_input, mshape, export, &
1139 nc_vars, input_fname, iout)
1142 type(blockparsertype), intent(inout) :: parser !< block parser
1143 type(inputparamdefinitiontype), intent(in) :: idt !< input data type object describing this record
1144 type(modflowinputtype), intent(in) :: mf6_input !< description of input
1145 integer(I4B), dimension(:), contiguous, pointer, intent(in) :: mshape !< model shape
1146 logical(LGP), intent(in) :: export !< export to ascii layer files
1147 type(ncpackagevarstype), pointer, intent(in) :: nc_vars
1148 character(len=*), intent(in) :: input_fname !< ascii input file name
1149 integer(I4B), intent(in) :: iout !< unit number for output
1150 real(DP), dimension(:, :), pointer, contiguous :: dbl2d
1151 integer(I4B) :: nlay
1152 integer(I4B) :: nsize1, nsize2
1153 integer(I4B), dimension(:), allocatable :: array_shape
1154 integer(I4B), dimension(:), allocatable :: layer_shape
1155 character(len=LINELENGTH) :: keyword
1156
1157 ! determine the array shape from the input data definition (idt%shape),
1158 ! which looks like "NCOL, NROW, NLAY"
1159 call get_shape_from_string(idt%shape, array_shape, mf6_input%mempath)
1160 nsize1 = array_shape(1)
1161 nsize2 = array_shape(2)
1162
1163 ! create a new 3d memory managed variable
1164 call mem_allocate(dbl2d, nsize1, nsize2, idt%mf6varname, mf6_input%mempath)
1165
1166 ! read keyword
1167 keyword = ''
1168 call parser%GetStringCaps(keyword)
1169
1170 ! check for "NETCDF" and "LAYERED"
1171 if (keyword == 'NETCDF') then
1172 call netcdf_read_array(dbl2d, mshape, idt, mf6_input, nc_vars, &
1173 input_fname, iout)
1174 else if (keyword == 'LAYERED' .and. idt%layered) then
1175 call get_layered_shape(mshape, nlay, layer_shape)
1176 call read_dbl2d_layered(parser, dbl2d, idt%mf6varname, nlay, layer_shape)
1177 else
1178 call read_dbl2d(parser, dbl2d, idt%mf6varname)
1179 end if
1180
1181 ! log information on the loaded array to the list file
1182 call idm_log_var(dbl2d, idt%tagname, mf6_input%mempath, iout)
1183
1184 ! create export file for griddata parameters if optioned
1185 if (export) then
1186 if (idt%blockname == 'GRIDDATA') then
1187 call idm_export(dbl2d, idt%tagname, mf6_input%mempath, idt%shape, iout)
1188 end if
1189 end if
1190 end subroutine load_double2d_type
1191
1192 !> @brief load type 3d double
1193 !<
1194 subroutine load_double3d_type(parser, idt, mf6_input, mshape, export, &
1195 nc_vars, input_fname, iout)
1198 type(blockparsertype), intent(inout) :: parser !< block parser
1199 type(inputparamdefinitiontype), intent(in) :: idt !< input data type object describing this record
1200 type(modflowinputtype), intent(in) :: mf6_input !< description of input
1201 integer(I4B), dimension(:), contiguous, pointer, intent(in) :: mshape !< model shape
1202 logical(LGP), intent(in) :: export !< export to ascii layer files
1203 type(ncpackagevarstype), pointer, intent(in) :: nc_vars
1204 character(len=*), intent(in) :: input_fname !< ascii input file name
1205 integer(I4B), intent(in) :: iout !< unit number for output
1206 real(DP), dimension(:, :, :), pointer, contiguous :: dbl3d
1207 integer(I4B) :: nlay
1208 integer(I4B) :: nsize1, nsize2, nsize3
1209 integer(I4B), dimension(:), allocatable :: array_shape
1210 integer(I4B), dimension(:), allocatable :: layer_shape
1211 real(DP), dimension(:), pointer, contiguous :: dbl1d_ptr
1212 character(len=LINELENGTH) :: keyword
1213
1214 ! determine the array shape from the input data definition (idt%shape),
1215 ! which looks like "NCOL, NROW, NLAY"
1216 call get_shape_from_string(idt%shape, array_shape, mf6_input%mempath)
1217 nsize1 = array_shape(1)
1218 nsize2 = array_shape(2)
1219 nsize3 = array_shape(3)
1220
1221 ! create a new 3d memory managed variable
1222 call mem_allocate(dbl3d, nsize1, nsize2, nsize3, idt%mf6varname, &
1223 mf6_input%mempath)
1224
1225 ! read keyword
1226 keyword = ''
1227 call parser%GetStringCaps(keyword)
1228
1229 ! check for "NETCDF" and "LAYERED"
1230 if (keyword == 'NETCDF') then
1231 call netcdf_read_array(dbl3d, mshape, idt, mf6_input, nc_vars, &
1232 input_fname, iout)
1233 else if (keyword == 'LAYERED' .and. idt%layered) then
1234 call get_layered_shape(mshape, nlay, layer_shape)
1235 call read_dbl3d_layered(parser, dbl3d, idt%mf6varname, nlay, &
1236 layer_shape)
1237 else
1238 dbl1d_ptr(1:nsize1 * nsize2 * nsize3) => dbl3d(:, :, :)
1239 call read_dbl1d(parser, dbl1d_ptr, idt%mf6varname)
1240 end if
1241
1242 ! log information on the loaded array to the list file
1243 call idm_log_var(dbl3d, idt%tagname, mf6_input%mempath, iout)
1244
1245 ! create export file for griddata parameters if optioned
1246 if (export) then
1247 if (idt%blockname == 'GRIDDATA') then
1248 call idm_export(dbl3d, idt%tagname, mf6_input%mempath, idt%shape, iout)
1249 end if
1250 end if
1251 end subroutine load_double3d_type
1252
1253 function read_control_record(parser, oc_inunit, iout) result(ibinary)
1254 use simmodule, only: store_error_unit
1255 use inputoutputmodule, only: urword
1256 use inputoutputmodule, only: openfile
1257 use openspecmodule, only: form, access
1258 use constantsmodule, only: linelength
1260 type(blockparsertype), intent(inout) :: parser
1261 integer(I4B), intent(inout) :: oc_inunit
1262 integer(I4B), intent(in) :: iout
1263 integer(I4B) :: ibinary
1264 integer(I4B) :: lloc, istart, istop, idum, inunit, itmp, ierr
1265 integer(I4B) :: nunopn = 99
1266 character(len=:), allocatable :: line
1267 character(len=LINELENGTH) :: fname
1268 logical(LGP) :: exists
1269 real(dp) :: r
1270 character(len=*), parameter :: fmtocne = &
1271 &"('Specified OPEN/CLOSE file ',(A),' does not exist')"
1272 character(len=*), parameter :: fmtobf = &
1273 &"(1X,/1X,'OPENING BINARY FILE ON UNIT ',I0,':',/1X,A)"
1274
1275 ! initialize oc_inunit and ibinary
1276 oc_inunit = 0
1277 ibinary = 0
1278 inunit = parser%getunit()
1279
1280 ! Read to the first non-commented line
1281 lloc = 1
1282 call parser%line_reader%rdcom(inunit, iout, line, ierr)
1283 call urword(line, lloc, istart, istop, 1, idum, r, iout, inunit)
1284
1285 if (line(istart:istop) == 'OPEN/CLOSE') then
1286 ! get filename
1287 call urword(line, lloc, istart, istop, 0, idum, r, &
1288 iout, inunit)
1289 fname = line(istart:istop)
1290 ! check to see if file OPEN/CLOSE file exists
1291 inquire (file=fname, exist=exists)
1292 if (.not. exists) then
1293 write (errmsg, fmtocne) line(istart:istop)
1294 call store_error(errmsg)
1295 call store_error('Specified OPEN/CLOSE file does not exist')
1296 call store_error_unit(inunit)
1297 end if
1298
1299 ! Check for (BINARY) keyword
1300 call urword(line, lloc, istart, istop, 1, idum, r, &
1301 iout, inunit)
1302
1303 if (line(istart:istop) == '(BINARY)') ibinary = 1
1304 ! Open the file depending on ibinary flag
1305 if (ibinary == 1) then
1306 oc_inunit = nunopn
1307 itmp = iout
1308 if (iout > 0) then
1309 itmp = 0
1310 write (iout, fmtobf) oc_inunit, trim(adjustl(fname))
1311 end if
1312 call openfile(oc_inunit, itmp, fname, 'OPEN/CLOSE', &
1313 fmtarg_opt=form, accarg_opt=access)
1314 end if
1315 end if
1316
1317 if (ibinary == 0) then
1318 call parser%line_reader%bkspc(parser%getunit())
1319 end if
1320 end function read_control_record
1321
1322 !> @brief Save structarray pointer for deferred TS linking
1323 !!
1324 !! Saves the current structarray pointer when it contains TS string locs,
1325 !! then nullifies the pointer so load_block does not destroy it.
1326 !<
1327 subroutine save_ts_sa(this)
1328 class(loadmf6filetype), intent(inout) :: this
1329 type(structvectortype), pointer :: svect
1330 type(staticsatype), allocatable :: tmp(:)
1331 logical(LGP) :: has_ts
1332 integer(I4B) :: m, n
1333
1334 ! check if any column has deferred TS strlocs
1335 has_ts = .false.
1336 do m = 1, this%structarray%count()
1337 svect => this%structarray%get(m)
1338 if (svect%idt%timeseries .and. svect%ts_strlocs%count() > 0) then
1339 has_ts = .true.
1340 exit
1341 end if
1342 end do
1343
1344 if (has_ts) then
1345 n = size(this%ts_sas)
1346 allocate (tmp(n + 1))
1347 tmp(1:n) = this%ts_sas
1348 tmp(n + 1)%sa => this%structarray
1349 call move_alloc(tmp, this%ts_sas)
1350 ! nullify so load_block does not destroy the saved SA
1351 nullify (this%structarray)
1352 end if
1353 end subroutine save_ts_sa
1354
1355 !> @brief Allocate time series link flags for a static block
1356 !!
1357 !! For a block with time series capable double columns, allocate
1358 !! TSLINK_<id>, an integer array (ncol, nrow) that is nonzero where a row's
1359 !! value is linked to a time series, and TSLINKVARS_<id>, the names of its
1360 !! columns, where <id> identifies the block (see tslink_id). Packages use
1361 !! these to apply time series updates to linked values only.
1362 !<
1363 subroutine alloc_tslink(this, iblk)
1365 use loadcontextmodule, only: tslink_id
1367 class(loadmf6filetype), intent(inout) :: this
1368 integer(I4B), intent(in) :: iblk
1369 type(structvectortype), pointer :: svect
1370 type(tsstringloctype), pointer :: ts_strloc
1371 integer(I4B), dimension(:, :), pointer, contiguous :: tslink
1372 type(characterstringtype), dimension(:), pointer, contiguous :: tslinkvars
1373 integer(I4B), dimension(:), allocatable :: icols
1374 character(len=LINELENGTH) :: blockname
1375 character(len=2) :: id
1376 integer(I4B) :: m, n, ncol, nrow
1377
1378 ! find time series capable double columns
1379 allocate (icols(0))
1380 do m = 1, this%structarray%count()
1381 svect => this%structarray%get(m)
1382 if (svect%idt%timeseries .and. svect%memtype == mtype_dbl) then
1383 icols = [icols, m]
1384 end if
1385 end do
1386 ncol = size(icols)
1387 if (ncol == 0) return
1388
1389 ! block identifier
1390 blockname = this%mf6_input%block_dfns(iblk)%blockname
1391 id = tslink_id(blockname)
1392 if (id == '') then
1393 write (errmsg, '(a)') 'Time series link identifier not defined for &
1394 &block "'//trim(blockname)//'".'
1395 call store_error(errmsg)
1396 call this%parser%StoreErrorUnit()
1397 return
1398 end if
1399
1400 ! allocate
1401 svect => this%structarray%get(icols(1))
1402 nrow = size(svect%dbl1d)
1403 call mem_allocate(tslink, ncol, nrow, 'TSLINK_'//id, this%mf6_input%mempath)
1404 call mem_allocate(tslinkvars, lenvarname, ncol, 'TSLINKVARS_'//id, &
1405 this%mf6_input%mempath)
1406
1407 ! set column names and linked rows
1408 tslink = 0
1409 do m = 1, ncol
1410 svect => this%structarray%get(icols(m))
1411 tslinkvars(m) = svect%idt%mf6varname
1412 do n = 1, svect%ts_strlocs%count()
1413 ts_strloc => svect%get_ts_strloc(n)
1414 tslink(m, ts_strloc%row) = 1
1415 end do
1416 end do
1417 end subroutine alloc_tslink
1418
1419 !> @brief Clean up saved static structarrays
1420 !!
1421 !! Called from destroy() of dynamic loaders.
1422 !<
1423 subroutine cleanup(this)
1425 class(loadmf6filetype), intent(inout) :: this
1426 integer(I4B) :: n
1427 do n = 1, size(this%ts_sas)
1428 if (associated(this%ts_sas(n)%sa)) then
1429 call destructstructarray(this%ts_sas(n)%sa)
1430 nullify (this%ts_sas(n)%sa)
1431 end if
1432 end do
1433 deallocate (this%ts_sas)
1434 end subroutine cleanup
1435
1436end module loadmf6filemodule
This module contains block parser methods.
This module contains simulation constants.
Definition Constants.f90:9
integer(i4b), parameter linelength
maximum length of a standard line
Definition Constants.f90:45
integer(i4b), parameter lenpackagename
maximum length of the package name
Definition Constants.f90:23
integer(i4b), parameter lenbigline
maximum length of a big line
Definition Constants.f90:15
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
This module contains the DefinitionSelectModule.
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.
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.
subroutine, public read_dbl1d(parser, dbl1d, aname)
subroutine, public read_dbl2d(parser, dbl2d, aname)
Disable development features in release mode.
subroutine, public developmode(errmsg, iunit)
Terminate if in release mode (guard development features).
This module contains the Input Data Model Logger Module.
Definition IdmLogger.f90:7
subroutine, public idm_log_close(component, subcomponent, iout)
log the closing message
Definition IdmLogger.f90:56
subroutine, public idm_log_header(component, subcomponent, iout)
log a header message
Definition IdmLogger.f90:44
Input definition module.
subroutine, public urdaux(naux, inunit, iout, lloc, istart, istop, auxname, line, text)
Read auxiliary variables from an input line.
subroutine, public parseline(line, nwords, words, inunit, filename)
Parse a line into words.
subroutine, public openfile(iu, iout, fname, ftype, fmtarg_opt, accarg_opt, filstat_opt, mode_opt)
Open a file.
subroutine, public urword(line, icol, istart, istop, ncode, n, r, iout, in)
Extract a word from a string.
subroutine, public read_int1d(parser, int1d, aname)
subroutine, public read_int1d_layered(parser, int1d, aname, nlay, layer_shape)
subroutine, public read_int2d(parser, int2d, aname)
This module defines variable data types.
Definition kind.f90:8
subroutine, public read_int1d_layered(parser, int1d, aname, nlay, layer_shape)
subroutine, public read_dbl1d_layered(parser, dbl1d, aname, nlay, layer_shape)
subroutine, public read_dbl2d_layered(parser, dbl2d, aname, nlay, layer_shape)
subroutine, public read_int3d_layered(parser, int3d, aname, nlay, layer_shape)
subroutine, public read_dbl3d_layered(parser, dbl3d, aname, nlay, layer_shape)
subroutine, public read_int2d_layered(parser, int2d, aname, nlay, layer_shape)
Load context for IDM generic dynamic loaders.
character(len=2) function, public tslink_id(blockname)
time series link identifier for a static block
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,...
This module contains the LoadMf6FileModule.
subroutine cleanup(this)
Clean up saved static structarrays.
type(inputparamdefinitiontype) function block_index_dfn(this, iblk)
subroutine load_integer1d_type(parser, idt, mf6_input, mshape, export, nc_vars, input_fname, iout)
load type 1d integer
subroutine load_auxvar_names(parser, idt, memorypath, iout)
load aux variable names
subroutine load_double3d_type(parser, idt, mf6_input, mshape, export, nc_vars, input_fname, iout)
load type 3d double
subroutine load_keyword_type(parser, idt, memorypath, iout)
load type keyword
type(structarraytype) function, pointer get_ts_sa(this, n)
Return the n-th saved static StructArray pointer.
subroutine load_io_tag(parser, idt, memorypath, which, iout)
load io tag
subroutine alloc_tslink(this, iblk)
Allocate time series link flags for a static block.
subroutine init(this, parser, mf6_input, filename, iout)
init
subroutine load_double1d_type(parser, idt, mf6_input, mshape, export, nc_vars, input_fname, iout)
load type 1d double
subroutine load_block(this, iblk)
load a single block
subroutine parse_io_tag(this, iblk, pkgtype, which, tag)
subroutine save_ts_sa(this)
Save structarray pointer for deferred TS linking.
subroutine load_double2d_type(parser, idt, mf6_input, mshape, export, nc_vars, input_fname, iout)
load type 2d double
recursive subroutine parse_block(this, iblk, recursive_call)
parse block
subroutine load_string_type(parser, idt, memorypath, iout)
load type string
subroutine load_integer3d_type(parser, idt, mf6_input, mshape, export, nc_vars, input_fname, iout)
load type 3d integer
subroutine block_post_process(this, iblk)
Post parse block handling.
integer(i4b) function ts_sa_count(this)
Return number of saved static StructArrays with deferred TS strlocs.
subroutine load_integer_type(parser, idt, memorypath, iout)
load type integer
subroutine finalize(this)
finalize
subroutine load_tag(this, iblk, idt)
load input keyword Load input associated with tag key into the memory manager.
subroutine load_integer2d_type(parser, idt, mf6_input, mshape, export, nc_vars, input_fname, iout)
load type 2d integer
subroutine parse_structarray_block(this, iblk)
parse a structured array record into memory manager
subroutine load(this, parser, mf6_input, nc_vars, filename, iout)
load all static input blocks
subroutine load_double_type(parser, idt, memorypath, iout)
load type double
integer(i4b) function, public read_control_record(parser, oc_inunit, iout)
recursive subroutine parse_record_tag(this, iblk, inidt, recursive_call)
This module contains the LoadNCInputModule.
subroutine, public get_from_memorystore(name, mem_path, mt, found, check)
Get a memory type entry from the memory list.
subroutine, public get_isize(name, mem_path, isize)
Get the number of elements for this variable.
subroutine, public get_mem_rank(name, mem_path, rank)
Get the variable rank.
This module contains the ModflowInputModule.
This module contains the NCFileVarsModule.
Definition NCFileVars.f90:7
character(len=20) access
Definition OpenSpec.f90:7
character(len=20) form
Definition OpenSpec.f90:7
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_unit(iunit, terminate)
Store the file unit number.
Definition Sim.f90:172
This module contains simulation variables.
character(len=maxcharlen) errmsg
error message string
integer(i4b) iout
file unit number for simulation output
This module contains the SourceCommonModule.
subroutine, public get_layered_shape(mshape, nlay, layer_shape)
subroutine, public set_model_shape(ftype, fname, model_mempath, dis_mempath, model_shape)
routine for setting the model shape
subroutine, public get_shape_from_string(shape_string, array_shape, memorypath)
This module contains the StructArrayModule.
subroutine, public destructstructarray(struct_array)
destructor for a struct_array
type(structarraytype) function, pointer, public constructstructarray(mf6_input, ncol, nrow, blocknum, mempath, component_mempath, size_init)
constructor for a struct_array
This module contains the StructVectorModule.
@ mtype_dbl
dbl1d column
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.
Input load context for generic dynamic loaders and StructArray based static loads....
Static parser based input loader.
Fortran workaround for allocatable arrays of pointers; wraps a StructArray pointer for deferred TS li...
derived type for storing input definition for a file
Type describing input variables for a package in NetCDF file.
type for structured array
derived type for generic vector
derived type which describes time series string field