ComIn 0.5.1
ICON Community Interface
Loading...
Searching...
No Matches
comin_errhandler.F90
Go to the documentation of this file.
1!> @file comin_errhandler.F90
2!! @brief Utility functions for error handling.
3!
4! @authors 08/2021 :: ICON Community Interface <comin@icon-model.org>
5!
6! SPDX-License-Identifier: BSD-3-Clause
7!
8! See LICENSES for license information.
9! Where software is supplied by third parties, it is indicated in the
10! headers of the routines.
11!
12
14
15 USE iso_c_binding, ONLY: c_ptr, c_int, c_bool, c_char, c_null_char
20
21 IMPLICIT NONE
22
23 PRIVATE
24 PUBLIC :: comin_plugin_finish
25 PUBLIC :: comin_message
28 PUBLIC :: comin_error_check
29 PUBLIC :: comin_error_get
30 PUBLIC :: comin_error_set
32 PUBLIC :: comin_error_reset
33
34#include "comin_global.inc"
35
36 INTERFACE
37 !> Retrieve the current ComIn error code.
38 FUNCTION comin_error_get() BIND(C)
39 IMPORT c_int
40 INTEGER(c_int) :: comin_error_get
41 END FUNCTION
42
43 SUBROUTINE comin_error_reset() BIND(C)
44 END SUBROUTINE
45
46 TYPE(c_ptr) FUNCTION comin_error_get_string_c(error_code) &
47 & BIND(C, name='comin_error_get_string')
48 IMPORT c_int, c_ptr
49 INTEGER(c_int), VALUE, INTENT(IN) :: error_code
50 END FUNCTION comin_error_get_string_c
51
52 TYPE(c_ptr) FUNCTION comin_error_get_category_c(error_code) &
53 & BIND(C, name='comin_error_get_category')
54 IMPORT c_int, c_ptr
55 INTEGER(c_int), VALUE, INTENT(IN) :: error_code
56 END FUNCTION comin_error_get_category_c
57
58 SUBROUTINE comin_plugin_finish_c(routine, text) BIND(C, NAME="comin_plugin_finish")
59 IMPORT c_char
60 CHARACTER(kind=c_char) :: routine(*)
61 CHARACTER(kind=c_char) :: text(*)
62 END SUBROUTINE comin_plugin_finish_c
63
64 !> @ingroup fortran_interface
65 SUBROUTINE comin_error_check() BIND(C)
66 END SUBROUTINE comin_error_check
67
68 !> @ingroup fortran_interface
69 SUBROUTINE comin_error_set(err_code) BIND(C)
70 IMPORT c_int
71 INTEGER(C_INT), VALUE, INTENT(IN) :: err_code
72 END SUBROUTINE comin_error_set
73
74 !> @ingroup fortran_interface
75 SUBROUTINE comin_error_set_errors_return_c(errors_return) &
76 BIND(C, NAME="comin_error_set_errors_return")
77 IMPORT c_bool
78 LOGICAL(C_BOOL), VALUE, INTENT(IN) :: errors_return
79 END SUBROUTINE comin_error_set_errors_return_c
80
81 END INTERFACE
82
83CONTAINS
84
85 !> Wrapper function for callback to ICON's "finish" routine.
86 !! @ingroup fortran_interface
87 SUBROUTINE comin_plugin_finish(routine, text)
88 CHARACTER(LEN=*), INTENT(IN) :: routine
89 CHARACTER(LEN=*), INTENT(IN) :: text
90 CALL comin_plugin_finish_c(routine // c_null_char, text // c_null_char)
91 END SUBROUTINE comin_plugin_finish
92
93 !> Prints a message on rank 0 if the global verbosity level larger than lvl
94 SUBROUTINE comin_message(message, lvl)
95 CHARACTER(LEN=*), INTENT(IN) :: message
96 INTEGER, INTENT(IN) :: lvl
97
98 INTEGER :: iverbosity
99
101
102 IF (lvl < 0) THEN
103 CALL comin_plugin_finish("message", "ERROR: Message level must be non-negative.")
104 END IF
105
106 IF (comin_state_get_lstdout() .AND. (iverbosity > lvl)) THEN
107 WRITE(comin_state_get_output_unit(), *) trim(message)
108 END IF
109 END SUBROUTINE comin_message
110
111 !> C-wrapper for the `comin_message` subroutine.
112 SUBROUTINE comin_message_c(msg, lvl) &
113 & BIND(C, name="comin_message")
114 TYPE(c_ptr), VALUE, INTENT(IN) :: msg
115 INTEGER(KIND=c_int), VALUE, INTENT(IN) :: lvl
116 CALL comin_message(convert_c_string(msg), lvl)
117 END SUBROUTINE comin_message_c
118
119 !> Return the string description of the given error code.
120 !! @ingroup fortran_interface
121 FUNCTION comin_error_get_string(error_code) RESULT(string)
122 INTEGER, INTENT(IN) :: error_code
123 CHARACTER(LEN=COMIN_MAX_LEN_ERR_MESSAGE) :: string
124
125 string = convert_c_string(comin_error_get_string_c(error_code))
126 END FUNCTION
127
128 !> Return the category of the given error code.
129 !! @ingroup fortran_interface
130 FUNCTION comin_error_get_category(error_code) RESULT(category)
131 INTEGER, INTENT(IN) :: error_code
132 CHARACTER(LEN=11) :: category
133
134 category = convert_c_string(comin_error_get_category_c(error_code))
135 END FUNCTION comin_error_get_category
136
137 SUBROUTINE comin_error_set_errors_return(errors_return)
138 LOGICAL, INTENT(IN) :: errors_return
139 CALL comin_error_set_errors_return_c(LOGICAL(errors_return, c_bool))
140 END SUBROUTINE comin_error_set_errors_return
141
142END MODULE comin_errhandler
int comin_state_get_output_unit()
int comin_setup_get_verbosity_level()
bool comin_state_get_lstdout()
character(len=11) function, public comin_error_get_category(error_code)
Return the category of the given error code.
subroutine, public comin_plugin_finish(routine, text)
Wrapper function for callback to ICON's "finish" routine.
character(len=comin_max_len_err_message) function, public comin_error_get_string(error_code)
Return the string description of the given error code.
Retrieve the current ComIn error code.
subroutine, public comin_message(message, lvl)
Prints a message on rank 0 if the global verbosity level larger than lvl.
subroutine, public comin_error_set_errors_return(errors_return)