MODFLOW 6  version 6.5.0.dev2
MODFLOW 6 Code Documentation
sourcecommonmodule Module Reference

This module contains the SourceCommonModule. More...

Functions/Subroutines

character(len=lenpackagename) function, public package_source_type (sourcename)
 source identifier from model namfile FNAME array More...
 
character(len=lencomponentname) function, public idm_component_type (component)
 component from package or model type More...
 
character(len=lencomponentname) function, public idm_subcomponent_type (component, subcomponent)
 component from package or model type More...
 
character(len=lenpackagename) function, public idm_subcomponent_name (component_type, subcomponent_type, sc_name)
 model package subcomponent name More...
 
character(len=lenpackagetype) function, public file_ext (filename)
 input file extension More...
 
subroutine, public get_shape_from_string (shape_string, array_shape, memoryPath)
 
subroutine, public set_model_shape (ftype, fname, model_mempath, dis_mempath, model_shape)
 routine for setting the model shape More...
 
integer(i4b) function, public ifind_charstr (array, str)
 
logical(lgp) function, public filein_fname (filename, tagname, input_mempath, input_fname)
 enforce and set a single input filename provided via FILEIN keyword More...
 

Detailed Description

This module contains source independent input processing helper routines.

Function/Subroutine Documentation

◆ file_ext()

character(len=lenpackagetype) function, public sourcecommonmodule::file_ext ( character(len=*), intent(in)  filename)

Return a file extension, or an empty string if not identified.

Definition at line 174 of file SourceCommon.f90.

175  ! -- modules
177  ! -- dummy
178  character(len=*), intent(in) :: filename
179  ! -- return
180  character(len=LENPACKAGETYPE) :: ext
181  ! -- local
182  integer(I4B) :: idx
183  !
184  ! -- initialize
185  ext = ''
186  idx = 0
187  !
188  ! -- identify '.' character position from back of string
189  idx = index(filename, '.', back=.true.)
190  !
191  !
192  if (idx > 0) then
193  ext = filename(idx + 1:len_trim(filename))
194  end if
195  !
196  ! -- return
197  return
logical function, public idm_multi_package(component, subcomponent)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ filein_fname()

logical(lgp) function, public sourcecommonmodule::filein_fname ( character(len=*), intent(inout)  filename,
character(len=*), intent(in)  tagname,
character(len=*), intent(in)  input_mempath,
character(len=*), intent(in)  input_fname 
)

Set a FILEIN filename provided via an OPTIONS block. Only use this function if a maximum of one FILEIN file name string is expected.

Return true if single FILEIN file name found and set, return false if FILEIN tag not found.

Definition at line 446 of file SourceCommon.f90.

451  character(len=*), intent(inout) :: filename
452  character(len=*), intent(in) :: tagname
453  character(len=*), intent(in) :: input_mempath
454  character(len=*), intent(in) :: input_fname
455  logical(LGP) :: found
456  type(CharacterStringType), dimension(:), pointer, &
457  contiguous :: fnames
458  integer(I4B) :: isize
459  !
460  ! -- initialize
461  found = .false.
462  filename = ''
463  !
464  call get_isize(tagname, input_mempath, isize)
465  !
466  if (isize > 0) then
467  !
468  if (isize /= 1) then
469  errmsg = 'Multiple FILEIN keywords detected for tag "'//trim(tagname)// &
470  '" in OPTIONS block. Only one entry allowed.'
471  call store_error(errmsg)
472  call store_error_filename(input_fname)
473  end if
474  !
475  call mem_setptr(fnames, tagname, input_mempath)
476  !
477  filename = fnames(1)
478  found = .true.
479  !
480  end if
481  !
482  ! -- return
483  return
subroutine, public get_isize(name, mem_path, isize)
@ brief Get the number of elements for this variable
This module contains simulation methods.
Definition: Sim.f90:10
subroutine, public store_error(msg, terminate)
Store an error message.
Definition: Sim.f90:92
subroutine, public store_error_filename(filename, terminate)
Store the erroring file name.
Definition: Sim.f90:203
This class is used to store a single deferred-length character string. It was designed to work in an ...
Definition: CharString.f90:23
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_shape_from_string()

subroutine, public sourcecommonmodule::get_shape_from_string ( character(len=*), intent(in)  shape_string,
integer(i4b), dimension(:), intent(inout), allocatable  array_shape,
character(len=*), intent(in)  memoryPath 
)
Parameters
[in]memorypathmemorypath to put loaded information

Definition at line 200 of file SourceCommon.f90.

201  use inputoutputmodule, only: parseline
203  character(len=*), intent(in) :: shape_string
204  integer(I4B), dimension(:), allocatable, intent(inout) :: array_shape
205  character(len=*), intent(in) :: memoryPath !< memorypath to put loaded information
206  integer(I4B) :: ndim
207  integer(I4B) :: i
208  integer(I4B), pointer :: int_ptr
209  character(len=16), dimension(:), allocatable :: array_shape_string
210  character(len=:), allocatable :: shape_string_copy
211  !
212  ! -- parse the string into multiple words
213  shape_string_copy = trim(shape_string)//' '
214  call parseline(shape_string_copy, ndim, array_shape_string)
215  allocate (array_shape(ndim))
216  !
217  ! -- find shape in memory manager and put into array_shape
218  do i = 1, ndim
219  call mem_setptr(int_ptr, array_shape_string(i), memorypath)
220  array_shape(i) = int_ptr
221  end do
222  !
223  ! -- return
224  return
subroutine, public parseline(line, nwords, words, inunit, filename)
Parse a line into words.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ idm_component_type()

character(len=lencomponentname) function, public sourcecommonmodule::idm_component_type ( character(len=*), intent(in)  component)

Return the component type typically derived from package file type, i.e. return GWF when input is GWF6. This function checks the resultant component type and throws a terminating error if not supported by IDM in some capacity.

Definition at line 62 of file SourceCommon.f90.

63  ! -- modules
65  ! -- dummy
66  character(len=*), intent(in) :: component
67  ! -- return
68  character(len=LENCOMPONENTNAME) :: component_type
69  ! -- local
70  integer(I4B) :: i, ilen, idx
71  !
72  ! -- initialize
73  component_type = ''
74  idx = 0
75  !
76  ilen = len_trim(component)
77  do i = 1, ilen
78  if (component(i:i) == '6' .or. component(i:i) == '-') then
79  else
80  idx = idx + 1
81  component_type(idx:idx) = component(i:i)
82  end if
83  end do
84  !
85  if (.not. idm_component(component_type)) then
86  write (errmsg, '(a)') &
87  'IDP input error, unrecognized component: "'//trim(component)//'"'
88  call store_error(errmsg, .true.)
89  end if
90  !
91  ! -- return
92  return
logical function, public idm_component(component)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ idm_subcomponent_name()

character(len=lenpackagename) function, public sourcecommonmodule::idm_subcomponent_name ( character(len=*), intent(in)  component_type,
character(len=*), intent(in)  subcomponent_type,
character(len=*), intent(in)  sc_name 
)

Return the IDM component name, which is the package type for base packages and the package name for multi package (i.e. stress) types.

Definition at line 142 of file SourceCommon.f90.

144  ! -- modules
146  ! -- dummy
147  character(len=*), intent(in) :: component_type
148  character(len=*), intent(in) :: subcomponent_type
149  character(len=*), intent(in) :: sc_name
150  ! -- return
151  character(len=LENPACKAGENAME) :: subcomponent_name
152  ! -- local
153  !
154  subcomponent_name = ''
155  !
156  if (idm_multi_package(component_type, subcomponent_type)) then
157  !
158  subcomponent_name = sc_name
159  else
160  !
161  subcomponent_name = subcomponent_type
162  end if
163  !
164  ! -- return
165  return
Here is the call graph for this function:
Here is the caller graph for this function:

◆ idm_subcomponent_type()

character(len=lencomponentname) function, public sourcecommonmodule::idm_subcomponent_type ( character(len=*), intent(in)  component,
character(len=*), intent(in)  subcomponent 
)

Return the subcomponent type typically derived from package file type, i.e. return CHD when input is CHD6. Note this function is called on file types that are both idm integrated and not and should not set an error based on this difference.

Parameters
[in]componentcomponent, e.g. GWF6
[in]subcomponentsubcomponent, e.g. CHD6

Definition at line 103 of file SourceCommon.f90.

105  ! -- modules
106  ! -- dummy
107  character(len=*), intent(in) :: component !< component, e.g. GWF6
108  character(len=*), intent(in) :: subcomponent !< subcomponent, e.g. CHD6
109  ! -- return
110  character(len=LENCOMPONENTNAME) :: subcomponent_type
111  ! -- local
112  character(len=LENCOMPONENTNAME) :: component_type
113  integer(I4B) :: i, ilen, idx
114  !
115  ! -- initialize
116  subcomponent_type = ''
117  idx = 0
118  !
119  ! -- verify component
120  component_type = idm_component_type(component)
121  !
122  ilen = len_trim(subcomponent)
123  do i = 1, ilen
124  if (subcomponent(i:i) == '6' .or. subcomponent(i:i) == '-') then
125  else
126  idx = idx + 1
127  subcomponent_type(idx:idx) = subcomponent(i:i)
128  end if
129  end do
130  !
131  ! -- return
132  return
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ifind_charstr()

integer(i4b) function, public sourcecommonmodule::ifind_charstr ( type(characterstringtype), dimension(:), intent(in)  array,
character(len=*)  str 
)

Definition at line 407 of file SourceCommon.f90.

409  ! -- Find the first array element containing str
410  ! -- Return -1 if not found.
411  implicit none
412  ! -- return
413  integer(I4B) :: ifind_charstr
414  ! -- dummy
415  type(CharacterStringType), dimension(:), intent(in) :: array
416  character(len=*) :: str
417  character(len=LINELENGTH) :: compare_str
418  ! -- local
419  integer(I4B) :: i
420  !
421  ! -- initialize
422  ifind_charstr = -1
423  !
424  findloop: do i = 1, size(array)
425  compare_str = array(i)
426  if (compare_str == str) then
427  ifind_charstr = i
428  exit findloop
429  end if
430  end do findloop
431  !
432  ! -- return
433  return
Here is the caller graph for this function:

◆ package_source_type()

character(len=lenpackagename) function, public sourcecommonmodule::package_source_type ( character(len=*), intent(in)  sourcename)

Return the source type for a package listed in the model nam file packages block FNAME field.

Definition at line 33 of file SourceCommon.f90.

34  ! -- modules
35  use inputoutputmodule, only: upcase
36  ! -- dummy
37  character(len=*), intent(in) :: sourcename
38  ! -- result
39  character(len=LENPACKAGENAME) :: sourcetype
40  ! -- local
41  character(len=LENPACKAGENAME) :: ext
42  !
43  ext = file_ext(sourcename)
44  !
45  select case (ext)
46  case default
47  sourcetype = 'MF6FILE'
48  end select
49  !
50  ! -- return
51  return
subroutine, public upcase(word)
Convert to upper case.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_model_shape()

subroutine, public sourcecommonmodule::set_model_shape ( character(len=*), intent(in)  ftype,
character(len=*), intent(in)  fname,
character(len=*), intent(in)  model_mempath,
character(len=*), intent(in)  dis_mempath,
integer(i4b), dimension(:), intent(inout), pointer, contiguous  model_shape 
)

The model shape must be set in the memory manager because individual packages need to know the shape of the arrays to read.

Definition at line 234 of file SourceCommon.f90.

238  character(len=*), intent(in) :: ftype
239  character(len=*), intent(in) :: fname
240  character(len=*), intent(in) :: model_mempath
241  character(len=*), intent(in) :: dis_mempath
242  integer(I4B), dimension(:), pointer, contiguous, intent(inout) :: model_shape
243  integer(I4B), pointer :: ndim1
244  integer(I4B), pointer :: ndim2
245  integer(I4B), pointer :: ndim3
246  integer(I4B), pointer :: ncelldim
247  integer(I4B), pointer :: distype
248  integer(I4B) :: dim1_size, dim2_size, dim3_size, dis_type
249  !
250  ! -- initialize dis_type
251  dis_type = disundef
252  !
253  ! -- allocate and set model shape in model input context
254  select case (ftype)
255  case ('DIS6')
256  !
257  ! -- set dis_type
258  dis_type = dis
259  !
260  call get_isize('NLAY', dis_mempath, dim1_size)
261  call get_isize('NROW', dis_mempath, dim2_size)
262  call get_isize('NCOL', dis_mempath, dim3_size)
263  !
264  if (dim1_size <= 0) then
265  write (errmsg, '(a)') &
266  'Required input dimension "NLAY" not found.'
267  call store_error(errmsg)
268  end if
269  !
270  if (dim2_size <= 0) then
271  write (errmsg, '(a)') &
272  'Required input dimension "NROW" not found.'
273  call store_error(errmsg)
274  end if
275  !
276  if (dim3_size <= 0) then
277  write (errmsg, '(a)') &
278  'Required input dimension "NCOL" not found.'
279  call store_error(errmsg)
280  end if
281  !
282  if (dim1_size >= 1 .and. dim2_size >= 1 .and. dim3_size >= 1) then
283  call mem_allocate(model_shape, 3, 'MODEL_SHAPE', model_mempath)
284  call mem_setptr(ndim1, 'NLAY', dis_mempath)
285  call mem_setptr(ndim2, 'NROW', dis_mempath)
286  call mem_setptr(ndim3, 'NCOL', dis_mempath)
287  model_shape = [ndim1, ndim2, ndim3]
288  else
289  call store_error_filename(fname)
290  end if
291  !
292  case ('DIS2D6')
293  !
294  ! -- set dis_type
295  dis_type = dis2d
296  !
297  call get_isize('NROW', dis_mempath, dim1_size)
298  call get_isize('NCOL', dis_mempath, dim2_size)
299  !
300  if (dim1_size <= 0) then
301  write (errmsg, '(a)') &
302  'Required input dimension "NROW" not found.'
303  call store_error(errmsg)
304  end if
305  !
306  if (dim2_size <= 0) then
307  write (errmsg, '(a)') &
308  'Required input dimension "NCOL" not found.'
309  call store_error(errmsg)
310  end if
311  !
312  if (dim1_size >= 1 .and. dim2_size >= 1) then
313  call mem_allocate(model_shape, 2, 'MODEL_SHAPE', model_mempath)
314  call mem_setptr(ndim1, 'NROW', dis_mempath)
315  call mem_setptr(ndim2, 'NCOL', dis_mempath)
316  model_shape = [ndim1, ndim2]
317  else
318  call store_error_filename(fname)
319  end if
320  !
321  case ('DISV6')
322  !
323  ! -- set dis_type
324  dis_type = disv
325  !
326  call get_isize('NLAY', dis_mempath, dim1_size)
327  call get_isize('NCPL', dis_mempath, dim2_size)
328  !
329  if (dim1_size <= 0) then
330  write (errmsg, '(a)') &
331  'Required input dimension "NLAY" not found.'
332  call store_error(errmsg)
333  end if
334  !
335  if (dim2_size <= 0) then
336  write (errmsg, '(a)') &
337  'Required input dimension "NCPL" not found.'
338  call store_error(errmsg)
339  end if
340  !
341  if (dim1_size >= 1 .and. dim2_size >= 1) then
342  call mem_allocate(model_shape, 2, 'MODEL_SHAPE', model_mempath)
343  call mem_setptr(ndim1, 'NLAY', dis_mempath)
344  call mem_setptr(ndim2, 'NCPL', dis_mempath)
345  model_shape = [ndim1, ndim2]
346  else
347  call store_error_filename(fname)
348  end if
349  case ('DISV2D6')
350  !
351  call get_isize('NODES', dis_mempath, dim1_size)
352  !
353  if (dim1_size <= 0) then
354  write (errmsg, '(a)') &
355  'Required input dimension "NODES" not found.'
356  call store_error(errmsg)
357  end if
358  !
359  if (dim1_size >= 1) then
360  call mem_allocate(model_shape, 1, 'MODEL_SHAPE', model_mempath)
361  call mem_setptr(ndim1, 'NODES', dis_mempath)
362  model_shape = [ndim1]
363  else
364  call store_error_filename(fname)
365  end if
366  case ('DISU6', 'DISV1D6')
367  !
368  ! -- set dis_type
369  if (ftype == 'DISU6') then
370  dis_type = disu
371  else if (ftype == 'DISV1D6') then
372  dis_type = disv1d
373  end if
374  !
375  call get_isize('NODES', dis_mempath, dim1_size)
376  !
377  if (dim1_size <= 0) then
378  write (errmsg, '(a)') &
379  'Required input dimension "NODES" not found.'
380  call store_error(errmsg)
381  call store_error_filename(fname)
382  end if
383  !
384  call mem_allocate(model_shape, 1, 'MODEL_SHAPE', model_mempath)
385  call mem_setptr(ndim1, 'NODES', dis_mempath)
386  model_shape = [ndim1]
387  case default
388  errmsg = 'Unknown discretization type. IDM cannot set shape for "' &
389  //trim(ftype)//"'"
390  call store_error(errmsg)
391  call store_error_filename(fname)
392  end select
393  !
394  ! -- allocate and set ncelldim in model input context
395  call mem_allocate(ncelldim, 'NCELLDIM', model_mempath)
396  ncelldim = size(model_shape)
397  !
398  ! -- allocate and set distype in model input context
399  ! TODO make sure this doesn't clash name GRIDTYPE, e.g.
400  call mem_allocate(distype, 'DISENUM', model_mempath)
401  distype = dis_type
402  !
403  ! -- return
404  return
This module contains simulation constants.
Definition: Constants.f90:9
@ disu
DISV6 discretization.
Definition: Constants.f90:156
@ dis
DIS6 discretization.
Definition: Constants.f90:154
@ disv1d
DISV1D6 discretization.
Definition: Constants.f90:159
@ dis2d
DIS2D6 discretization.
Definition: Constants.f90:162
@ disv
DISU6 discretization.
Definition: Constants.f90:155
@ disundef
undefined discretization
Definition: Constants.f90:152
Here is the call graph for this function:
Here is the caller graph for this function: