MODFLOW 6  version 6.6.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(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_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 132 of file mf6bmiUtil.f90.

133  ! -- dummy variables
134  integer(c_int), intent(in) :: length !< string length without terminating null character
135  character(c_char), intent(in) :: char_array(length) !< string to convert
136  character(len=length) :: f_string !< Fortran fixed length character string
137  ! -- local variables
138  integer(I4B) :: i
139 
140  do i = 1, length
141  f_string(i:i) = char_array(i)
142  end do
143 
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 91 of file mf6bmiUtil.f90.

92  ! -- modules
94  use memorytypemodule, only: memorytype
95  ! -- dummy variables
96  character(len=LENMEMPATH), intent(in) :: mem_path !< memory path used by the memory manager
97  character(len=LENVARNAME), intent(in) :: var_name !< name of the variable
98  logical(LGP), intent(out) :: found !< true when found
99  ! -- local variables
100  type(MemoryType), pointer :: mt
101 
102  found = .false.
103  mt => null()
104 
105  ! check = false: otherwise stop is called when the variable does not exist
106  call get_from_memorystore(var_name, mem_path, mt, found, check=.false.)
107 
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 259 of file mf6bmiUtil.f90.

260  ! -- dummy variables
261  integer(kind=c_int), intent(in) :: grid_id
262  character(len=*), intent(in) :: expected_type
263  logical :: is_match
264  ! -- local variables
265  character(len=LENMODELNAME) :: model_name
266  character(len=LENGRIDTYPE) :: grid_type
267 
268  is_match = .false.
269 
270  model_name = get_model_name(grid_id)
271  call get_grid_type_model(model_name, grid_type)
272  ! careful comparison:
273  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 165 of file mf6bmiUtil.f90.

166  ! -- dummy variables
167  character(len=*), intent(in) :: var_address !< the memory address for the variable
168  character(len=LENMODELNAME) :: model_name !< the extracted model name
169  logical(LGP), intent(out) :: success
170  ! -- local variables
171  character(len=LENMEMPATH) :: mem_path
172  character(len=LENCOMPONENTNAME) :: dummy_component
173  character(len=LENVARNAME) :: var_name
174  logical(LGP) :: split_succeeded
175 
176  success = .false.
177 
178  call split_mem_address(var_address, mem_path, var_name, split_succeeded)
179  if (.not. split_succeeded) then
180  return
181  end if
182 
183  call split_mem_path(mem_path, model_name, dummy_component)
184  success = .true.
185 
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 238 of file mf6bmiUtil.f90.

239  ! -- modules
240  use listsmodule, only: basemodellist
242  ! -- dummy variables
243  character(len=LENMODELNAME) :: model_name
244  character(len=LENGRIDTYPE) :: grid_type_f
245  ! -- local variables
246  integer(I4B) :: i
247  class(NumericalModelType), pointer :: numericalModel
248 
249  do i = 1, basemodellist%Count()
250  numericalmodel => getnumericalmodelfromlist(basemodellist, i)
251  if (numericalmodel%name == model_name) then
252  call numericalmodel%dis%get_dis_type(grid_type_f)
253  end if
254  end do
type(listtype), public basemodellist
Definition: mf6lists.f90:16
class(numericalmodeltype) function, pointer, public getnumericalmodelfromlist(list, idx)
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 190 of file mf6bmiUtil.f90.

191  ! -- modules
192  use listsmodule, only: basemodellist
194  ! -- dummy variables
195  integer(kind=c_int), intent(in) :: grid_id !< grid id
196  character(len=LENMODELNAME) :: model_name !< model name
197  ! -- local variables
198  integer(I4B) :: i
199  class(BaseModelType), pointer :: baseModel
200  character(len=LINELENGTH) :: error_msg
201 
202  model_name = ''
203 
204  do i = 1, basemodellist%Count()
205  basemodel => getbasemodelfromlist(basemodellist, i)
206  if (basemodel%id == grid_id) then
207  model_name = basemodel%name
208  return
209  end if
210  end do
211 
212  write (error_msg, '(a,i0)') 'BMI error: no model for grid id ', grid_id
213  call write_message(error_msg, iunit=istdout, skipbefore=1, skipafter=1)
class(basemodeltype) function, pointer, public getbasemodelfromlist(list, idx)
Definition: BaseModel.f90:172
Highest level model type. All models extend this parent type.
Definition: BaseModel.f90:13
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 218 of file mf6bmiUtil.f90.

219  ! -- modules
223  ! -- dummy variables
224  integer(I4B), intent(in) :: subcomponent_idx !< index of solution
225  class(BaseSolutionType), pointer :: solution !< Base Solution
226  ! -- local variables
227  class(SolutionGroupType), pointer :: sgp
228  integer(I4B) :: solutionIdx
229 
230  ! this is equivalent to how it's done in sgp_ca
232  solutionidx = sgp%idsolutions(subcomponent_idx)
233  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 53 of file mf6bmiUtil.f90.

54  ! -- modules
56  ! -- dummy variables
57  character(kind=c_char), intent(in) :: c_var_address(*) !< full address of a variable
58  character(len=LENMEMPATH), intent(out) :: mem_path !< memory path used by the memory manager
59  character(len=LENVARNAME), intent(out) :: var_name !< name of the variable
60  logical(LGP), intent(out) :: success !< false when invalid
61  ! -- local variables
62  character(len=LENMEMADDRESS) :: var_address
63  logical(LGP) :: valid, found
64 
65  success = .false.
66 
67  ! try and split the address string:
68  var_address = char_array_to_string(c_var_address, &
69  strlen(c_var_address, lenmemaddress + 1))
70  call split_mem_address(var_address, mem_path, var_name, valid)
71  if (.not. valid) then
72  write (bmi_last_error, fmt_invalid_var) trim(var_address)
73  call report_bmi_error(bmi_last_error)
74  return
75  end if
76 
77  ! check if the variable even exists:
78  call check_mem_address(mem_path, var_name, found)
79  if (.not. found) then
80  write (bmi_last_error, fmt_unknown_var) trim(var_name), trim(mem_path)
81  call report_bmi_error(bmi_last_error)
82  return
83  end if
84 
85  success = .true.
86 
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 148 of file mf6bmiUtil.f90.

149  ! -- dummy variables
150  integer(c_int), intent(in) :: length !< Fortran string length
151  character(len=length), intent(in) :: string !< string to convert
152  character(kind=c_char, len=1) :: c_array(length + 1) !< C-style character string
153  ! -- local variables
154  integer(I4B) :: i
155 
156  do i = 1, length
157  c_array(i) = string(i:i)
158  end do
159  c_array(length + 1) = c_null_char
160 
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 112 of file mf6bmiUtil.f90.

113  ! -- dummy variables
114  integer(I4B), intent(in) :: max_len
115  character(c_char), intent(in) :: char_array(max_len) !< C-style character string
116  integer(I4B) :: string_length !< Fortran string length
117  ! -- local variables
118  integer(I4B) :: i
119 
120  string_length = 0
121  do i = 1, size(char_array)
122  if (char_array(i) .eq. c_null_char) then
123  string_length = i - 1
124  exit
125  end if
126  end do
127 
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 38 of file mf6bmiUtil.f90.

38  integer(c_int), bind(C, name="BMI_LENCOMPONENTNAME") :: BMI_LENCOMPONENTNAME = &
39  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 30 of file mf6bmiUtil.f90.

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

◆ bmi_lenvaraddress

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

Definition at line 34 of file mf6bmiUtil.f90.

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

◆ bmi_lenvartype

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

Definition at line 26 of file mf6bmiUtil.f90.

26  integer(c_int), bind(C, name="BMI_LENVARTYPE") :: BMI_LENVARTYPE = &
27  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 42 of file mf6bmiUtil.f90.

42  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