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...
 
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 142 of file mf6bmiUtil.f90.

143  ! -- dummy variables
144  integer(c_int), intent(in) :: length !< string length without terminating null character
145  character(c_char), intent(in) :: char_array(length) !< string to convert
146  character(len=length) :: f_string !< Fortran fixed length character string
147  ! -- local variables
148  integer(I4B) :: i
149 
150  do i = 1, length
151  f_string(i:i) = char_array(i)
152  end do
153 
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 101 of file mf6bmiUtil.f90.

102  ! -- modules
104  use memorytypemodule, only: memorytype
105  ! -- dummy variables
106  character(len=LENMEMPATH), intent(in) :: mem_path !< memory path used by the memory manager
107  character(len=LENVARNAME), intent(in) :: var_name !< name of the variable
108  logical(LGP), intent(out) :: found !< true when found
109  ! -- local variables
110  type(MemoryType), pointer :: mt
111 
112  found = .false.
113  mt => null()
114 
115  ! check = false: otherwise stop is called when the variable does not exist
116  call get_from_memorystore(var_name, mem_path, mt, found, check=.false.)
117 
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 270 of file mf6bmiUtil.f90.

271  ! -- dummy variables
272  integer(kind=c_int), intent(in) :: grid_id
273  character(len=*), intent(in) :: expected_type
274  logical :: is_match
275  ! -- local variables
276  character(len=LENMODELNAME) :: model_name
277  character(len=LENGRIDTYPE) :: grid_type
278 
279  is_match = .false.
280 
281  model_name = get_model_name(grid_id)
282  call get_grid_type_model(model_name, grid_type)
283  ! careful comparison:
284  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 175 of file mf6bmiUtil.f90.

176  ! -- dummy variables
177  character(len=*), intent(in) :: var_address !< the memory address for the variable
178  character(len=LENMODELNAME) :: model_name !< the extracted model name
179  logical(LGP), intent(out) :: success
180  ! -- local variables
181  character(len=LENMEMPATH) :: mem_path
182  character(len=LENCOMPONENTNAME) :: dummy_component
183  character(len=LENVARNAME) :: var_name
184  logical(LGP) :: split_succeeded
185 
186  success = .false.
187 
188  call split_mem_address(var_address, mem_path, var_name, split_succeeded)
189  if (.not. split_succeeded) then
190  return
191  end if
192 
193  call split_mem_path(mem_path, model_name, dummy_component)
194  success = .true.
195 
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 248 of file mf6bmiUtil.f90.

249  ! -- modules
250  use listsmodule, only: basemodellist
252  ! -- dummy variables
253  character(len=LENMODELNAME) :: model_name
254  character(len=LENGRIDTYPE) :: grid_type_f
255  ! -- local variables
256  integer(I4B) :: i
257  class(BaseModelType), pointer :: baseModel
258 
259  do i = 1, basemodellist%Count()
260  basemodel => getbasemodelfromlist(basemodellist, i)
261  if (basemodel%name == model_name) then
262  call basemodel%dis%get_dis_type(grid_type_f)
263  return
264  end if
265  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 200 of file mf6bmiUtil.f90.

201  ! -- modules
202  use listsmodule, only: basemodellist
204  ! -- dummy variables
205  integer(kind=c_int), intent(in) :: grid_id !< grid id
206  character(len=LENMODELNAME) :: model_name !< model name
207  ! -- local variables
208  integer(I4B) :: i
209  class(BaseModelType), pointer :: baseModel
210  character(len=LINELENGTH) :: error_msg
211 
212  model_name = ''
213 
214  do i = 1, basemodellist%Count()
215  basemodel => getbasemodelfromlist(basemodellist, i)
216  if (basemodel%id == grid_id) then
217  model_name = basemodel%name
218  return
219  end if
220  end do
221 
222  write (error_msg, '(a,i0)') 'BMI error: no model for grid id ', grid_id
223  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 228 of file mf6bmiUtil.f90.

229  ! -- modules
233  ! -- dummy variables
234  integer(I4B), intent(in) :: subcomponent_idx !< index of solution
235  class(BaseSolutionType), pointer :: solution !< Base Solution
236  ! -- local variables
237  class(SolutionGroupType), pointer :: sgp
238  integer(I4B) :: solutionIdx
239 
240  ! this is equivalent to how it's done in sgp_ca
242  solutionidx = sgp%idsolutions(subcomponent_idx)
243  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  success = .true.
96 
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 158 of file mf6bmiUtil.f90.

159  ! -- dummy variables
160  integer(c_int), intent(in) :: length !< Fortran string length
161  character(len=length), intent(in) :: string !< string to convert
162  character(kind=c_char, len=1) :: c_array(length + 1) !< C-style character string
163  ! -- local variables
164  integer(I4B) :: i
165 
166  do i = 1, length
167  c_array(i) = string(i:i)
168  end do
169  c_array(length + 1) = c_null_char
170 
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 122 of file mf6bmiUtil.f90.

123  ! -- dummy variables
124  integer(I4B), intent(in) :: max_len
125  character(c_char), intent(in) :: char_array(max_len) !< C-style character string
126  integer(I4B) :: string_length !< Fortran string length
127  ! -- local variables
128  integer(I4B) :: i
129 
130  string_length = 0
131  do i = 1, size(char_array)
132  if (char_array(i) .eq. c_null_char) then
133  string_length = i - 1
134  exit
135  end if
136  end do
137 
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