MODFLOW 6  version 6.6.0.dev0
USGS Modular Hydrologic Model
modelpackageinputsmodule Module Reference

This module contains the ModelPackageInputsModule. More...

Data Types

type  loadablepackagetype
 derived type for loadable package type More...
 
type  modelpackageinputstype
 derived type for model package inputs type More...
 

Functions/Subroutines

logical(lgp) function multi_pkg_type (mtype_component, ptype_component, pkgtype)
 does model support multiple instances of this package type More...
 
subroutine pkgtype_create (this, modeltype, modelname, pkgtype)
 create a new package type More...
 
subroutine pkgtype_add (this, modelname, mtype_component, filetype, filename, pkgname, iout)
 add a new package instance to this package type More...
 
subroutine pkgtype_destroy (this)
 deallocate object More...
 
subroutine modelpkgs_init (this, modeltype, modelfname, modelname, iout)
 initialize model package inputs object More...
 
subroutine modelpkgs_create (this, ftypes)
 create the package type list More...
 
subroutine modelpkgs_add (this, pkgtype, filename, pkgname)
 add a model package instance to package type list More...
 
subroutine modelpkgs_addpkgs (this)
 build the type list with all model package instances More...
 
integer(i4b) function modelpkgs_pkgcount (this)
 get package instance count and verify base or multi of each More...
 
subroutine modelpkgs_memload (this)
 load package descriptors to managed memory More...
 
subroutine modelpkgs_destroy (this)
 deallocate object More...
 

Detailed Description

This module contains the high-level routines for assembling model package information and loading to the input context

Function/Subroutine Documentation

◆ modelpkgs_add()

subroutine modelpackageinputsmodule::modelpkgs_add ( class(modelpackageinputstype this,
character(len=*), intent(in)  pkgtype,
character(len=*), intent(in)  filename,
character(len=*), intent(in)  pkgname 
)

Definition at line 314 of file ModelPackageInputs.f90.

315  class(ModelPackageInputsType) :: this
316  character(len=*), intent(in) :: pkgtype
317  character(len=*), intent(in) :: filename
318  character(len=*), intent(in) :: pkgname
319  type(LoadablePackageType) :: pkg
320  integer(I4B) :: n
321  ! locate index of pkgtype in pkglist
322  do n = 1, size(this%pkglist)
323  pkg = this%pkglist(n)
324  if (pkg%pkgtype == pkgtype) then
325  call this%pkglist(n)%add(this%modelname, this%component_type, &
326  pkgtype, filename, pkgname, this%iout)
327  exit
328  end if
329  end do

◆ modelpkgs_addpkgs()

subroutine modelpackageinputsmodule::modelpkgs_addpkgs ( class(modelpackageinputstype this)
private

Definition at line 334 of file ModelPackageInputs.f90.

337  class(ModelPackageInputsType) :: this
338  type(CharacterStringType), dimension(:), contiguous, &
339  pointer :: ftypes !< file types
340  type(CharacterStringType), dimension(:), contiguous, &
341  pointer :: fnames !< file names
342  type(CharacterStringType), dimension(:), contiguous, &
343  pointer :: pnames !< package names
344  character(len=LINELENGTH) :: ftype, fname, pname
345  integer(I4B) :: n
346 
347  ! set pointers to input context model package attribute arrays
348  call mem_setptr(ftypes, 'FTYPE', this%input_mempath)
349  call mem_setptr(fnames, 'FNAME', this%input_mempath)
350  call mem_setptr(pnames, 'PNAME', this%input_mempath)
351 
352  ! create the package list
353  call this%create(ftypes)
354 
355  ! load model packages
356  do n = 1, size(ftypes)
357  ! attributes for this package
358  ftype = ftypes(n)
359  fname = fnames(n)
360  call inlen_check(pnames(n), pname, lenpackagename, 'PACKAGENAME')
361 
362  ! add this instance to package list
363  call this%add(ftype, fname, pname)
364  end do
365 
366  ! terminate if errors were detected
367  if (count_errors() > 0) then
368  call store_error_filename(this%modelfname)
369  end if
This module contains the SourceCommonModule.
Definition: SourceCommon.f90:7
subroutine, public inlen_check(input_name, mf6_name, maxlen, name_type)
store an error for input exceeding internal name length
Here is the call graph for this function:

◆ modelpkgs_create()

subroutine modelpackageinputsmodule::modelpkgs_create ( class(modelpackageinputstype this,
type(characterstringtype), dimension(:), pointer, contiguous  ftypes 
)

Definition at line 246 of file ModelPackageInputs.f90.

247  use sortmodule, only: qsort
248  class(ModelPackageInputsType) :: this
249  type(CharacterStringType), dimension(:), contiguous, &
250  pointer :: ftypes
251  integer(I4B), dimension(:), allocatable :: cunit_idxs, indx
252  character(len=LENPACKAGETYPE) :: ftype
253  integer(I4B) :: n, m
254  logical(LGP) :: found
255 
256  ! allocate
257  allocate (cunit_idxs(0))
258 
259  ! identify input packages and check that each is supported
260  do n = 1, size(ftypes)
261  ! type from model nam file packages block
262  ftype = ftypes(n)
263  found = .false.
264 
265  ! search supported types for this filetype
266  do m = 1, this%niunit
267  if (this%cunit(m) == ftype) then
268  ! set found
269  found = .true.
270 
271  ! add to cunit list if first instance of this type
272  if (any(cunit_idxs == m)) then
273  ! no-op
274  else
275  call expandarray(cunit_idxs)
276  cunit_idxs(size(cunit_idxs)) = m
277  end if
278 
279  ! exit search
280  exit
281  end if
282  end do
283 
284  ! set error if namfile pkg filetype is not supported
285  if (.not. found) then
286  write (errmsg, '(a,a,a,a,a)') 'Model package type not supported &
287  &[model=', trim(this%modelname), ', type=', &
288  trim(ftype), '].'
289  call store_error(errmsg)
290  call store_error_filename(this%modelfname)
291  end if
292  end do
293 
294  ! allocate the pkglist
295  allocate (this%pkglist(size(cunit_idxs)))
296 
297  ! sort cunit indexes
298  allocate (indx(size(cunit_idxs)))
299  call qsort(indx, cunit_idxs)
300 
301  ! create sorted LoadablePackageType object list
302  do n = 1, size(cunit_idxs)
303  call this%pkglist(n)%create(this%modeltype, this%modelname, &
304  this%cunit(cunit_idxs(n)))
305  end do
306 
307  ! cleanup
308  deallocate (cunit_idxs)
309  deallocate (indx)
Here is the call graph for this function:

◆ modelpkgs_destroy()

subroutine modelpackageinputsmodule::modelpkgs_destroy ( class(modelpackageinputstype this)

Definition at line 447 of file ModelPackageInputs.f90.

448  class(ModelPackageInputsType) :: this
449  integer(I4B) :: n
450  do n = 1, size(this%pkglist)
451  call this%pkglist(n)%destroy()
452  end do
453  deallocate (this%pkglist)
454  deallocate (this%cunit)

◆ modelpkgs_init()

subroutine modelpackageinputsmodule::modelpkgs_init ( class(modelpackageinputstype this,
character(len=*), intent(in)  modeltype,
character(len=*), intent(in)  modelfname,
character(len=*), intent(in)  modelname,
integer(i4b), intent(in)  iout 
)
private

Definition at line 205 of file ModelPackageInputs.f90.

211  class(ModelPackageInputsType) :: this
212  character(len=*), intent(in) :: modeltype
213  character(len=*), intent(in) :: modelfname
214  character(len=*), intent(in) :: modelname
215  integer(I4B), intent(in) :: iout
216 
217  ! initialize object
218  this%modeltype = modeltype
219  this%modelfname = modelfname
220  this%modelname = modelname
221  this%component_type = idm_component_type(modeltype)
222  this%iout = iout
223 
224  ! allocate and set model supported package types
225  call supported_model_packages(modeltype, this%cunit, this%niunit)
226 
227  ! set memory paths
228  this%input_mempath = create_mem_path(this%modelname, 'NAM', idm_context)
229  this%model_mempath = create_mem_path(component=this%modelname, &
230  context=idm_context)
231  ! allocate managed memory
232  call mem_allocate(this%pkgtypes, lenpackagetype, 0, 'PKGTYPES', &
233  this%model_mempath)
234  call mem_allocate(this%pkgnames, lenpackagename, 0, 'PKGNAMES', &
235  this%model_mempath)
236  call mem_allocate(this%mempaths, lenmempath, 0, 'MEMPATHS', &
237  this%model_mempath)
238  call mem_allocate(this%inunits, 0, 'INUNITS', this%model_mempath)
239 
240  ! build descriptions of packages
241  call this%addpkgs()
character(len=lenmempath) function create_mem_path(component, subcomponent, context)
returns the path to the memory object
This module contains the ModelPackageInputModule.
subroutine, public supported_model_packages(mtype, pkgtypes, numpkgs)
set supported package types for model
This module contains simulation variables.
Definition: SimVariables.f90:9
character(len=linelength) idm_context
character(len=lencomponentname) function, public idm_component_type(component)
component from package or model type
Here is the call graph for this function:

◆ modelpkgs_memload()

subroutine modelpackageinputsmodule::modelpkgs_memload ( class(modelpackageinputstype this)
private

Definition at line 407 of file ModelPackageInputs.f90.

409  class(ModelPackageInputsType) :: this
410  integer(I4B) :: n, m, idx
411  integer(I4B) :: pnum
412 
413  ! initialize load index
414  idx = 0
415 
416  ! set total number of package instances
417  pnum = this%pkgcount()
418 
419  ! reallocate model input package attribute arrays
420  call mem_reallocate(this%pkgtypes, lenpackagetype, pnum, 'PKGTYPES', &
421  this%model_mempath)
422  call mem_reallocate(this%pkgnames, lenpackagename, pnum, 'PKGNAMES', &
423  this%model_mempath)
424  call mem_reallocate(this%mempaths, lenmempath, pnum, 'MEMPATHS', &
425  this%model_mempath)
426  call mem_reallocate(this%inunits, pnum, 'INUNITS', this%model_mempath)
427 
428  ! load pkinfo
429  do n = 1, size(this%pkglist)
430  do m = 1, this%pkglist(n)%pnum
431  ! increment index
432  idx = idx + 1
433  ! package type like 'CHD6'
434  this%pkgtypes(idx) = trim(this%pkglist(n)%pkgtype)
435  ! package name like 'CHD-2'
436  this%pkgnames(idx) = trim(this%pkglist(n)%pkgnames(m))
437  ! memory path like '__INPUT__/MYMODEL/CHD-2'
438  this%mempaths(idx) = trim(this%pkglist(n)%mempaths(m))
439  ! input file unit number
440  this%inunits(idx) = this%pkglist(n)%inunits(m)
441  end do
442  end do

◆ modelpkgs_pkgcount()

integer(i4b) function modelpackageinputsmodule::modelpkgs_pkgcount ( class(modelpackageinputstype this)

Definition at line 374 of file ModelPackageInputs.f90.

375  class(ModelPackageInputsType) :: this
376  integer(I4B) :: pnum
377  integer(I4B) :: n
378 
379  ! initialize
380  pnum = 0
381 
382  ! count model package instances
383  do n = 1, size(this%pkglist)
384  if (multi_pkg_type(this%component_type, &
385  this%pkglist(n)%subcomponent_type, &
386  this%pkglist(n)%pkgtype)) then
387  ! multiple instances ok
388  else
389  ! set error for unexpected extra packages
390  if (this%pkglist(n)%pnum > 1) then
391  write (errmsg, '(a,a,a,a,a)') &
392  'Multiple instances specified for model base package type &
393  &[model=', trim(this%modelname), ', type=', &
394  trim(this%pkglist(n)%pkgtype), '].'
395  call store_error(errmsg)
396  call store_error_filename(this%modelfname)
397  end if
398  end if
399 
400  ! add to package count
401  pnum = pnum + this%pkglist(n)%pnum
402  end do
Here is the call graph for this function:

◆ multi_pkg_type()

logical(lgp) function modelpackageinputsmodule::multi_pkg_type ( character(len=lencomponentname), intent(in)  mtype_component,
character(len=lencomponentname), intent(in)  ptype_component,
character(len=lenftype), intent(in)  pkgtype 
)
private

Definition at line 92 of file ModelPackageInputs.f90.

96  character(len=LENCOMPONENTNAME), intent(in) :: mtype_component
97  character(len=LENCOMPONENTNAME), intent(in) :: ptype_component
98  character(len=LENFTYPE), intent(in) :: pkgtype
99  logical(LGP) :: multi_pkg
100  multi_pkg = .false.
101  if (idm_integrated(mtype_component, ptype_component)) then
102  multi_pkg = idm_multi_package(mtype_component, ptype_component)
103  else
104  multi_pkg = multi_package_type(mtype_component, ptype_component, pkgtype)
105  end if
logical function, public idm_integrated(component, subcomponent)
logical function, public idm_multi_package(component, subcomponent)
logical(lgp) function, public multi_package_type(mtype_component, ptype_component, pkgtype)
Is the package multi-instance.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pkgtype_add()

subroutine modelpackageinputsmodule::pkgtype_add ( class(loadablepackagetype this,
character(len=*), intent(in)  modelname,
character(len=*), intent(in)  mtype_component,
character(len=*), intent(in)  filetype,
character(len=*), intent(in)  filename,
character(len=*), intent(in)  pkgname,
integer(i4b), intent(in)  iout 
)

Definition at line 131 of file ModelPackageInputs.f90.

139  class(LoadablePackageType) :: this
140  character(len=*), intent(in) :: modelname
141  character(len=*), intent(in) :: mtype_component
142  character(len=*), intent(in) :: filetype
143  character(len=*), intent(in) :: filename
144  character(len=*), intent(in) :: pkgname
145  integer(I4B), intent(in) :: iout
146  character(len=LENPACKAGENAME) :: sc_name, pname
147  character(len=LENMEMPATH) :: mempath
148  character(len=LINELENGTH), pointer :: cstr
149 
150  ! reallocate
151  call expandarray(this%filenames)
152  call expandarray(this%pkgnames)
153  call expandarray(this%inunits)
154  call expandarray(this%mempaths)
155 
156  ! add new package instance
157  this%pnum = this%pnum + 1
158  this%filenames(this%pnum) = filename
159  this%pkgnames(this%pnum) = pkgname
160  this%inunits(this%pnum) = 0
161 
162  ! set pkgname if empty
163  if (this%pkgnames(this%pnum) == '') then
164  if (multi_pkg_type(mtype_component, &
165  this%subcomponent_type, &
166  filetype)) then
167  write (pname, '(a,i0)') trim(this%subcomponent_type)//'-', this%pnum
168  else
169  write (pname, '(a,i0)') trim(this%subcomponent_type)
170  end if
171  this%pkgnames(this%pnum) = pname
172  end if
173 
174  ! set up input context for model
175  if (idm_integrated(mtype_component, this%subcomponent_type)) then
176  ! set subcomponent name
177  sc_name = idm_subcomponent_name(mtype_component, this%subcomponent_type, &
178  this%pkgnames(this%pnum))
179  ! create and store the mempath
180  this%mempaths(this%pnum) = &
181  create_mem_path(modelname, sc_name, idm_context)
182  ! allocate and initialize filename for package
183  mempath = create_mem_path(modelname, sc_name, idm_context)
184  call mem_allocate(cstr, linelength, 'INPUT_FNAME', mempath)
185  cstr = filename
186  else
187  ! set mempath empty
188  this%mempaths(this%pnum) = ''
189  end if
character(len=lenpackagename) function, public idm_subcomponent_name(component_type, subcomponent_type, sc_name)
model package subcomponent name
Here is the call graph for this function:

◆ pkgtype_create()

subroutine modelpackageinputsmodule::pkgtype_create ( class(loadablepackagetype this,
character(len=*), intent(in)  modeltype,
character(len=*), intent(in)  modelname,
character(len=*), intent(in)  pkgtype 
)

Definition at line 110 of file ModelPackageInputs.f90.

112  class(LoadablePackageType) :: this
113  character(len=*), intent(in) :: modeltype
114  character(len=*), intent(in) :: modelname
115  character(len=*), intent(in) :: pkgtype
116 
117  ! initialize
118  this%pkgtype = pkgtype
119  this%subcomponent_type = idm_subcomponent_type(modeltype, pkgtype)
120  this%pnum = 0
121 
122  ! allocate arrays
123  allocate (this%filenames(0))
124  allocate (this%pkgnames(0))
125  allocate (this%mempaths(0))
126  allocate (this%inunits(0))
character(len=lencomponentname) function, public idm_subcomponent_type(component, subcomponent)
component from package or model type
Here is the call graph for this function:

◆ pkgtype_destroy()

subroutine modelpackageinputsmodule::pkgtype_destroy ( class(loadablepackagetype this)

Definition at line 194 of file ModelPackageInputs.f90.

195  class(LoadablePackageType) :: this
196  ! deallocate dynamic arrays
197  deallocate (this%filenames)
198  deallocate (this%pkgnames)
199  deallocate (this%inunits)
200  deallocate (this%mempaths)