MODFLOW 6  version 6.7.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_fail_cvg_sol = & !< Solution failed to converge, args: detail
38  "('BMI Error, Numerical Solution ', i3, &
39  &' failed to converge')"
40 
41 contains
42 
43  !> @brief Sets the last BMI error message and copies
44  !! it to an exported C-string
45  !<
46  subroutine report_bmi_error(err_msg)
47  ! -- dummy variables
48  character(len=*), intent(in) :: err_msg !< the error message
49  bmi_last_error = err_msg
50  write (istdout, *) trim(err_msg)
51  end subroutine report_bmi_error
52 
53  !> @brief Get the last error in the BMI as a character array
54  !! with size BMI_LENERRMESSAGE
55  !<
56  function get_last_bmi_error(c_error) result(bmi_status) &
57  bind(C, name="get_last_bmi_error")
58  !DIR$ ATTRIBUTES DLLEXPORT :: get_last_bmi_error
59  ! -- dummy variables
60  character(kind=c_char, len=1), intent(out) :: c_error(bmi_lenerrmessage) !< C style char array with error
61  integer(kind=c_int) :: bmi_status !< BMI status code
62  ! -- local variables
63  integer(I4B) :: i, length
64 
65  length = len(trim(bmi_last_error))
66  do i = 1, length
67  c_error(i) = bmi_last_error(i:i)
68  end do
69  c_error(length + 1) = c_null_char
70 
71  bmi_status = bmi_success
72  end function get_last_bmi_error
73 
74 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:58
character(len= *), parameter fmt_unsupported_type
Definition: mf6bmiError.f90:31
character(len=lenerrmessage) bmi_last_error
module variable containing the last error as a Fortran string
Definition: mf6bmiError.f90:20
subroutine report_bmi_error(err_msg)
Sets the last BMI error message and copies it to an exported C-string.
Definition: mf6bmiError.f90:47
character(len= *), parameter fmt_invalid_mem_access
Definition: mf6bmiError.f90:34
character(len= *), parameter fmt_fail_cvg_sol
Definition: mf6bmiError.f90:37
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