MODFLOW 6 version 6.9.0.dev0
USGS Modular Hydrologic Model
Loading...
Searching...
No Matches
Mf6FileSetting.f90
Go to the documentation of this file.
1!> @brief This module contains the Mf6FileSettingLoadModule
2!!
3!! This module contains the routines for reading a dfn setting
4!! with multiple tokens into a single CharacterStringType array
5!! using the StructArrayType.
6!!
7!! Preceding param columns can be configured per package (e.g. OC)
8!!
9!<
11
12 use kindmodule, only: i4b, dp, lgp
21
22 implicit none
23 private
24 public :: settingloadtype
25
26 !> @brief Pointer type for read state variable
27 !<
29 type(inputparamdefinitiontype), pointer :: idt
30 end type idtptrtype
31
32 !> @brief Setting package loader
33 !!
34 !<
36 type(structarraytype), pointer :: structarray => null() !< struct array list based load type
37 type(idtptrtype), dimension(:), allocatable :: idts !< idts for struct array input cols
38 type(loadcontexttype) :: ctx !< input load context
39 contains
40 procedure :: ainit => settingload_init
41 procedure :: df
42 procedure :: rp
43 procedure :: reset
44 procedure :: set_leading_idts
45 procedure :: set_idts
46 procedure :: set_oc_idts
47 procedure :: destroy
48 end type settingloadtype
49
50contains
51
52 subroutine settingload_init(this, mf6_input, component_name, &
53 component_input_name, input_name, &
54 iperblock, parser, iout)
57 class(settingloadtype), intent(inout) :: this
58 type(modflowinputtype), intent(in) :: mf6_input
59 character(len=*), intent(in) :: component_name
60 character(len=*), intent(in) :: component_input_name
61 character(len=*), intent(in) :: input_name
62 integer(I4B), intent(in) :: iperblock
63 type(blockparsertype), pointer, intent(inout) :: parser
64 integer(I4B), intent(in) :: iout
65 type(loadmf6filetype) :: loader
66 integer(I4B) :: icol, numset
67
68 ! init loader
69 call this%DynamicPkgLoadType%init(mf6_input, component_name, &
70 component_input_name, input_name, &
71 iperblock, iout)
72 ! initialize static loader
73 call loader%load(parser, mf6_input, this%nc_vars, this%input_name, iout)
74
75 ! create and allocate load context
76 call this%ctx%init(mf6_input)
77 call this%ctx%allocate_arrays()
78
79 ! allocate idt arrays and set idts for leading cols
80 numset = this%set_leading_idts()
81 icol = numset + 1
82
83 ! set setting idt
84 this%idts(icol)%idt => &
85 idt_default(mf6_input%component_type, mf6_input%subcomponent_type, &
86 'PERIOD', 'SETTING', 'SETTING', 'STRING')
87 ! force all setting tokens to be read
88 this%idts(icol)%idt%shape = 'LINELENGTH'
89 end subroutine settingload_init
90
91 subroutine df(this)
92 class(settingloadtype), intent(inout) :: this
93 end subroutine df
94
95 subroutine rp(this, parser)
96 class(settingloadtype), intent(inout) :: this
97 type(blockparsertype), pointer, intent(inout) :: parser
98
99 ! recreate structarray for period load
100 call this%reset()
101
102 ! read from ascii
103 this%ctx%nbound = &
104 this%structarray%read_from_parser(parser, .false., this%iout, &
105 this%input_name)
106 end subroutine rp
107
108 subroutine reset(this)
109 class(settingloadtype), intent(inout) :: this
110 integer(I4B) :: icol
111
112 if (associated(this%structarray)) then
113 ! destroy the structured array reader
114 call destructstructarray(this%structarray)
115 end if
116
117 ! construct and set up the struct array object
118 this%structarray => constructstructarray(this%mf6_input, size(this%idts), &
119 -1, 0, this%mf6_input%mempath, &
120 this%mf6_input%component_mempath)
121 ! set up struct array
122 do icol = 1, size(this%idts)
123 ! allocate variable in memory manager
124 call this%structarray%mem_create_vector(icol, this%idts(icol)%idt)
125 end do
126 end subroutine reset
127
128 function set_leading_idts(this) result(nset)
129 class(settingloadtype), intent(inout) :: this
130 integer(I4B) :: nset
131
132 ! This loader is intended to be generic for LIST based dynamic input that
133 ! includes any number of columns preceding a final keystring type
134 ! setting column. This routine handles exception cases. OC, for example,
135 ! which could adhere to this format however changes to the dfn to make it
136 ! so would introduce breaking changes to existing FloPy3 user scripts.
137
138 ! set leading idts
139 select case (this%mf6_input%subcomponent_type)
140 case ('OC')
141 nset = this%set_oc_idts()
142 case default
143 nset = this%set_idts()
144 end select
145 end function set_leading_idts
146
147 function set_idts(this) result(nset)
152 class(settingloadtype), intent(inout) :: this
153 integer(I4B) :: nset
154 type(inputparamdefinitiontype), pointer :: aidt, idt
155 character(len=LINELENGTH), dimension(:), allocatable :: cols
156 integer(I4B) :: nparam, iparam, ip, ilen
157
158 nset = 0
159
160 aidt => &
161 get_aggregate_definition_type(this%mf6_input%aggregate_dfns, &
162 this%mf6_input%component_type, &
163 this%mf6_input%subcomponent_type, &
164 'PERIOD')
165
166 call idt_parse_rectype(aidt, cols, nparam)
167
168 ! allocate idts
169 ilen = len_trim(cols(nparam))
170 if (cols(nparam) (ilen - 6:ilen) == 'SETTING') then
171 allocate (this%idts(nparam))
172 nset = nparam - 1
173 else
174 call store_error('Internal IDM error: trailing setting param not found')
175 call store_error_filename(this%input_name)
176 end if
177
178 ! set leading idts
179 do iparam = 1, nset
180 do ip = 1, size(this%mf6_input%param_dfns)
181 idt => this%mf6_input%param_dfns(ip)
182 if (idt%tagname == cols(iparam)) then
183 this%idts(iparam)%idt => idt
184 end if
185 end do
186 end do
187
188 if (allocated(cols)) deallocate (cols)
189 return
190 end function set_idts
191
192 function set_oc_idts(this) result(nset)
195 class(settingloadtype), intent(inout) :: this
196 integer(I4B) :: nset
197 type(inputparamdefinitiontype), pointer :: idt, idt_ocaction
198 integer(I4B) :: nparam, ip
199
200 ! generalize first kw field to a string
201 idt_ocaction => &
202 idt_default(this%mf6_input%component_type, &
203 this%mf6_input%subcomponent_type, &
204 'PERIOD', 'OCACTION', 'OCACTION', 'STRING')
205
206 ! set 2 leading params
207 nset = 2
208
209 ! allocate for 3 including ocsetting
210 nparam = nset + 1
211 allocate (this%idts(nparam))
212
213 ! first generalized idt
214 this%idts(1)%idt => idt_ocaction
215
216 ! set rtype idt
217 do ip = 1, size(this%mf6_input%param_dfns)
218 idt => this%mf6_input%param_dfns(ip)
219 if (idt%tagname == 'RTYPE') then
220 this%idts(2)%idt => idt
221 end if
222 end do
223 end function set_oc_idts
224
225 subroutine destroy(this)
227 class(settingloadtype), intent(inout) :: this
228 integer(I4B) :: icol
229
230 if (associated(this%structarray)) then
231 ! destroy the structured array reader
232 call destructstructarray(this%structarray)
233 end if
234
235 do icol = 1, size(this%idts)
236 !deallocate (this%idts(icol)%idt)
237 nullify (this%idts(icol)%idt)
238 end do
239
240 if (allocated(this%idts)) deallocate (this%idts)
241
242 call this%DynamicPkgLoadType%destroy()
243 end subroutine destroy
244
This module contains the AsciiInputLoadTypeModule.
This module contains block parser methods.
This module contains simulation constants.
Definition Constants.f90:9
integer(i4b), parameter linelength
maximum length of a standard line
Definition Constants.f90:45
This module contains the DefinitionSelectModule.
type(inputparamdefinitiontype) function, pointer, public idt_default(component_type, subcomponent_type, blockname, tagname, mf6varname, datatype)
return allocated input definition type
type(inputparamdefinitiontype) function, pointer, public get_aggregate_definition_type(input_definition_types, component_type, subcomponent_type, blockname)
Return aggregate definition.
subroutine, public idt_parse_rectype(idt, cols, ncol)
allocate and set RECARRAY, KEYSTRING or RECORD param list
Input definition module.
This module defines variable data types.
Definition kind.f90:8
Load context for IDM generic dynamic loaders.
subroutine destroy(this)
destroy input context object
This module contains the LoadMf6FileModule.
This module contains the Mf6FileSettingLoadModule.
integer(i4b) function set_leading_idts(this)
integer(i4b) function set_idts(this)
subroutine rp(this, parser)
subroutine settingload_init(this, mf6_input, component_name, component_input_name, input_name, iperblock, parser, iout)
integer(i4b) function set_oc_idts(this)
This module contains the ModflowInputModule.
This module contains simulation methods.
Definition Sim.f90:10
subroutine, public store_error(msg, terminate)
Store an error message.
Definition Sim.f90:94
subroutine, public store_error_filename(filename, terminate)
Store the erroring file name.
Definition Sim.f90:208
This module contains the StructArrayModule.
subroutine, public destructstructarray(struct_array)
destructor for a struct_array
type(structarraytype) function, pointer, public constructstructarray(mf6_input, ncol, nrow, blocknum, mempath, component_mempath, size_init)
constructor for a struct_array
base abstract type for ascii source dynamic load
Input parameter definition. Describes an input parameter.
Input load context for generic dynamic loaders and StructArray based static loads....
Static parser based input loader.
Pointer type for read state variable.
derived type for storing input definition for a file
type for structured array