MODFLOW 6  version 6.7.0.dev2
USGS Modular Hydrologic Model
Mf6FileList.f90
Go to the documentation of this file.
1 !> @brief This module contains the ListLoadModule
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 :: listloadtype
24 
25  !> @brief list input loader for dynamic packages.
26  !!
27  !! Create and update input context for list based period blocks.
28  !!
29  !<
31  type(timeseriesmanagertype), pointer :: tsmanager => null()
32  type(structarraytype), pointer :: structarray => null()
33  type(loadcontexttype) :: ctx
34  integer(I4B) :: ts_active
35  integer(I4B) :: iboundname
36  contains
37  procedure :: ainit
38  procedure :: df
39  procedure :: ad
40  procedure :: reset
41  procedure :: rp
42  procedure :: destroy
43  procedure :: ts_link_bnd
44  procedure :: ts_link_aux
45  procedure :: ts_link
46  procedure :: ts_update
47  procedure :: create_structarray
48  end type listloadtype
49 
50 contains
51 
52  subroutine ainit(this, mf6_input, component_name, component_input_name, &
53  input_name, iperblock, parser, iout)
54  use inputoutputmodule, only: getunit
58  class(listloadtype), intent(inout) :: this
59  type(modflowinputtype), intent(in) :: mf6_input
60  character(len=*), intent(in) :: component_name
61  character(len=*), intent(in) :: component_input_name
62  character(len=*), intent(in) :: input_name
63  integer(I4B), intent(in) :: iperblock
64  type(blockparsertype), pointer, intent(inout) :: parser
65  integer(I4B), intent(in) :: iout
66  type(loadmf6filetype) :: loader
67  type(characterstringtype), dimension(:), pointer, &
68  contiguous :: ts_fnames
69  character(len=LINELENGTH) :: fname
70  integer(I4B) :: ts6_size, n
71 
72  ! init loader
73  call this%DynamicPkgLoadType%init(mf6_input, component_name, &
74  component_input_name, input_name, &
75  iperblock, iout)
76  ! initialize scalars
77  this%iboundname = 0
78  this%ts_active = 0
79 
80  ! load static input
81  call loader%load(parser, mf6_input, this%nc_vars, this%input_name, iout)
82 
83  ! create tsmanager
84  allocate (this%tsmanager)
85  call tsmanager_cr(this%tsmanager, iout)
86 
87  ! determine if TS6 files were provided in OPTIONS block
88  call get_isize('TS6_FILENAME', this%mf6_input%mempath, ts6_size)
89  if (ts6_size > 0) then
90  this%ts_active = 1
91  call mem_setptr(ts_fnames, 'TS6_FILENAME', this%mf6_input%mempath)
92  do n = 1, size(ts_fnames)
93  fname = ts_fnames(n)
94  call this%tsmanager%add_tsfile(fname, getunit())
95  end do
96  end if
97 
98  ! initialize package input context
99  call this%ctx%init(mf6_input)
100 
101  ! store in scope SA cols for list input
102  call this%ctx%tags(this%param_names, this%nparam, this%input_name)
103 
104  ! construct and set up the struct array object
105  call this%create_structarray()
106 
107  ! finalize input context setup
108  call this%ctx%allocate_arrays()
109  end subroutine ainit
110 
111  subroutine df(this)
112  class(listloadtype), intent(inout) :: this
113  ! define tsmanager
114  call this%tsmanager%tsmanager_df()
115  end subroutine df
116 
117  subroutine ad(this)
118  class(listloadtype), intent(inout) :: this
119  ! advance timeseries
120  call this%tsmanager%ad()
121  end subroutine ad
122 
123  subroutine reset(this)
124  class(listloadtype), intent(inout) :: this
125  ! reset tsmanager
126  call this%tsmanager%reset(this%mf6_input%subcomponent_name)
127  end subroutine reset
128 
129  subroutine rp(this, parser)
134  class(listloadtype), intent(inout) :: this
135  type(blockparsertype), pointer, intent(inout) :: parser
136  integer(I4B) :: ibinary
137  integer(I4B) :: oc_inunit
138  logical(LGP) :: ts_active
139 
140  call this%reset()
141  ibinary = read_control_record(parser, oc_inunit, this%iout)
142 
143  ! log lst file header
144  call idm_log_header(this%mf6_input%component_name, &
145  this%mf6_input%subcomponent_name, this%iout)
146 
147  if (ibinary == 1) then
148  this%ctx%nbound = &
149  this%structarray%read_from_binary(oc_inunit, this%iout)
150  call parser%terminateblock()
151  close (oc_inunit)
152  else
153  ts_active = (this%ts_active /= 0)
154  this%ctx%nbound = &
155  this%structarray%read_from_parser(parser, ts_active, this%iout)
156  end if
157 
158  ! update ts links
159  if (this%ts_active /= 0) then
160  call this%ts_update(this%structarray)
161  end if
162 
163  ! close logging statement
164  call idm_log_close(this%mf6_input%component_name, &
165  this%mf6_input%subcomponent_name, this%iout)
166  end subroutine rp
167 
168  subroutine destroy(this)
169  class(listloadtype), intent(inout) :: this
170  !
171  ! deallocate tsmanager
172  call this%tsmanager%da()
173  deallocate (this%tsmanager)
174  nullify (this%tsmanager)
175  !
176  ! deallocate StructArray
177  call destructstructarray(this%structarray)
178  call this%ctx%destroy()
179  end subroutine destroy
180 
181  subroutine ts_link_bnd(this, structvector, ts_strloc)
185  class(listloadtype), intent(inout) :: this
186  type(structvectortype), pointer, intent(in) :: structvector
187  type(tsstringloctype), pointer, intent(in) :: ts_strloc
188  real(DP), pointer :: bndElem
189  type(timeserieslinktype), pointer :: tsLinkBnd
190  type(structvectortype), pointer :: sv_bound
191  character(len=LENBOUNDNAME) :: boundname
192 
193  nullify (tslinkbnd)
194 
195  ! set bound element
196  bndelem => structvector%dbl1d(ts_strloc%row)
197 
198  ! set link
199  call read_value_or_time_series(ts_strloc%token, ts_strloc%row, &
200  ts_strloc%structarray_col, bndelem, &
201  this%mf6_input%subcomponent_name, &
202  'BND', this%tsmanager, &
203  this%ctx%iprpak, tslinkbnd)
204  if (associated(tslinkbnd)) then
205  ! set variable name
206  tslinkbnd%Text = structvector%idt%mf6varname
207  ! set boundname if provided
208  if (this%ctx%boundnames > 0) then
209  sv_bound => this%structarray%get(this%iboundname)
210  boundname = sv_bound%charstr1d(ts_strloc%row)
211  tslinkbnd%BndName = boundname
212  end if
213  end if
214  end subroutine ts_link_bnd
215 
216  subroutine ts_link_aux(this, structvector, ts_strloc)
220  class(listloadtype), intent(inout) :: this
221  type(structvectortype), pointer, intent(in) :: structvector
222  type(tsstringloctype), pointer, intent(in) :: ts_strloc
223  real(DP), pointer :: bndElem
224  type(timeserieslinktype), pointer :: tsLinkAux
225  type(structvectortype), pointer :: sv_bound
226  character(len=LENBOUNDNAME) :: boundname
227 
228  nullify (tslinkaux)
229 
230  ! set bound element
231  bndelem => structvector%dbl2d(ts_strloc%col, ts_strloc%row)
232 
233  ! set link
234  call read_value_or_time_series(ts_strloc%token, ts_strloc%row, &
235  ts_strloc%structarray_col, bndelem, &
236  this%mf6_input%subcomponent_name, &
237  'AUX', this%tsmanager, &
238  this%ctx%iprpak, tslinkaux)
239  if (associated(tslinkaux)) then
240  ! set variable name
241  tslinkaux%Text = this%ctx%auxname_cst(ts_strloc%col)
242  ! set boundname if provided
243  if (this%ctx%boundnames > 0) then
244  sv_bound => this%structarray%get(this%iboundname)
245  boundname = sv_bound%charstr1d(ts_strloc%row)
246  tslinkaux%BndName = boundname
247  end if
248  end if
249  end subroutine ts_link_aux
250 
251  subroutine ts_update(this, structarray)
255  class(listloadtype), intent(inout) :: this
256  type(structarraytype), pointer, intent(inout) :: structarray
257  integer(I4B) :: n, m
258  type(tsstringloctype), pointer :: ts_strloc
259  type(structvectortype), pointer :: sv
260 
261  do m = 1, structarray%count()
262  sv => structarray%get(m)
263  if (sv%idt%timeseries) then
264  do n = 1, sv%ts_strlocs%count()
265  ts_strloc => sv%get_ts_strloc(n)
266  call this%ts_link(sv, ts_strloc)
267  end do
268  call sv%clear()
269  end if
270  end do
271 
272  ! terminate if errors were detected
273  if (count_errors() > 0) then
274  call store_error_filename(this%input_name)
275  end if
276  end subroutine ts_update
277 
278  subroutine ts_link(this, structvector, ts_strloc)
280  class(listloadtype), intent(inout) :: this
281  type(structvectortype), pointer, intent(in) :: structvector
282  type(tsstringloctype), pointer, intent(in) :: ts_strloc
283  select case (structvector%memtype)
284  case (2) ! dbl1d
285  call this%ts_link_bnd(structvector, ts_strloc)
286  case (6) ! dbl2d
287  call this%ts_link_aux(structvector, ts_strloc)
288  case default
289  end select
290  end subroutine ts_link
291 
292  subroutine create_structarray(this)
295  class(listloadtype), intent(inout) :: this
296  type(inputparamdefinitiontype), pointer :: idt
297  integer(I4B) :: icol
298 
299  ! construct and set up the struct array object
300  this%structarray => constructstructarray(this%mf6_input, this%nparam, &
301  this%ctx%maxbound, 0, &
302  this%mf6_input%mempath, &
303  this%mf6_input%component_mempath)
304  ! set up struct array
305  do icol = 1, this%nparam
306  idt => get_param_definition_type(this%mf6_input%param_dfns, &
307  this%mf6_input%component_type, &
308  this%mf6_input%subcomponent_type, &
309  'PERIOD', &
310  this%param_names(icol), this%input_name)
311  ! allocate variable in memory manager
312  call this%structarray%mem_create_vector(icol, idt)
313  ! store boundname index when found
314  if (idt%mf6varname == 'BOUNDNAME') this%iboundname = icol
315  end do
316  end subroutine create_structarray
317 
318 end module listloadmodule
This module contains the AsciiInputLoadTypeModule.
This module contains block parser methods.
Definition: BlockParser.f90:7
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 ListLoadModule.
Definition: Mf6FileList.f90:7
subroutine ainit(this, mf6_input, component_name, component_input_name, input_name, iperblock, parser, iout)
Definition: Mf6FileList.f90:54
subroutine ad(this)
subroutine ts_link_aux(this, structvector, ts_strloc)
subroutine rp(this, parser)
subroutine destroy(this)
subroutine df(this)
subroutine reset(this)
subroutine ts_link_bnd(this, structvector, ts_strloc)
subroutine create_structarray(this)
subroutine ts_update(this, structarray)
subroutine ts_link(this, structvector, ts_strloc)
This module contains the LoadContextModule.
Definition: LoadContext.f90:10
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 ModflowInputModule.
Definition: ModflowInput.f90:9
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
This class is used to store a single deferred-length character string. It was designed to work in an ...
Definition: CharString.f90:23
list input loader for dynamic packages.
Definition: Mf6FileList.f90:30
derived type for boundary package input context
Definition: LoadContext.f90:61
Static parser based input loader.
Definition: LoadMf6File.f90:47
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