MODFLOW 6  version 6.7.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  if (ts6_size > 0) then
92  this%ts_active = 1
93  call mem_setptr(ts_fnames, 'TS6_FILENAME', this%mf6_input%mempath)
94  do n = 1, size(ts_fnames)
95  fname = ts_fnames(n)
96  call this%tsmanager%add_tsfile(fname, getunit())
97  end do
98  end if
99 
100  ! initialize package input context
101  call this%bound_context%create(mf6_input, this%readasarrays)
102 
103  ! store in scope SA cols for list input
104  call this%bound_context%bound_params(this%param_names, this%nparam, &
105  this%input_name, create=.false.)
106  ! construct and set up the struct array object
107  call this%create_structarray()
108 
109  ! finalize input context setup
110  call this%bound_context%allocate_arrays()
111  end subroutine bndlist_init
112 
113  subroutine bndlist_df(this)
114  class(boundlistinputtype), intent(inout) :: this !< ListInputType
115  ! define tsmanager
116  call this%tsmanager%tsmanager_df()
117  end subroutine bndlist_df
118 
119  subroutine bndlist_ad(this)
120  class(boundlistinputtype), intent(inout) :: this !< ListInputType
121  ! advance timeseries
122  call this%tsmanager%ad()
123  end subroutine bndlist_ad
124 
125  subroutine bndlist_reset(this)
126  class(boundlistinputtype), intent(inout) :: this !< ListInputType
127  ! reset tsmanager
128  call this%tsmanager%reset(this%mf6_input%subcomponent_name)
129  end subroutine bndlist_reset
130 
131  subroutine bndlist_rp(this, parser)
136  class(boundlistinputtype), intent(inout) :: this
137  type(blockparsertype), pointer, intent(inout) :: parser
138  integer(I4B) :: ibinary
139  integer(I4B) :: oc_inunit
140  logical(LGP) :: ts_active
141 
142  call this%reset()
143  ibinary = read_control_record(parser, oc_inunit, this%iout)
144 
145  ! log lst file header
146  call idm_log_header(this%mf6_input%component_name, &
147  this%mf6_input%subcomponent_name, this%iout)
148 
149  if (ibinary == 1) then
150  this%bound_context%nbound = &
151  this%structarray%read_from_binary(oc_inunit, this%iout)
152  call parser%terminateblock()
153  close (oc_inunit)
154  else
155  ts_active = (this%ts_active /= 0)
156  this%bound_context%nbound = &
157  this%structarray%read_from_parser(parser, ts_active, this%iout)
158  end if
159 
160  ! update ts links
161  if (this%ts_active /= 0) then
162  call this%ts_update(this%structarray)
163  end if
164 
165  ! close logging statement
166  call idm_log_close(this%mf6_input%component_name, &
167  this%mf6_input%subcomponent_name, this%iout)
168  end subroutine bndlist_rp
169 
170  subroutine bndlist_destroy(this)
171  class(boundlistinputtype), intent(inout) :: this !< BoundListInputType
172  !
173  ! deallocate tsmanager
174  call this%tsmanager%da()
175  deallocate (this%tsmanager)
176  nullify (this%tsmanager)
177  !
178  ! deallocate StructArray
179  call destructstructarray(this%structarray)
180  call this%bound_context%destroy()
181  end subroutine bndlist_destroy
182 
183  subroutine bndlist_ts_link_bnd(this, structvector, ts_strloc)
187  class(boundlistinputtype), intent(inout) :: this
188  type(structvectortype), pointer, intent(in) :: structvector
189  type(tsstringloctype), pointer, intent(in) :: ts_strloc
190  real(DP), pointer :: bndElem
191  type(timeserieslinktype), pointer :: tsLinkBnd
192  type(structvectortype), pointer :: sv_bound
193  character(len=LENBOUNDNAME) :: boundname
194 
195  nullify (tslinkbnd)
196 
197  ! set bound element
198  bndelem => structvector%dbl1d(ts_strloc%row)
199 
200  ! set link
201  call read_value_or_time_series(ts_strloc%token, ts_strloc%row, &
202  ts_strloc%structarray_col, bndelem, &
203  this%mf6_input%subcomponent_name, &
204  'BND', this%tsmanager, &
205  this%bound_context%iprpak, tslinkbnd)
206  if (associated(tslinkbnd)) then
207  ! set variable name
208  tslinkbnd%Text = structvector%idt%mf6varname
209  ! set boundname if provided
210  if (this%bound_context%inamedbound > 0) then
211  sv_bound => this%structarray%get(this%iboundname)
212  boundname = sv_bound%charstr1d(ts_strloc%row)
213  tslinkbnd%BndName = boundname
214  end if
215  end if
216  end subroutine bndlist_ts_link_bnd
217 
218  subroutine bndlist_ts_link_aux(this, structvector, ts_strloc)
222  class(boundlistinputtype), intent(inout) :: this
223  type(structvectortype), pointer, intent(in) :: structvector
224  type(tsstringloctype), pointer, intent(in) :: ts_strloc
225  real(DP), pointer :: bndElem
226  type(timeserieslinktype), pointer :: tsLinkAux
227  type(structvectortype), pointer :: sv_bound
228  character(len=LENBOUNDNAME) :: boundname
229 
230  nullify (tslinkaux)
231 
232  ! set bound element
233  bndelem => structvector%dbl2d(ts_strloc%col, ts_strloc%row)
234 
235  ! set link
236  call read_value_or_time_series(ts_strloc%token, ts_strloc%row, &
237  ts_strloc%structarray_col, bndelem, &
238  this%mf6_input%subcomponent_name, &
239  'AUX', this%tsmanager, &
240  this%bound_context%iprpak, tslinkaux)
241  if (associated(tslinkaux)) then
242  ! set variable name
243  tslinkaux%Text = this%bound_context%auxname_cst(ts_strloc%col)
244  ! set boundname if provided
245  if (this%bound_context%inamedbound > 0) then
246  sv_bound => this%structarray%get(this%iboundname)
247  boundname = sv_bound%charstr1d(ts_strloc%row)
248  tslinkaux%BndName = boundname
249  end if
250  end if
251  end subroutine bndlist_ts_link_aux
252 
253  subroutine bndlist_ts_update(this, structarray)
257  class(boundlistinputtype), intent(inout) :: this
258  type(structarraytype), pointer, intent(inout) :: structarray
259  integer(I4B) :: n, m
260  type(tsstringloctype), pointer :: ts_strloc
261  type(structvectortype), pointer :: sv
262 
263  do m = 1, structarray%count()
264  sv => structarray%get(m)
265  if (sv%idt%timeseries) then
266  do n = 1, sv%ts_strlocs%count()
267  ts_strloc => sv%get_ts_strloc(n)
268  call this%ts_link(sv, ts_strloc)
269  end do
270  call sv%clear()
271  end if
272  end do
273 
274  ! terminate if errors were detected
275  if (count_errors() > 0) then
276  call store_error_filename(this%input_name)
277  end if
278  end subroutine bndlist_ts_update
279 
280  subroutine bndlist_ts_link(this, structvector, ts_strloc)
282  class(boundlistinputtype), intent(inout) :: this
283  type(structvectortype), pointer, intent(in) :: structvector
284  type(tsstringloctype), pointer, intent(in) :: ts_strloc
285  select case (structvector%memtype)
286  case (2) ! dbl1d
287  call this%ts_link_bnd(structvector, ts_strloc)
288  case (6) ! dbl2d
289  call this%ts_link_aux(structvector, ts_strloc)
290  case default
291  end select
292  end subroutine bndlist_ts_link
293 
294  subroutine bndlist_create_structarray(this)
297  class(boundlistinputtype), intent(inout) :: this
298  type(inputparamdefinitiontype), pointer :: idt
299  integer(I4B) :: icol
300 
301  ! construct and set up the struct array object
302  this%structarray => constructstructarray(this%mf6_input, this%nparam, &
303  this%bound_context%maxbound, 0, &
304  this%mf6_input%mempath, &
305  this%mf6_input%component_mempath)
306  ! set up struct array
307  do icol = 1, this%nparam
308  idt => get_param_definition_type(this%mf6_input%param_dfns, &
309  this%mf6_input%component_type, &
310  this%mf6_input%subcomponent_type, &
311  'PERIOD', &
312  this%param_names(icol), this%input_name)
313  ! allocate variable in memory manager
314  call this%structarray%mem_create_vector(icol, idt)
315  ! store boundname index when found
316  if (idt%mf6varname == 'BOUNDNAME') this%iboundname = icol
317  end do
318  end subroutine bndlist_create_structarray
319 
320 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:56
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:73
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:36
derived type for generic vector
derived type which describes time series string field