MODFLOW 6  version 6.9.0.dev0
USGS Modular Hydrologic Model
mf6bmiutil Module Reference

This module contains helper routines and parameters for the MODFLOW 6 BMI.

Functions/Subroutines

subroutine split_address (c_var_address, mem_path, var_name, success)
 Split the variable address string. More...
 
subroutine check_mem_address (mem_path, var_name, found)
 Check if the variable exists in the memory manager. More...
 
subroutine warn_deprecated_address (mem_path, var_name)
 Store a warning the first time a deprecated variable name is used. More...
 
pure integer(i4b) function strlen (char_array, max_len)
 Returns the string length without the trailing null character. More...
 
pure character(len=length) function char_array_to_string (char_array, length)
 Convert C-style string to Fortran character string. More...
 
pure character(kind=c_char, len=1) function, dimension(length+1) string_to_char_array (string, length)
 Convert Fortran string to C-style character string. More...
 
character(len=lenmodelname) function extract_model_name (var_address, success)
 Extract the model name from a memory address string. More...
 
character(len=lenmodelname) function get_model_name (grid_id)
 Get the model name from the grid id. More...
 
class(basesolutiontype) function, pointer getsolution (subcomponent_idx)
 Get the solution object for this index. More...
 
subroutine get_grid_type_model (model_name, grid_type_f)
 Get the grid type for a named model as a fortran string. More...
 
logical function confirm_grid_type (grid_id, expected_type)
 Confirm that grid is of an expected type. More...
 

Variables

integer(i4b), parameter lengridtype = 16
 max length for Fortran grid type string More...
 
integer(i4b), parameter lenunits = 16
 max length for Fortran units string More...
 
integer(i4b), parameter lenvarlocation = 16
 max length for Fortran variable location string More...
 
integer(c_int), bind(C, name="BMI_LENVARTYPE") bmi_lenvartype = LENMEMTYPE + 1
 max. length for variable type C-strings More...
 
integer(c_int), bind(C, name="BMI_LENGRIDTYPE") bmi_lengridtype = LENGRIDTYPE + 1
 max. length for grid type C-strings More...
 
integer(c_int), bind(C, name="BMI_LENUNITS") bmi_lenunits = LENUNITS + 1
 max. length for units C-strings More...
 
integer(c_int), bind(C, name="BMI_LENVARLOCATION") bmi_lenvarlocation = LENVARLOCATION + 1
 max. length for variable location C-strings More...
 
integer(c_int), bind(C, name="BMI_LENVARADDRESS") bmi_lenvaraddress = LENMEMADDRESS + 1
 max. length for the variable's address C-string More...
 
integer(c_int), bind(C, name="BMI_LENCOMPONENTNAME") bmi_lencomponentname = 256
 component name length, i.e. 'MODFLOW 6' More...
 
integer(c_int), bind(C, name="BMI_LENVERSION") bmi_lenversion = 256
 length of version string, e.g. '6.3.1' or '6.4.1-dev' More...
 

Function/Subroutine Documentation

◆ char_array_to_string()

pure character(len=length) function mf6bmiutil::char_array_to_string ( character(c_char), dimension(length), intent(in)  char_array,
integer(c_int), intent(in)  length 
)
Parameters
[in]lengthstring length without terminating null character
[in]char_arraystring to convert
Returns
Fortran fixed length character string

Definition at line 171 of file mf6bmiUtil.f90.

172  ! -- dummy variables
173  integer(c_int), intent(in) :: length !< string length without terminating null character
174  character(c_char), intent(in) :: char_array(length) !< string to convert
175  character(len=length) :: f_string !< Fortran fixed length character string
176  ! -- local variables
177  integer(I4B) :: i
178 
179  do i = 1, length
180  f_string(i:i) = char_array(i)
181  end do
182 
Here is the caller graph for this function:

◆ check_mem_address()

subroutine mf6bmiutil::check_mem_address ( character(len=lenmempath), intent(in)  mem_path,
character(len=lenvarname), intent(in)  var_name,
logical(lgp), intent(out)  found 
)
Parameters
[in]mem_pathmemory path used by the memory manager
[in]var_namename of the variable
[out]foundtrue when found

Definition at line 104 of file mf6bmiUtil.f90.

105  ! -- modules
107  use memorytypemodule, only: memorytype
108  ! -- dummy variables
109  character(len=LENMEMPATH), intent(in) :: mem_path !< memory path used by the memory manager
110  character(len=LENVARNAME), intent(in) :: var_name !< name of the variable
111  logical(LGP), intent(out) :: found !< true when found
112  ! -- local variables
113  type(MemoryType), pointer :: mt
114 
115  found = .false.
116  mt => null()
117 
118  ! check = false: otherwise stop is called when the variable does not exist
119  call get_from_memorystore(var_name, mem_path, mt, found, check=.false.)
120 
subroutine, public get_from_memorystore(name, mem_path, mt, found, check)
@ brief Get a memory type entry from the memory list
Here is the call graph for this function:
Here is the caller graph for this function:

◆ confirm_grid_type()

logical function mf6bmiutil::confirm_grid_type ( integer(kind=c_int), intent(in)  grid_id,
character(len=*), intent(in)  expected_type 
)

Definition at line 299 of file mf6bmiUtil.f90.

300  ! -- dummy variables
301  integer(kind=c_int), intent(in) :: grid_id
302  character(len=*), intent(in) :: expected_type
303  logical :: is_match
304  ! -- local variables
305  character(len=LENMODELNAME) :: model_name
306  character(len=LENGRIDTYPE) :: grid_type
307 
308  is_match = .false.
309 
310  model_name = get_model_name(grid_id)
311  call get_grid_type_model(model_name, grid_type)
312  ! careful comparison:
313  if (expected_type == grid_type) is_match = .true.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ extract_model_name()

character(len=lenmodelname) function mf6bmiutil::extract_model_name ( character(len=*), intent(in)  var_address,
logical(lgp), intent(out)  success 
)
Parameters
[in]var_addressthe memory address for the variable
Returns
the extracted model name

Definition at line 204 of file mf6bmiUtil.f90.

205  ! -- dummy variables
206  character(len=*), intent(in) :: var_address !< the memory address for the variable
207  character(len=LENMODELNAME) :: model_name !< the extracted model name
208  logical(LGP), intent(out) :: success
209  ! -- local variables
210  character(len=LENMEMPATH) :: mem_path
211  character(len=LENCOMPONENTNAME) :: dummy_component
212  character(len=LENVARNAME) :: var_name
213  logical(LGP) :: split_succeeded
214 
215  success = .false.
216 
217  call split_mem_address(var_address, mem_path, var_name, split_succeeded)
218  if (.not. split_succeeded) then
219  return
220  end if
221 
222  call split_mem_path(mem_path, model_name, dummy_component)
223  success = .true.
224 
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_grid_type_model()

subroutine mf6bmiutil::get_grid_type_model ( character(len=lenmodelname)  model_name,
character(len=lengridtype)  grid_type_f 
)

Definition at line 277 of file mf6bmiUtil.f90.

278  ! -- modules
279  use listsmodule, only: basemodellist
281  ! -- dummy variables
282  character(len=LENMODELNAME) :: model_name
283  character(len=LENGRIDTYPE) :: grid_type_f
284  ! -- local variables
285  integer(I4B) :: i
286  class(BaseModelType), pointer :: baseModel
287 
288  do i = 1, basemodellist%Count()
289  basemodel => getbasemodelfromlist(basemodellist, i)
290  if (basemodel%name == model_name) then
291  call basemodel%dis%get_dis_type(grid_type_f)
292  return
293  end if
294  end do
class(basemodeltype) function, pointer, public getbasemodelfromlist(list, idx)
Definition: BaseModel.f90:171
type(listtype), public basemodellist
Definition: mf6lists.f90:16
Highest level model type. All models extend this parent type.
Definition: BaseModel.f90:16
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_model_name()

character(len=lenmodelname) function mf6bmiutil::get_model_name ( integer(kind=c_int), intent(in)  grid_id)
Parameters
[in]grid_idgrid id
Returns
model name

Definition at line 229 of file mf6bmiUtil.f90.

230  ! -- modules
231  use listsmodule, only: basemodellist
233  ! -- dummy variables
234  integer(kind=c_int), intent(in) :: grid_id !< grid id
235  character(len=LENMODELNAME) :: model_name !< model name
236  ! -- local variables
237  integer(I4B) :: i
238  class(BaseModelType), pointer :: baseModel
239  character(len=LINELENGTH) :: error_msg
240 
241  model_name = ''
242 
243  do i = 1, basemodellist%Count()
244  basemodel => getbasemodelfromlist(basemodellist, i)
245  if (basemodel%id == grid_id) then
246  model_name = basemodel%name
247  return
248  end if
249  end do
250 
251  write (error_msg, '(a,i0)') 'BMI error: no model for grid id ', grid_id
252  call write_message(error_msg, iunit=istdout, skipbefore=1, skipafter=1)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getsolution()

class(basesolutiontype) function, pointer mf6bmiutil::getsolution ( integer(i4b), intent(in)  subcomponent_idx)
Parameters
[in]subcomponent_idxindex of solution
Returns
Base Solution

Definition at line 257 of file mf6bmiUtil.f90.

258  ! -- modules
262  ! -- dummy variables
263  integer(I4B), intent(in) :: subcomponent_idx !< index of solution
264  class(BaseSolutionType), pointer :: solution !< Base Solution
265  ! -- local variables
266  class(SolutionGroupType), pointer :: sgp
267  integer(I4B) :: solutionIdx
268 
269  ! this is equivalent to how it's done in sgp_ca
271  solutionidx = sgp%idsolutions(subcomponent_idx)
272  solution => getbasesolutionfromlist(basesolutionlist, solutionidx)
class(basesolutiontype) function, pointer, public getbasesolutionfromlist(list, idx)
type(listtype), public solutiongrouplist
Definition: mf6lists.f90:22
type(listtype), public basesolutionlist
Definition: mf6lists.f90:19
class(solutiongrouptype) function, pointer, public getsolutiongroupfromlist(list, idx)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ split_address()

subroutine mf6bmiutil::split_address ( character(kind=c_char), dimension(*), intent(in)  c_var_address,
character(len=lenmempath), intent(out)  mem_path,
character(len=lenvarname), intent(out)  var_name,
logical(lgp), intent(out)  success 
)

Splits the full address string into a memory path and variable name, following the rules used by the memory manager. The error handling is inside to avoid lots of duplication

Parameters
[in]c_var_addressfull address of a variable
[out]mem_pathmemory path used by the memory manager
[out]var_namename of the variable
[out]successfalse when invalid

Definition at line 63 of file mf6bmiUtil.f90.

64  ! -- modules
66  ! -- dummy variables
67  character(kind=c_char), intent(in) :: c_var_address(*) !< full address of a variable
68  character(len=LENMEMPATH), intent(out) :: mem_path !< memory path used by the memory manager
69  character(len=LENVARNAME), intent(out) :: var_name !< name of the variable
70  logical(LGP), intent(out) :: success !< false when invalid
71  ! -- local variables
72  character(len=LENMEMADDRESS) :: var_address
73  logical(LGP) :: valid, found
74 
75  success = .false.
76 
77  ! try and split the address string:
78  var_address = char_array_to_string(c_var_address, &
79  strlen(c_var_address, lenmemaddress + 1))
80  call split_mem_address(var_address, mem_path, var_name, valid)
81  if (.not. valid) then
82  write (bmi_last_error, fmt_invalid_var) trim(var_address)
83  call report_bmi_error(bmi_last_error)
84  return
85  end if
86 
87  ! check if the variable even exists:
88  call check_mem_address(mem_path, var_name, found)
89  if (.not. found) then
90  write (bmi_last_error, fmt_unknown_var) trim(var_name), trim(mem_path)
91  call report_bmi_error(bmi_last_error)
92  return
93  end if
94 
95  ! warn if the variable is addressed by a deprecated name
96  call warn_deprecated_address(mem_path, var_name)
97 
98  success = .true.
99 
character(len=lenmemseparator), parameter mempathseparator
used to build up the memory address for the stored variables
Here is the call graph for this function:
Here is the caller graph for this function:

◆ string_to_char_array()

pure character(kind=c_char, len=1) function, dimension(length + 1) mf6bmiutil::string_to_char_array ( character(len=length), intent(in)  string,
integer(c_int), intent(in)  length 
)
Parameters
[in]lengthFortran string length
[in]stringstring to convert
Returns
C-style character string

Definition at line 187 of file mf6bmiUtil.f90.

188  ! -- dummy variables
189  integer(c_int), intent(in) :: length !< Fortran string length
190  character(len=length), intent(in) :: string !< string to convert
191  character(kind=c_char, len=1) :: c_array(length + 1) !< C-style character string
192  ! -- local variables
193  integer(I4B) :: i
194 
195  do i = 1, length
196  c_array(i) = string(i:i)
197  end do
198  c_array(length + 1) = c_null_char
199 
Here is the caller graph for this function:

◆ strlen()

pure integer(i4b) function mf6bmiutil::strlen ( character(c_char), dimension(max_len), intent(in)  char_array,
integer(i4b), intent(in)  max_len 
)
Parameters
[in]char_arrayC-style character string
Returns
Fortran string length

Definition at line 151 of file mf6bmiUtil.f90.

152  ! -- dummy variables
153  integer(I4B), intent(in) :: max_len
154  character(c_char), intent(in) :: char_array(max_len) !< C-style character string
155  integer(I4B) :: string_length !< Fortran string length
156  ! -- local variables
157  integer(I4B) :: i
158 
159  string_length = 0
160  do i = 1, size(char_array)
161  if (char_array(i) .eq. c_null_char) then
162  string_length = i - 1
163  exit
164  end if
165  end do
166 
Here is the caller graph for this function:

◆ warn_deprecated_address()

subroutine mf6bmiutil::warn_deprecated_address ( character(len=lenmempath), intent(in)  mem_path,
character(len=lenvarname), intent(in)  var_name 
)
Parameters
[in]mem_pathmemory path used by the memory manager
[in]var_namename of the variable

Definition at line 125 of file mf6bmiUtil.f90.

126  ! -- modules
128  use simmodule, only: store_warning
129  ! -- dummy variables
130  character(len=LENMEMPATH), intent(in) :: mem_path !< memory path used by the memory manager
131  character(len=LENVARNAME), intent(in) :: var_name !< name of the variable
132  ! -- local variables
133  logical(LGP) :: found
134  character(len=LENMEMADDRESS) :: replacement
135  character(len=LINELENGTH) :: version
136  character(len=MAXCHARLEN) :: msg
137 
138  call get_deprecated_alias(var_name, mem_path, found, replacement, version)
139  if (.not. found) return
140 
141  write (msg, '(a)') &
142  "API VARIABLE '"//trim(var_name)//"' IN '"//trim(mem_path)// &
143  "' WAS DEPRECATED IN VERSION "//trim(version)//". USE '"// &
144  trim(replacement)//"' INSTEAD."
145  call store_warning(trim(msg), substring=trim(msg))
146 
Previous variable names checked in as deprecated aliases.
Definition: MemoryAlias.f90:7
subroutine, public get_deprecated_alias(name, mem_path, found, replacement, version)
Get the replacement and version of a deprecated name.
This module contains simulation methods.
Definition: Sim.f90:10
subroutine, public store_warning(msg, substring)
Store warning message.
Definition: Sim.f90:237
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ bmi_lencomponentname

integer(c_int), bind(C, name="BMI_LENCOMPONENTNAME") mf6bmiutil::bmi_lencomponentname = 256

Definition at line 48 of file mf6bmiUtil.f90.

48  integer(c_int), bind(C, name="BMI_LENCOMPONENTNAME") :: BMI_LENCOMPONENTNAME = &
49  256 !< component name length, i.e. 'MODFLOW 6'

◆ bmi_lengridtype

integer(c_int), bind(C, name="BMI_LENGRIDTYPE") mf6bmiutil::bmi_lengridtype = LENGRIDTYPE + 1

Definition at line 32 of file mf6bmiUtil.f90.

32  integer(c_int), bind(C, name="BMI_LENGRIDTYPE") :: BMI_LENGRIDTYPE = &
33  lengridtype + 1 !< max. length for grid type C-strings

◆ bmi_lenunits

integer(c_int), bind(C, name="BMI_LENUNITS") mf6bmiutil::bmi_lenunits = LENUNITS + 1

Definition at line 36 of file mf6bmiUtil.f90.

36  integer(c_int), bind(C, name="BMI_LENUNITS") :: BMI_LENUNITS = &
37  lenunits + 1 !< max. length for units C-strings

◆ bmi_lenvaraddress

integer(c_int), bind(C, name="BMI_LENVARADDRESS") mf6bmiutil::bmi_lenvaraddress = LENMEMADDRESS + 1

Definition at line 44 of file mf6bmiUtil.f90.

44  integer(c_int), bind(C, name="BMI_LENVARADDRESS") :: BMI_LENVARADDRESS = &
45  lenmemaddress + 1 !< max. length for the variable's address C-string

◆ bmi_lenvarlocation

integer(c_int), bind(C, name="BMI_LENVARLOCATION") mf6bmiutil::bmi_lenvarlocation = LENVARLOCATION + 1

Definition at line 40 of file mf6bmiUtil.f90.

40  integer(c_int), bind(C, name="BMI_LENVARLOCATION") :: BMI_LENVARLOCATION = &
41  lenvarlocation + 1 !< max. length for variable location C-strings

◆ bmi_lenvartype

integer(c_int), bind(C, name="BMI_LENVARTYPE") mf6bmiutil::bmi_lenvartype = LENMEMTYPE + 1

Definition at line 28 of file mf6bmiUtil.f90.

28  integer(c_int), bind(C, name="BMI_LENVARTYPE") :: BMI_LENVARTYPE = &
29  lenmemtype + 1 !< max. length for variable type C-strings

◆ bmi_lenversion

integer(c_int), bind(C, name="BMI_LENVERSION") mf6bmiutil::bmi_lenversion = 256

Definition at line 52 of file mf6bmiUtil.f90.

52  integer(c_int), bind(C, name="BMI_LENVERSION") :: BMI_LENVERSION = 256 !< length of version string, e.g. '6.3.1' or '6.4.1-dev'

◆ lengridtype

integer(i4b), parameter mf6bmiutil::lengridtype = 16

Definition at line 24 of file mf6bmiUtil.f90.

24  integer(I4B), parameter :: LENGRIDTYPE = 16 !< max length for Fortran grid type string

◆ lenunits

integer(i4b), parameter mf6bmiutil::lenunits = 16

Definition at line 25 of file mf6bmiUtil.f90.

25  integer(I4B), parameter :: LENUNITS = 16 !< max length for Fortran units string

◆ lenvarlocation

integer(i4b), parameter mf6bmiutil::lenvarlocation = 16

Definition at line 26 of file mf6bmiUtil.f90.

26  integer(I4B), parameter :: LENVARLOCATION = 16 !< max length for Fortran variable location string