MODFLOW 6  version 6.5.0.dev2
MODFLOW 6 Code Documentation
DefinitionSelect.f90
Go to the documentation of this file.
1 !> @brief This module contains the DefinitionSelectModule
2 !!
3 !! This module contains the routines for getting parameter
4 !! definitions, aggregate definitions, and block definitions
5 !! for the different package types.
6 !!
7 !<
9 
10  use kindmodule, only: i4b
11  use simvariablesmodule, only: errmsg
15 
16  implicit none
17  private
20  public :: split_record_definition
21  public :: idt_parse_rectype
22  public :: idt_datatype
23 
24 contains
25 
26  !> @brief allocate and set RECARRAY, KEYSTRING or RECORD param list
27  !<
28  subroutine idt_parse_rectype(idt, cols, ncol)
29  ! -- modules
30  use constantsmodule, only: linelength
31  use inputoutputmodule, only: parseline
32  ! -- dummy
33  type(inputparamdefinitiontype), pointer, intent(in) :: idt
34  character(len=LINELENGTH), dimension(:), allocatable, &
35  intent(inout) :: cols
36  integer(I4B), intent(inout) :: ncol
37  ! -- local
38  character(len=:), allocatable :: parse_str
39  character(len=LINELENGTH), dimension(:), allocatable :: param_cols
40  integer(I4B) :: param_ncol, n
41  !
42  ! -- initialize
43  if (allocated(cols)) deallocate (cols)
44  ncol = 0
45  !
46  ! -- split definition
47  parse_str = trim(idt%datatype)//' '
48  call parseline(parse_str, param_ncol, param_cols)
49  !
50  if (param_ncol > 1) then
51  if (param_cols(1) == 'RECARRAY' .or. &
52  param_cols(1) == 'KEYSTRING' .or. &
53  param_cols(1) == 'RECORD') then
54  ! -- exclude 1st column
55  allocate (cols(param_ncol - 1))
56  do n = 2, param_ncol
57  cols(n - 1) = param_cols(n)
58  end do
59  !
60  ! -- set ncol
61  ncol = param_ncol - 1
62  end if
63  end if
64  !
65  ! -- cleanup
66  if (allocated(param_cols)) deallocate (param_cols)
67  if (allocated(parse_str)) deallocate (parse_str)
68  !
69  ! -- return
70  return
71  end subroutine idt_parse_rectype
72 
73  !> @brief return input definition type datatype
74  !<
75  function idt_datatype(idt) result(datatype)
76  ! -- modules
77  use constantsmodule, only: linelength
78  ! -- dummy
79  type(inputparamdefinitiontype), pointer, intent(in) :: idt
80  ! -- result
81  character(len=LINELENGTH) :: datatype
82  !
83  if (idt%datatype(1:9) == 'KEYSTRING') then
84  datatype = 'KEYSTRING'
85  else if (idt%datatype(1:8) == 'RECARRAY') then
86  datatype = 'RECARRAY'
87  else if (idt%datatype(1:6) == 'RECORD') then
88  datatype = 'RECORD'
89  else
90  datatype = idt%datatype
91  end if
92  !
93  ! -- return
94  return
95  end function idt_datatype
96 
97  !> @brief Return parameter definition
98  !<
99  function get_param_definition_type(input_definition_types, &
100  component_type, subcomponent_type, &
101  blockname, tagname, filename) &
102  result(idt)
103  type(inputparamdefinitiontype), dimension(:), intent(in), target :: &
104  input_definition_types
105  character(len=*), intent(in) :: component_type !< component type, such as GWF or GWT
106  character(len=*), intent(in) :: subcomponent_type !< subcomponent type, such as DIS or NPF
107  character(len=*), intent(in) :: blockname !< name of the block
108  character(len=*), intent(in) :: tagname !< name of the input tag
109  character(len=*), intent(in) :: filename !< input filename
110  type(inputparamdefinitiontype), pointer :: idt !< corresponding InputParameterDefinitionType for this tag
111  type(inputparamdefinitiontype), pointer :: tmp_ptr
112  integer(I4B) :: i
113  !
114  nullify (idt)
115  do i = 1, size(input_definition_types)
116  tmp_ptr => input_definition_types(i)
117  if (tmp_ptr%component_type == component_type .and. &
118  tmp_ptr%subcomponent_type == subcomponent_type .and. &
119  tmp_ptr%blockname == blockname .and. &
120  tmp_ptr%tagname == tagname) then
121  idt => input_definition_types(i)
122  exit
123  end if
124  end do
125  !
126  if (.not. associated(idt)) then
127  write (errmsg, '(a,a,a,a,a)') &
128  'Input file tag not found: "', trim(tagname), &
129  '" in block "', trim(blockname), &
130  '".'
131  call store_error(errmsg)
132  call store_error_filename(filename)
133  end if
134  !
135  ! -- return
136  return
137  end function get_param_definition_type
138 
139  !> @brief Return aggregate definition
140  !<
141  function get_aggregate_definition_type(input_definition_types, component_type, &
142  subcomponent_type, blockname) result(idt)
143  type(inputparamdefinitiontype), dimension(:), intent(in), target :: &
144  input_definition_types
145  character(len=*), intent(in) :: component_type !< component type, such as GWF or GWT
146  character(len=*), intent(in) :: subcomponent_type !< subcomponent type, such as DIS or NPF
147  character(len=*), intent(in) :: blockname !< name of the block
148  type(inputparamdefinitiontype), pointer :: idt !< corresponding InputParameterDefinitionType for this block
149  type(inputparamdefinitiontype), pointer :: tmp_ptr
150  integer(I4B) :: i
151  !
152  nullify (idt)
153  do i = 1, size(input_definition_types)
154  tmp_ptr => input_definition_types(i)
155  if (tmp_ptr%component_type == component_type .and. &
156  tmp_ptr%subcomponent_type == subcomponent_type .and. &
157  tmp_ptr%blockname == blockname) then
158  idt => input_definition_types(i)
159  exit
160  end if
161  end do
162  !
163  if (.not. associated(idt)) then
164  write (errmsg, '(a,a,a,a,a,a,a)') &
165  'Idm aggregate definition not found: ', trim(blockname), &
166  '. Component="', trim(component_type), &
167  '", subcomponent="', trim(subcomponent_type), '".'
168  call store_error(errmsg, .true.)
169  end if
170  !
171  ! -- return
172  return
173  end function get_aggregate_definition_type
174 
175  !> @brief Return aggregate definition
176  !!
177  !! Split a component RECORD datatype definition whose second element matches
178  !! tagname into an array of character tokens
179  !<
180  subroutine split_record_definition(input_definition_types, component_type, &
181  subcomponent_type, tagname, nwords, words)
182  use inputoutputmodule, only: parseline
183  type(inputparamdefinitiontype), dimension(:), intent(in), target :: &
184  input_definition_types
185  character(len=*), intent(in) :: component_type !< component type, such as GWF or GWT
186  character(len=*), intent(in) :: subcomponent_type !< subcomponent type, such as DIS or NPF
187  character(len=*), intent(in) :: tagname !< name of the input tag
188  integer(I4B), intent(inout) :: nwords
189  character(len=40), dimension(:), allocatable, intent(inout) :: words
190  type(inputparamdefinitiontype), pointer :: tmp_ptr
191  integer(I4B) :: i
192  character(len=:), allocatable :: parse_str
193  !
194  ! -- initialize to deallocated
195  if (allocated(words)) deallocate (words)
196  !
197  ! -- return all tokens of multi-record type that matches the first
198  ! -- tag following the expected first token "RECORD"
199  do i = 1, size(input_definition_types)
200  !
201  ! -- initialize
202  nwords = 0
203  !
204  ! -- set ptr to current definition
205  tmp_ptr => input_definition_types(i)
206  !
207  ! -- match for definition to split
208  if (tmp_ptr%component_type == component_type .and. &
209  tmp_ptr%subcomponent_type == subcomponent_type .and. &
210  idt_datatype(tmp_ptr) == 'RECORD') then
211  !
212  ! -- set split string
213  parse_str = trim(input_definition_types(i)%datatype)//' '
214  !
215  ! -- split
216  call parseline(parse_str, nwords, words)
217  !
218  ! -- check for match and manage memory
219  if (nwords >= 2) then
220  if (words(1) == 'RECORD' .and. words(2) == tagname) then
221  exit
222  end if
223  end if
224  !
225  ! -- deallocate
226  if (allocated(parse_str)) deallocate (parse_str)
227  if (allocated(words)) deallocate (words)
228  !
229  end if
230  end do
231  end subroutine split_record_definition
232 
233 end module definitionselectmodule
This module contains simulation constants.
Definition: Constants.f90:9
integer(i4b), parameter linelength
maximum length of a standard line
Definition: Constants.f90:44
This module contains the DefinitionSelectModule.
type(inputparamdefinitiontype) function, pointer, public get_param_definition_type(input_definition_types, component_type, subcomponent_type, blockname, tagname, filename)
Return parameter definition.
subroutine, public split_record_definition(input_definition_types, component_type, subcomponent_type, tagname, nwords, words)
Return aggregate definition.
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
character(len=linelength) function, public idt_datatype(idt)
return input definition type datatype
This module contains the InputDefinitionModule.
subroutine, public parseline(line, nwords, words, inunit, filename)
Parse a line into words.
This module defines variable data types.
Definition: kind.f90:8
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 simulation variables.
Definition: SimVariables.f90:9
character(len=maxcharlen) errmsg
error message string