MODFLOW 6  version 6.7.0.dev2
USGS Modular Hydrologic Model
ModflowInput.f90
Go to the documentation of this file.
1 !> @brief This module contains the ModflowInputModule
2 !!
3 !! This module contains a helper object and function
4 !! for accessing the ModflowInput, which is a
5 !! description of the structure of a modflow input
6 !! file.
7 !!
8 !<
10 
11  use kindmodule, only: i4b, lgp
21 
22  implicit none
23  private
25 
26  !> @brief derived type for storing input definition for a file
27  !!
28  !! This derived type contains the information needed to read
29  !! a specific modflow input file, including block definitions,
30  !! aggregate definitions (structarrays), and individual
31  !! parameter definitions.
32  !!
33  !<
35  character(len=LENCOMPONENTNAME) :: pkgtype
36  character(len=LENCOMPONENTNAME) :: component_type
37  character(len=LENCOMPONENTNAME) :: subcomponent_type
38  character(len=LENCOMPONENTNAME) :: component_name
39  character(len=LENCOMPONENTNAME) :: subcomponent_name
40  character(len=LENMEMPATH) :: mempath
41  character(len=LENMEMPATH) :: component_mempath
42  character(len=LENCOMPONENTNAME) :: load_scope
43  type(inputblockdefinitiontype), dimension(:), pointer :: block_dfns
44  type(inputparamdefinitiontype), dimension(:), pointer :: aggregate_dfns
45  type(inputparamdefinitiontype), dimension(:), pointer :: param_dfns
46  end type modflowinputtype
47 
48 contains
49 
50  !> @brief function to return ModflowInputType
51  !<
52  function getmodflowinput(pkgtype, component_type, subcomponent_type, &
53  component_name, subcomponent_name, &
54  load_scope, filename) &
55  result(mf6_input)
56  character(len=*), intent(in) :: pkgtype !< package type to load, such as DIS6, DISV6, NPF6
57  character(len=*), intent(in) :: component_type !< component type, such as GWF or GWT
58  character(len=*), intent(in) :: subcomponent_type !< subcomponent type, such as DIS or NPF
59  character(len=*), intent(in) :: component_name !< component name, such as MYGWFMODEL
60  character(len=*), intent(in) :: subcomponent_name !< subcomponent name, such as MYWELLPACKAGE
61  character(len=*), intent(in) :: load_scope !< e.g. SIM, MODEL, EXCHANGE
62  character(len=*), optional, intent(in) :: filename !< optional name of package input file
63  type(modflowinputtype) :: mf6_input
64  character(len=LENPACKAGETYPE) :: dfn_subcomponent_type
65 
66  ! set subcomponent type
67  if (present(filename)) then
68  dfn_subcomponent_type = update_sc_type(pkgtype, filename, component_type, &
69  subcomponent_type)
70  else
71  dfn_subcomponent_type = trim(subcomponent_type)
72  end if
73 
74  ! set input attributes
75  mf6_input%pkgtype = trim(pkgtype)
76  mf6_input%component_type = trim(component_type)
77  mf6_input%subcomponent_type = trim(dfn_subcomponent_type)
78  mf6_input%component_name = trim(component_name)
79  mf6_input%subcomponent_name = trim(subcomponent_name)
80  mf6_input%load_scope = trim(load_scope)
81 
82  ! set mempaths
83  mf6_input%mempath = create_mem_path(component_name, subcomponent_name, &
85  mf6_input%component_mempath = create_mem_path(component=component_name, &
86  context=idm_context)
87 
88  ! set input definitions
89  mf6_input%block_dfns => block_definitions(mf6_input%component_type, &
90  mf6_input%subcomponent_type)
91  mf6_input%aggregate_dfns => aggregate_definitions(mf6_input%component_type, &
92  mf6_input%subcomponent_type)
93  mf6_input%param_dfns => param_definitions(mf6_input%component_type, &
94  mf6_input%subcomponent_type)
95  end function getmodflowinput
96 
97  function update_sc_type(filetype, filename, component_type, subcomponent_type) &
98  result(sc_type)
99  character(len=*), intent(in) :: component_type
100  character(len=*), intent(in) :: subcomponent_type
101  character(len=*), intent(in) :: filetype
102  character(len=*), intent(in) :: filename
103  character(len=LENPACKAGETYPE) :: sc_type
104  sc_type = subcomponent_type
105  select case (subcomponent_type)
106  case ('CHD', 'DRN', 'EVT', 'GHB', 'RCH', 'RIV', 'SCP', 'WEL')
107  sc_type = readarray(filetype, filename, component_type, &
108  subcomponent_type)
109  case default
110  end select
111  end function update_sc_type
112 
113  function readarray(filetype, filename, component_type, subcomponent_type) &
114  result(sc_type)
115  use constantsmodule, only: linelength
118  character(len=*), intent(in) :: component_type
119  character(len=*), intent(in) :: subcomponent_type
120  character(len=*), intent(in) :: filetype
121  character(len=*), intent(in) :: filename
122  character(len=LENPACKAGETYPE) :: sc_type
123  type(blockparsertype) :: parser
124  integer(I4B) :: ierr, inunit
125  logical(LGP) :: isfound
126  logical(LGP) :: endofblock
127  character(len=LINELENGTH) :: keyword
128 
129  sc_type = subcomponent_type
130  inunit = getunit()
131  call openfile(inunit, 0, trim(adjustl(filename)), filetype, &
132  'FORMATTED', 'SEQUENTIAL', 'OLD')
133  call parser%Initialize(inunit, 0)
134 
135  ! get options block
136  call parser%GetBlock('OPTIONS', isfound, ierr, &
137  supportopenclose=.true., blockrequired=.false.)
138 
139  ! parse options block if detected
140  if (isfound) then
141  do
142  call parser%GetNextLine(endofblock)
143  if (endofblock) exit
144  call parser%GetStringCaps(keyword)
145  select case (keyword)
146  case ('READASARRAYS')
147  write (sc_type, '(a)') trim(subcomponent_type)//'A'
148  case ('READARRAYGRID')
149  write (sc_type, '(a)') trim(subcomponent_type)//'G'
150  case default
151  end select
152  end do
153  end if
154 
155  call parser%clear()
156  end function readarray
157 
158 end module modflowinputmodule
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 lencomponentname
maximum length of a component name
Definition: Constants.f90:18
integer(i4b), parameter lenpackagetype
maximum length of a package type (DIS6, SFR6, CSUB6, etc.)
Definition: Constants.f90:38
integer(i4b), parameter lenmempath
maximum length of the memory path
Definition: Constants.f90:27
type(inputblockdefinitiontype) function, dimension(:), pointer, public block_definitions(component, subcomponent)
type(inputparamdefinitiontype) function, dimension(:), pointer, public param_definitions(component, subcomponent)
type(inputparamdefinitiontype) function, dimension(:), pointer, public aggregate_definitions(component, subcomponent)
This module contains the InputDefinitionModule.
integer(i4b) function, public getunit()
Get a free unit number.
subroutine, public openfile(iu, iout, fname, ftype, fmtarg_opt, accarg_opt, filstat_opt, mode_opt)
Open a file.
Definition: InputOutput.f90:30
This module defines variable data types.
Definition: kind.f90:8
character(len=lenmempath) function create_mem_path(component, subcomponent, context)
returns the path to the memory object
This module contains the ModflowInputModule.
Definition: ModflowInput.f90:9
character(len=lenpackagetype) function update_sc_type(filetype, filename, component_type, subcomponent_type)
character(len=lenpackagetype) function readarray(filetype, filename, component_type, subcomponent_type)
type(modflowinputtype) function, public getmodflowinput(pkgtype, component_type, subcomponent_type, component_name, subcomponent_name, load_scope, filename)
function to return ModflowInputType
This module contains simulation variables.
Definition: SimVariables.f90:9
character(len=linelength) idm_context
derived type for storing input definition for a file