MODFLOW 6  version 6.9.0.dev0
USGS Modular Hydrologic Model
mf6bmiError.f90
Go to the documentation of this file.
1 !> @brief Detailed error information for the BMI
2 !!
3 !! This module contains error codes and detailed error
4 !! messages (as format strings) for the BMI/XMI.
5 !<
6 module mf6bmierror
7  use iso_c_binding, only: c_char, c_int, c_null_char
8  use kindmodule, only: i4b
9  use constantsmodule, only: maxcharlen
10  use simvariablesmodule, only: istdout
11 
12  integer, parameter :: bmi_failure = 1 !< BMI status code for failure (taken from bmi.f90, CSDMS)
13  integer, parameter :: bmi_success = 0 !< BMI status code for success (taken from bmi.f90, CSDMS)
14 
15  integer(I4B), parameter :: lenerrmessage = 1024 !< max length for the error message
16  integer(c_int), bind(C, name="BMI_LENERRMESSAGE") :: bmi_lenerrmessage = &
17  lenerrmessage + 1 !< max. length for the (exported) C-style error message
18  !DIR$ ATTRIBUTES DLLEXPORT :: BMI_LENERRMESSAGE
19 
20  character(len=LENERRMESSAGE) :: bmi_last_error = 'No BMI error reported' !< module variable containing the last error as a Fortran string
21 
22  character(len=*), parameter :: fmt_general_err = & !< General bmi error, args: context/detail
23  "('BMI Error, ', a)"
24  character(len=*), parameter :: fmt_unknown_var = & !< Variable unknown, args: variable name, memory path
25  "('BMI Error, unknown variable: ', a, ' at ', a)"
26  character(len=*), parameter :: fmt_invalid_var = & !< Invalid variable address, args: variable address
27  "('BMI Error, invalid address string: ', a)"
28  character(len=*), parameter :: fmt_unsupported_rank = & !< Unsupported rank, args: variable name
29  "('BMI Error, unsupported rank for variable: &
30  &', a)"
31  character(len=*), parameter :: fmt_unsupported_type = & !< Unsupported type, args: variable name
32  "('BMI Error, unsupported type for variable: &
33  &', a)"
34  character(len=*), parameter :: fmt_invalid_mem_access = & !< Invalid memory access, args: variable name
35  "('Fatal BMI Error, invalid access of memory &
36  &for variable: ', a)"
37  character(len=*), parameter :: fmt_invalid_index = & !< Index out of range, args: index, variable name
38  "('BMI Error, index ', i0, &
39  &' out of range for variable: ', a)"
40  character(len=*), parameter :: fmt_invalid_time = & !< Time cannot be reached, args: time, detail
41  "('BMI Error, cannot update until time ', &
42  &g0, ', ', a)"
43  character(len=*), parameter :: fmt_fail_cvg_sol = & !< Solution failed to converge, args: detail
44  "('BMI Error, Numerical Solution ', i3, &
45  &' failed to converge')"
46 
47 contains
48 
49  !> @brief Sets the last BMI error message and copies
50  !! it to an exported C-string
51  !<
52  subroutine report_bmi_error(err_msg)
53  ! -- dummy variables
54  character(len=*), intent(in) :: err_msg !< the error message
55  bmi_last_error = err_msg
56  write (istdout, *) trim(err_msg)
57  end subroutine report_bmi_error
58 
59  !> @brief Get the last error in the BMI as a character array
60  !! with size BMI_LENERRMESSAGE
61  !<
62  function get_last_bmi_error(c_error) result(bmi_status) &
63  bind(C, name="get_last_bmi_error")
64  !DIR$ ATTRIBUTES DLLEXPORT :: get_last_bmi_error
65  ! -- dummy variables
66  character(kind=c_char, len=1), intent(out) :: c_error(bmi_lenerrmessage) !< C style char array with error
67  integer(kind=c_int) :: bmi_status !< BMI status code
68  ! -- local variables
69  integer(I4B) :: i, length
70 
71  length = len(trim(bmi_last_error))
72  do i = 1, length
73  c_error(i) = bmi_last_error(i:i)
74  end do
75  c_error(length + 1) = c_null_char
76 
77  bmi_status = bmi_success
78  end function get_last_bmi_error
79 
80 end module mf6bmierror
This module contains simulation constants.
Definition: Constants.f90:9
integer(i4b), parameter maxcharlen
maximum length of char string
Definition: Constants.f90:47
This module defines variable data types.
Definition: kind.f90:8
Detailed error information for the BMI.
Definition: mf6bmiError.f90:6
character(len= *), parameter fmt_invalid_var
Definition: mf6bmiError.f90:26
character(len= *), parameter fmt_unknown_var
Definition: mf6bmiError.f90:24
character(len= *), parameter fmt_general_err
Definition: mf6bmiError.f90:22
integer(i4b), parameter lenerrmessage
max length for the error message
Definition: mf6bmiError.f90:15
integer, parameter bmi_failure
BMI status code for failure (taken from bmi.f90, CSDMS)
Definition: mf6bmiError.f90:12
integer(kind=c_int) function get_last_bmi_error(c_error)
Get the last error in the BMI as a character array with size BMI_LENERRMESSAGE.
Definition: mf6bmiError.f90:64
character(len= *), parameter fmt_unsupported_type
Definition: mf6bmiError.f90:31
character(len= *), parameter fmt_invalid_time
Definition: mf6bmiError.f90:40
character(len=lenerrmessage) bmi_last_error
module variable containing the last error as a Fortran string
Definition: mf6bmiError.f90:20
character(len= *), parameter fmt_invalid_index
Definition: mf6bmiError.f90:37
subroutine report_bmi_error(err_msg)
Sets the last BMI error message and copies it to an exported C-string.
Definition: mf6bmiError.f90:53
character(len= *), parameter fmt_invalid_mem_access
Definition: mf6bmiError.f90:34
character(len= *), parameter fmt_fail_cvg_sol
Definition: mf6bmiError.f90:43
integer(c_int), bind(C, name="BMI_LENERRMESSAGE") bmi_lenerrmessage
max. length for the (exported) C-style error message
Definition: mf6bmiError.f90:16
character(len= *), parameter fmt_unsupported_rank
Definition: mf6bmiError.f90:28
integer, parameter bmi_success
BMI status code for success (taken from bmi.f90, CSDMS)
Definition: mf6bmiError.f90:13
This module contains simulation variables.
Definition: SimVariables.f90:9
integer(i4b) istdout
unit number for stdout