MODFLOW 6  version 6.6.0.dev0
USGS Modular Hydrologic Model
Mf6FileListInput.f90
Go to the documentation of this file.
1 !> @brief This module contains the Mf6FileListInputModule
2 !!
3 !! This module contains the routines for reading period block
4 !! list based input.
5 !!
6 !<
8 
9  use kindmodule, only: i4b, dp, lgp
20 
21  implicit none
22  private
23  public :: boundlistinputtype
24 
25  !> @brief Boundary package list loader.
26  !!
27  !! Creates boundary input context for a package,
28  !! (e.g. CHD or MAW) and updates that context in
29  !! read and prepare (RP) routines.
30  !!
31  !<
33  type(timeseriesmanagertype), pointer :: tsmanager => null()
34  type(structarraytype), pointer :: structarray => null()
35  type(boundinputcontexttype) :: bound_context
36  integer(I4B) :: ts_active
37  integer(I4B) :: iboundname
38  contains
39  procedure :: ainit => bndlist_init
40  procedure :: df => bndlist_df
41  procedure :: ad => bndlist_ad
42  procedure :: reset => bndlist_reset
43  procedure :: rp => bndlist_rp
44  procedure :: destroy => bndlist_destroy
45  procedure :: ts_link_bnd => bndlist_ts_link_bnd
46  procedure :: ts_link_aux => bndlist_ts_link_aux
47  procedure :: ts_link => bndlist_ts_link
48  procedure :: ts_update => bndlist_ts_update
49  procedure :: create_structarray => bndlist_create_structarray
50  end type boundlistinputtype
51 
52 contains
53 
54  subroutine bndlist_init(this, mf6_input, component_name, component_input_name, &
55  input_name, iperblock, parser, iout)
56  use inputoutputmodule, only: getunit
60  class(boundlistinputtype), intent(inout) :: this
61  type(modflowinputtype), intent(in) :: mf6_input
62  character(len=*), intent(in) :: component_name
63  character(len=*), intent(in) :: component_input_name
64  character(len=*), intent(in) :: input_name
65  integer(I4B), intent(in) :: iperblock
66  type(blockparsertype), pointer, intent(inout) :: parser
67  integer(I4B), intent(in) :: iout
68  type(loadmf6filetype) :: loader
69  type(characterstringtype), dimension(:), pointer, &
70  contiguous :: ts_fnames
71  character(len=LINELENGTH) :: fname
72  integer(I4B) :: ts6_size, n
73  !
74  ! -- init loader
75  call this%DynamicPkgLoadType%init(mf6_input, component_name, &
76  component_input_name, input_name, &
77  iperblock, iout)
78  ! -- initialize scalars
79  this%iboundname = 0
80  this%ts_active = 0
81  !
82  ! -- load static input
83  call loader%load(parser, mf6_input, this%nc_vars, this%input_name, iout)
84  !
85  ! -- create tsmanager
86  allocate (this%tsmanager)
87  call tsmanager_cr(this%tsmanager, iout)
88  !
89  ! -- determine if TS6 files were provided in OPTIONS block
90  call get_isize('TS6_FILENAME', this%mf6_input%mempath, ts6_size)
91  !
92  if (ts6_size > 0) then
93  !
94  this%ts_active = 1
95  call mem_setptr(ts_fnames, 'TS6_FILENAME', this%mf6_input%mempath)
96  !
97  do n = 1, size(ts_fnames)
98  fname = ts_fnames(n)
99  call this%tsmanager%add_tsfile(fname, getunit())
100  end do
101  !
102  end if
103  !
104  ! -- initialize package input context
105  call this%bound_context%create(mf6_input, this%readasarrays)
106  !
107  ! -- store in scope SA cols for list input
108  call this%bound_context%bound_params(this%param_names, this%nparam, &
109  this%input_name, create=.false.)
110  !
111  ! -- construct and set up the struct array object
112  call this%create_structarray()
113  !
114  ! -- finalize input context setup
115  call this%bound_context%allocate_arrays()
116  end subroutine bndlist_init
117 
118  subroutine bndlist_df(this)
119  ! -- modules
120  ! -- dummy
121  class(boundlistinputtype), intent(inout) :: this !< ListInputType
122  !
123  ! -- define tsmanager
124  call this%tsmanager%tsmanager_df()
125  end subroutine bndlist_df
126 
127  subroutine bndlist_ad(this)
128  ! -- modules
129  class(boundlistinputtype), intent(inout) :: this !< ListInputType
130  !
131  ! -- advance timeseries
132  call this%tsmanager%ad()
133  end subroutine bndlist_ad
134 
135  subroutine bndlist_reset(this)
136  ! -- modules
137  class(boundlistinputtype), intent(inout) :: this !< ListInputType
138  !
139  ! -- reset tsmanager
140  call this%tsmanager%reset(this%mf6_input%subcomponent_name)
141  end subroutine bndlist_reset
142 
143  subroutine bndlist_rp(this, parser)
144  ! -- modules
149  ! -- dummy
150  class(boundlistinputtype), intent(inout) :: this
151  type(blockparsertype), pointer, intent(inout) :: parser
152  ! -- local
153  integer(I4B) :: ibinary
154  integer(I4B) :: oc_inunit
155  logical(LGP) :: ts_active
156  !
157  call this%reset()
158  !
159  ibinary = read_control_record(parser, oc_inunit, this%iout)
160  !
161  ! -- log lst file header
162  call idm_log_header(this%mf6_input%component_name, &
163  this%mf6_input%subcomponent_name, this%iout)
164  !
165  if (ibinary == 1) then
166  !
167  this%bound_context%nbound = &
168  this%structarray%read_from_binary(oc_inunit, this%iout)
169  !
170  call parser%terminateblock()
171  !
172  close (oc_inunit)
173  !
174  else
175  !
176  ts_active = (this%ts_active /= 0)
177  !
178  this%bound_context%nbound = &
179  this%structarray%read_from_parser(parser, ts_active, this%iout)
180  end if
181  !
182  ! update ts links
183  if (this%ts_active /= 0) then
184  call this%ts_update(this%structarray)
185  end if
186  !
187  ! -- close logging statement
188  call idm_log_close(this%mf6_input%component_name, &
189  this%mf6_input%subcomponent_name, this%iout)
190  end subroutine bndlist_rp
191 
192  subroutine bndlist_destroy(this)
193  ! -- modules
194  class(boundlistinputtype), intent(inout) :: this !< BoundListInputType
195  !
196  deallocate (this%tsmanager)
197  !
198  ! -- deallocate StructArray
199  call destructstructarray(this%structarray)
200  !
201  call this%bound_context%destroy()
202  end subroutine bndlist_destroy
203 
204  subroutine bndlist_ts_link_bnd(this, structvector, ts_strloc)
205  ! -- modules
209  ! -- dummy
210  class(boundlistinputtype), intent(inout) :: this
211  type(structvectortype), pointer, intent(in) :: structvector
212  type(tsstringloctype), pointer, intent(in) :: ts_strloc
213  ! -- local
214  real(DP), pointer :: bndElem
215  type(timeserieslinktype), pointer :: tsLinkBnd
216  type(structvectortype), pointer :: sv_bound
217  character(len=LENBOUNDNAME) :: boundname
218  !
219  nullify (tslinkbnd)
220  !
221  ! -- set bound element
222  bndelem => structvector%dbl1d(ts_strloc%row)
223  !
224  ! -- set link
225  call read_value_or_time_series(ts_strloc%token, ts_strloc%row, &
226  ts_strloc%structarray_col, bndelem, &
227  this%mf6_input%subcomponent_name, &
228  'BND', this%tsmanager, &
229  this%bound_context%iprpak, tslinkbnd)
230  !
231  if (associated(tslinkbnd)) then
232  !
233  ! -- set variable name
234  tslinkbnd%Text = structvector%idt%mf6varname
235  !
236  ! -- set boundname if provided
237  if (this%bound_context%inamedbound > 0) then
238  sv_bound => this%structarray%get(this%iboundname)
239  boundname = sv_bound%charstr1d(ts_strloc%row)
240  tslinkbnd%BndName = boundname
241  end if
242  end if
243  end subroutine bndlist_ts_link_bnd
244 
245  subroutine bndlist_ts_link_aux(this, structvector, ts_strloc)
246  ! -- modules
250  ! -- dummy
251  class(boundlistinputtype), intent(inout) :: this
252  type(structvectortype), pointer, intent(in) :: structvector
253  type(tsstringloctype), pointer, intent(in) :: ts_strloc
254  ! -- local
255  real(DP), pointer :: bndElem
256  type(timeserieslinktype), pointer :: tsLinkAux
257  type(structvectortype), pointer :: sv_bound
258  character(len=LENBOUNDNAME) :: boundname
259  !
260  nullify (tslinkaux)
261  !
262  ! -- set bound element
263  bndelem => structvector%dbl2d(ts_strloc%col, ts_strloc%row)
264  !
265  ! -- set link
266  call read_value_or_time_series(ts_strloc%token, ts_strloc%row, &
267  ts_strloc%structarray_col, bndelem, &
268  this%mf6_input%subcomponent_name, &
269  'AUX', this%tsmanager, &
270  this%bound_context%iprpak, tslinkaux)
271 
272  if (associated(tslinkaux)) then
273  !
274  ! -- set variable name
275  tslinkaux%Text = this%bound_context%auxname_cst(ts_strloc%col)
276  !
277  ! -- set boundname if provided
278  if (this%bound_context%inamedbound > 0) then
279  sv_bound => this%structarray%get(this%iboundname)
280  boundname = sv_bound%charstr1d(ts_strloc%row)
281  tslinkaux%BndName = boundname
282  end if
283  !
284  end if
285  end subroutine bndlist_ts_link_aux
286 
287  subroutine bndlist_ts_update(this, structarray)
288  ! -- modules
292  ! -- dummy
293  class(boundlistinputtype), intent(inout) :: this
294  type(structarraytype), pointer, intent(inout) :: structarray
295  ! -- local
296  integer(I4B) :: n, m
297  type(tsstringloctype), pointer :: ts_strloc
298  type(structvectortype), pointer :: sv
299  !
300  do m = 1, structarray%count()
301 
302  sv => structarray%get(m)
303 
304  if (sv%idt%timeseries) then
305  !
306  do n = 1, sv%ts_strlocs%count()
307  ts_strloc => sv%get_ts_strloc(n)
308  call this%ts_link(sv, ts_strloc)
309  end do
310  !
311  call sv%clear()
312  end if
313  end do
314  !
315  ! -- terminate if errors were detected
316  if (count_errors() > 0) then
317  call store_error_filename(this%input_name)
318  end if
319  end subroutine bndlist_ts_update
320 
321  subroutine bndlist_ts_link(this, structvector, ts_strloc)
322  ! -- modules
324  ! -- dummy
325  class(boundlistinputtype), intent(inout) :: this
326  type(structvectortype), pointer, intent(in) :: structvector
327  type(tsstringloctype), pointer, intent(in) :: ts_strloc
328  ! -- local
329  !
330  select case (structvector%memtype)
331  case (2) ! -- dbl1d
332  !
333  call this%ts_link_bnd(structvector, ts_strloc)
334  !
335  case (6) ! -- dbl2d
336  !
337  call this%ts_link_aux(structvector, ts_strloc)
338  !
339  case default
340  end select
341  end subroutine bndlist_ts_link
342 
343  subroutine bndlist_create_structarray(this)
344  ! -- modules
347  ! -- dummy
348  class(boundlistinputtype), intent(inout) :: this
349  ! -- local
350  type(inputparamdefinitiontype), pointer :: idt
351  integer(I4B) :: icol
352  !
353  ! -- construct and set up the struct array object
354  this%structarray => constructstructarray(this%mf6_input, this%nparam, &
355  this%bound_context%maxbound, 0, &
356  this%mf6_input%mempath, &
357  this%mf6_input%component_mempath)
358  !
359  ! -- set up struct array
360  do icol = 1, this%nparam
361  !
362  idt => get_param_definition_type(this%mf6_input%param_dfns, &
363  this%mf6_input%component_type, &
364  this%mf6_input%subcomponent_type, &
365  'PERIOD', &
366  this%param_names(icol), this%input_name)
367  !
368  ! -- allocate variable in memory manager
369  call this%structarray%mem_create_vector(icol, idt)
370  !
371  ! -- store boundname index when found
372  if (idt%mf6varname == 'BOUNDNAME') this%iboundname = icol
373  !
374  end do
375  end subroutine bndlist_create_structarray
376 
377 end module mf6filelistinputmodule
This module contains the AsciiInputLoadTypeModule.
This module contains block parser methods.
Definition: BlockParser.f90:7
This module contains the BoundInputContextModule.
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 lenboundname
maximum length of a bound name
Definition: Constants.f90:36
This module contains the DefinitionSelectModule.
type(inputparamdefinitiontype) function, pointer, public get_param_definition_type(input_definition_types, component_type, subcomponent_type, blockname, tagname, filename)
Return parameter definition.
This module contains the Input Data Model Logger Module.
Definition: IdmLogger.f90:7
subroutine, public idm_log_close(component, subcomponent, iout)
@ brief log the closing message
Definition: IdmLogger.f90:57
subroutine, public idm_log_header(component, subcomponent, iout)
@ brief log a header message
Definition: IdmLogger.f90:44
This module contains the InputDefinitionModule.
integer(i4b) function, public getunit()
Get a free unit number.
This module defines variable data types.
Definition: kind.f90:8
This module contains the LoadMf6FileModule.
Definition: LoadMf6File.f90:8
integer(i4b) function, public read_control_record(parser, oc_inunit, iout)
subroutine, public get_isize(name, mem_path, isize)
@ brief Get the number of elements for this variable
This module contains the Mf6FileListInputModule.
subroutine bndlist_destroy(this)
subroutine bndlist_init(this, mf6_input, component_name, component_input_name, input_name, iperblock, parser, iout)
subroutine bndlist_ts_link_bnd(this, structvector, ts_strloc)
subroutine bndlist_reset(this)
subroutine bndlist_ts_link(this, structvector, ts_strloc)
subroutine bndlist_ts_link_aux(this, structvector, ts_strloc)
subroutine bndlist_df(this)
subroutine bndlist_rp(this, parser)
subroutine bndlist_ts_update(this, structarray)
subroutine bndlist_create_structarray(this)
subroutine bndlist_ad(this)
This module contains the ModflowInputModule.
Definition: ModflowInput.f90:9
type(modflowinputtype) function, public getmodflowinput(pkgtype, component_type, subcomponent_type, component_name, subcomponent_name, filename)
function to return ModflowInputType
This module contains simulation methods.
Definition: Sim.f90:10
integer(i4b) function, public count_errors()
Return number of errors.
Definition: Sim.f90:59
subroutine, public store_error_filename(filename, terminate)
Store the erroring file name.
Definition: Sim.f90:203
This module contains the StructArrayModule.
Definition: StructArray.f90:8
type(structarraytype) function, pointer, public constructstructarray(mf6_input, ncol, nrow, blocknum, mempath, component_mempath)
constructor for a struct_array
Definition: StructArray.f90:74
subroutine, public destructstructarray(struct_array)
destructor for a struct_array
This module contains the StructVectorModule.
Definition: StructVector.f90:7
subroutine, public tsmanager_cr(this, iout, removeTsLinksOnCompletion, extendTsToEndOfSimulation)
Create the tsmanager.
subroutine, public read_value_or_time_series(textInput, ii, jj, bndElem, pkgName, auxOrBnd, tsManager, iprpak, tsLink)
Call this subroutine if the time-series link is available or needed.
base abstract type for ascii source dynamic load
derived type for boundary package input context
This class is used to store a single deferred-length character string. It was designed to work in an ...
Definition: CharString.f90:23
Static parser based input loader.
Definition: LoadMf6File.f90:48
derived type for storing input definition for a file
type for structured array
Definition: StructArray.f90:37
derived type for generic vector
derived type which describes time series string field