ICON Community Interface 0.4.0
Loading...
Searching...
No Matches
comin_errhandler.F90
Go to the documentation of this file.
1
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
15SUBROUTINE comin_plugin_finish_external(routine, text)
16 USE mpi
18 USE comin_setup_constants, ONLY: ep_finish
19
20 CHARACTER(LEN=*), INTENT(IN) :: routine
21 CHARACTER(LEN=*), INTENT(IN) :: text
22 !
23 INTEGER, PARAMETER :: exit_no = 1
24 INTEGER :: ierr
25
26 ! skip this routine if the "finish" call was triggered by a plugin
27 ! inside the entry point EP_FINISH itself:
28 IF (comin_current_get_ep() == ep_finish) RETURN
29
30 IF (ASSOCIATED(state%comin_host_finish)) THEN
31 CALL state%comin_host_finish(routine, text)
32 ELSE
33 WRITE (0,*) routine, " ", text
34 CALL mpi_abort(mpi_comm_world, exit_no, ierr)
35 stop exit_no
36 END IF
38
40
41 USE mpi
42 USE iso_c_binding, ONLY: c_ptr, c_int, c_char, c_bool
46 USE comin_setup_constants, ONLY: ep_finish
49
50 IMPLICIT NONE
51
52 PRIVATE
53 PUBLIC :: comin_plugin_finish
54 PUBLIC :: comin_message
56 PUBLIC :: comin_error_check
59 PUBLIC :: comin_error_reset
60
61#include "comin_global.inc"
62
63CONTAINS
64
67 SUBROUTINE comin_plugin_finish(routine, text)
68 CHARACTER(LEN=*), INTENT(IN) :: routine
69 CHARACTER(LEN=*), INTENT(IN) :: text
70 CALL comin_plugin_finish_external(routine,text)
71 END SUBROUTINE comin_plugin_finish
72
74 !
75 SUBROUTINE comin_plugin_finish_c(routine, text) &
76 & BIND(C, name="comin_plugin_finish")
77 TYPE(c_ptr), VALUE, INTENT(IN) :: routine
78 TYPE(c_ptr), VALUE, INTENT(IN) :: text
80 END SUBROUTINE comin_plugin_finish_c
81
83 SUBROUTINE comin_message(message, lvl)
84 CHARACTER(LEN=*), INTENT(IN) :: message
85 INTEGER, INTENT(IN) :: lvl
86
87 INTEGER :: iverbosity
88
90
91 IF (lvl < 0) THEN
92 CALL comin_plugin_finish("message", "ERROR: Message level must be non-negative.")
93 END IF
94
95 IF (state%lstdout .AND. (iverbosity > lvl)) THEN
96 WRITE(state%output_unit, *) trim(message)
97 END IF
98 END SUBROUTINE comin_message
99
102 SUBROUTINE comin_error_get_message(error_code, category, message)
103 INTEGER, INTENT(IN) :: error_code
104 CHARACTER(LEN=11), INTENT(INOUT) :: category
105 CHARACTER(LEN=COMIN_MAX_LEN_ERR_MESSAGE), INTENT(INOUT) :: message
106
107 IF (error_code < comin_success .OR. error_code > comin_error_fatal) THEN
108 CALL comin_plugin_finish("error", "ERROR: Unknown error code.")
109 END IF
110
111 category = ""
112 IF (error_code == comin_success) THEN
113 category = "SUCCESS"
114 ELSE IF (error_code < comin_warning) THEN
115 category = "INFO"
116 ELSE IF (error_code < comin_error_status) THEN
117 category = "WARNING"
118 ELSE IF (error_code < comin_error_fatal) THEN
119 category = "ERROR"
120 ELSE
121 category = "FATAL ERROR"
122 END IF
123
124 message = trim(comin_errhandler_get_string(error_code))
125 END SUBROUTINE comin_error_get_message
126
127 SUBROUTINE comin_error_get_message_c(error_code, category, message) &
128 & BIND(C, name="comin_error_get_message")
129 INTEGER(C_INT), VALUE, INTENT(IN) :: error_code
130 CHARACTER(KIND=C_CHAR), INTENT(OUT) :: category(11)
131 CHARACTER(KIND=C_CHAR), INTENT(OUT) :: message(comin_max_len_err_message)
132
133 CHARACTER(LEN=11) :: category_f
134 CHARACTER(LEN=COMIN_MAX_LEN_ERR_MESSAGE) :: message_f
135 CALL comin_error_get_message(error_code, category_f, message_f)
136 CALL convert_f_string(category_f, category)
137 CALL convert_f_string(message_f, message)
138 END SUBROUTINE comin_error_get_message_c
139
145 SUBROUTINE comin_error_check() BIND(C)
146
147 INTEGER :: error_code
148 CHARACTER(LEN=11) :: message_prefix
149 CHARACTER(LEN=COMIN_MAX_LEN_ERR_MESSAGE) :: message
150
151 error_code = state%errcode
152 IF(error_code == comin_success) RETURN
153
154 CALL comin_error_get_message(error_code, message_prefix, message)
155
156 IF (error_code < comin_error_status) THEN
157 CALL comin_message(trim(message_prefix) // ": " &
158 &// trim(message), 0)
159 ELSE
160 IF (.NOT. ASSOCIATED(state%current_plugin)) THEN
161 CALL comin_plugin_finish("ComIn", &
162 trim(message_prefix) // ": " // trim(message))
163 ELSE
164 CALL comin_plugin_finish(state%current_plugin%name, &
165 trim(message_prefix) // ": " // trim(message))
166 END IF
167 END IF
168 END SUBROUTINE comin_error_check
169
170 SUBROUTINE comin_error_set(errcode)
171 INTEGER, INTENT(IN) :: errcode
172 state%errcode = errcode
173 IF (.NOT. ASSOCIATED(state%current_plugin)) THEN
174 CALL comin_error_check()
175 ELSE
176 IF(.NOT. state%current_plugin%errors_return) THEN
177 CALL comin_error_check()
178 END IF
179 END IF
180 END SUBROUTINE comin_error_set
181
184 FUNCTION comin_error_get() &
185 & BIND(C)
186 INTEGER(C_INT) :: comin_error_get
187 comin_error_get = state%errcode
188 END FUNCTION comin_error_get
189
192 SUBROUTINE comin_error_reset() &
193 & BIND(C)
194 state%errcode = comin_success
195 END SUBROUTINE comin_error_reset
196
201 SUBROUTINE comin_error_set_errors_return(errors_return)
202 LOGICAL, INTENT(IN) :: errors_return
203 state%current_plugin%errors_return = errors_return
204 END SUBROUTINE comin_error_set_errors_return
205
206 SUBROUTINE comin_error_set_errors_return_c(errors_return) &
207 BIND(C, NAME="comin_error_set_errors_return")
208 LOGICAL(C_BOOL), VALUE, INTENT(IN) :: errors_return
209 state%current_plugin%errors_return = errors_return
210 END SUBROUTINE comin_error_set_errors_return_c
211
212END MODULE comin_errhandler
integer function, public comin_setup_get_verbosity_level()
Returns verbosity level.
subroutine, public comin_plugin_finish(routine, text)
Wrapper function for callback to ICON's "finish" routine.
subroutine, public comin_error_get_message(error_code, category, message)
query the message and category for a given error code
subroutine, public comin_error_check()
check the error code: does nothing if error_code == COMIN_SUCCESS prints the corresponding message ca...
subroutine, public comin_error_reset()
resets the internal error code to COMIN_SUCCESS
subroutine, public comin_error_set_errors_return(errors_return)
Change the error handling mode. Set it to .TRUE. to handle errors manually. If it set to ....
subroutine comin_plugin_finish_external(routine, text)
Wrapper function for callback to ICON's "finish" routine.
integer(c_int) function, public comin_current_get_ep()
Access information on the current entry point being processed by ComIn.
integer(c_int) function, public comin_error_get()
returns the current error code
subroutine, public convert_f_string(string, arr)
Convert Fortran string into C-style character array.
character(len=comin_max_len_err_message) function comin_errhandler_get_string(err_code)
subroutine, public comin_error_set(errcode)
subroutine, public comin_message(message, lvl)
Prints a message on rank 0 if the global verbosity level larger than lvl.
type(t_comin_state), pointer, public state