MODFLOW 6  version 6.7.0.dev3
USGS Modular Hydrologic Model
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
13  use constantsmodule, only: linelength
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 
50 contains
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  end subroutine rp
106 
107  subroutine reset(this)
108  class(settingloadtype), intent(inout) :: this
109  integer(I4B) :: icol
110 
111  if (associated(this%structarray)) then
112  ! destroy the structured array reader
113  call destructstructarray(this%structarray)
114  end if
115 
116  ! construct and set up the struct array object
117  this%structarray => constructstructarray(this%mf6_input, size(this%idts), &
118  -1, 0, this%mf6_input%mempath, &
119  this%mf6_input%component_mempath)
120  ! set up struct array
121  do icol = 1, size(this%idts)
122  ! allocate variable in memory manager
123  call this%structarray%mem_create_vector(icol, this%idts(icol)%idt)
124  end do
125  end subroutine reset
126 
127  function set_leading_idts(this) result(nset)
128  class(settingloadtype), intent(inout) :: this
129  integer(I4B) :: nset
130 
131  ! This loader is intended to be generic for LIST based dynamic input that
132  ! includes any number of columns preceding a final keystring type
133  ! setting column. This routine handles exception cases. OC, for example,
134  ! which could adhere to this format however changes to the dfn to make it
135  ! so would introduce breaking changes to existing FloPy3 user scripts.
136 
137  ! set leading idts
138  select case (this%mf6_input%subcomponent_type)
139  case ('OC')
140  nset = this%set_oc_idts()
141  case default
142  nset = this%set_idts()
143  end select
144  end function set_leading_idts
145 
146  function set_idts(this) result(nset)
151  class(settingloadtype), intent(inout) :: this
152  integer(I4B) :: nset
153  type(inputparamdefinitiontype), pointer :: aidt, idt
154  character(len=LINELENGTH), dimension(:), allocatable :: cols
155  integer(I4B) :: nparam, iparam, ip, ilen
156 
157  nset = 0
158 
159  aidt => &
160  get_aggregate_definition_type(this%mf6_input%aggregate_dfns, &
161  this%mf6_input%component_type, &
162  this%mf6_input%subcomponent_type, &
163  'PERIOD')
164 
165  call idt_parse_rectype(aidt, cols, nparam)
166 
167  ! allocate idts
168  ilen = len_trim(cols(nparam))
169  if (cols(nparam) (ilen - 6:ilen) == 'SETTING') then
170  allocate (this%idts(nparam))
171  nset = nparam - 1
172  else
173  call store_error('Internal IDM error: trailing setting param not found')
174  call store_error_filename(this%input_name)
175  end if
176 
177  ! set leading idts
178  do iparam = 1, nset
179  do ip = 1, size(this%mf6_input%param_dfns)
180  idt => this%mf6_input%param_dfns(ip)
181  if (idt%tagname == cols(iparam)) then
182  this%idts(iparam)%idt => idt
183  end if
184  end do
185  end do
186 
187  if (allocated(cols)) deallocate (cols)
188  return
189  end function set_idts
190 
191  function set_oc_idts(this) result(nset)
194  class(settingloadtype), intent(inout) :: this
195  integer(I4B) :: nset
196  type(inputparamdefinitiontype), pointer :: idt, idt_ocaction
197  integer(I4B) :: nparam, ip
198 
199  ! generalize first kw field to a string
200  idt_ocaction => &
201  idt_default(this%mf6_input%component_type, &
202  this%mf6_input%subcomponent_type, &
203  'PERIOD', 'OCACTION', 'OCACTION', 'STRING')
204 
205  ! set 2 leading params
206  nset = 2
207 
208  ! allocate for 3 including ocsetting
209  nparam = nset + 1
210  allocate (this%idts(nparam))
211 
212  ! first generalized idt
213  this%idts(1)%idt => idt_ocaction
214 
215  ! set rtype idt
216  do ip = 1, size(this%mf6_input%param_dfns)
217  idt => this%mf6_input%param_dfns(ip)
218  if (idt%tagname == 'RTYPE') then
219  this%idts(2)%idt => idt
220  end if
221  end do
222  end function set_oc_idts
223 
224  subroutine destroy(this)
226  class(settingloadtype), intent(inout) :: this
227  integer(I4B) :: icol
228 
229  if (associated(this%structarray)) then
230  ! destroy the structured array reader
231  call destructstructarray(this%structarray)
232  end if
233 
234  do icol = 1, size(this%idts)
235  !deallocate (this%idts(icol)%idt)
236  nullify (this%idts(icol)%idt)
237  end do
238 
239  if (allocated(this%idts)) deallocate (this%idts)
240 
241  call this%DynamicPkgLoadType%destroy()
242  end subroutine destroy
243 
244 end module mf6filesettingloadmodule
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
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
This module contains the InputDefinitionModule.
This module defines variable data types.
Definition: kind.f90:8
This module contains the LoadContextModule.
Definition: LoadContext.f90:10
This module contains the LoadMf6FileModule.
Definition: LoadMf6File.f90:8
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.
Definition: ModflowInput.f90:9
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 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
base abstract type for ascii source dynamic load
derived type for boundary package input context
Definition: LoadContext.f90:61
Static parser based input loader.
Definition: LoadMf6File.f90:47
Pointer type for read state variable.
derived type for storing input definition for a file
type for structured array
Definition: StructArray.f90:36