30 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'cp_error_handling'
59 CHARACTER(len=*),
INTENT(in) :: location, message
63 CALL delay_non_master()
66 IF (unit_nr <= 0)
THEN
70 CALL print_abort_message(message, location, unit_nr)
84 CHARACTER(len=*),
INTENT(in) :: location, message
94 CALL print_message(
"WARNING in "//trim(location)//
' :: '//trim(adjustl(message)), unit_nr, 1, 1, 1)
106 CHARACTER(len=*),
INTENT(in) :: location, message
111 IF (unit_nr > 0)
THEN
112 CALL print_message(
"HINT in "//trim(location)//
' :: '//trim(adjustl(message)), unit_nr, 1, 1, 1)
121 SUBROUTINE delay_non_master()
123 REAL(kind=
dp) :: t1, wait_time
129 IF (unit_nr <= 0)
THEN
130 wait_time = wait_time + 1.0_dp
137 IF (wait_time > 0.0_dp)
THEN
140 IF (
m_walltime() - t1 > wait_time .OR. t1 < 0)
EXIT
144 END SUBROUTINE delay_non_master
153 SUBROUTINE print_abort_message(message, location, output_unit)
154 CHARACTER(LEN=*),
INTENT(IN) :: message, location
155 INTEGER,
INTENT(IN) :: output_unit
157 INTEGER,
PARAMETER :: img_height = 8, img_width = 9, screen_width = 80, &
158 txt_width = screen_width - img_width - 5
159 CHARACTER(LEN=img_width),
DIMENSION(img_height),
PARAMETER :: img = [
" ___ ",
" / \ "&
160 ,
" [ABORT] ",
" \___/ ",
" | ",
" O/| ",
" /| | ",
" / \ "]
162 CHARACTER(LEN=screen_width) :: msg_line
163 INTEGER :: a, b, c, fill, i, img_start, indent, &
164 msg_height, msg_start
168 a = 1; b = -1; msg_height = 0
169 DO WHILE (b < len_trim(message))
170 b = next_linebreak(message, a, txt_width)
172 msg_height = msg_height + 1
176 IF (img_height > msg_height)
THEN
177 msg_start = (img_height - msg_height)/2 + 1
181 img_start = msg_height - img_height + 2
185 WRITE (unit=output_unit, fmt=
"(A)")
""
188 WRITE (unit=output_unit, fmt=
"(T2,A)") repeat(
"*", screen_width - 1)
192 DO i = 1, max(img_height - 1, msg_height)
193 WRITE (unit=output_unit, fmt=
"(A)", advance=
'no')
" *"
194 IF (i < img_start)
THEN
195 WRITE (unit=output_unit, fmt=
"(A)", advance=
'no') repeat(
" ", img_width)
197 WRITE (unit=output_unit, fmt=
"(A)", advance=
'no') img(c)
200 IF (i < msg_start)
THEN
201 WRITE (unit=output_unit, fmt=
"(A)", advance=
'no') repeat(
" ", txt_width + 2)
203 b = next_linebreak(message, a, txt_width)
204 msg_line = message(a:b)
206 fill = (txt_width - len_trim(msg_line))/2 + 1
207 indent = txt_width - len_trim(msg_line) - fill + 2
208 WRITE (unit=output_unit, fmt=
"(A)", advance=
'no') repeat(
" ", indent)
209 WRITE (unit=output_unit, fmt=
"(A)", advance=
'no') trim(msg_line)
210 WRITE (unit=output_unit, fmt=
"(A)", advance=
'no') repeat(
" ", fill)
212 WRITE (unit=output_unit, fmt=
"(A)", advance=
'yes')
"*"
216 WRITE (unit=output_unit, fmt=
"(A)", advance=
'no')
" *"
217 WRITE (unit=output_unit, fmt=
"(A)", advance=
'no') img(c)
218 indent = txt_width - len_trim(location) + 1
219 WRITE (unit=output_unit, fmt=
"(A)", advance=
'no') repeat(
" ", indent)
220 WRITE (unit=output_unit, fmt=
"(A)", advance=
'no') trim(location)
221 WRITE (unit=output_unit, fmt=
"(A)", advance=
'yes')
" *"
224 WRITE (unit=output_unit, fmt=
"(T2,A)") repeat(
"*", screen_width - 1)
227 WRITE (unit=output_unit, fmt=
"(A)")
""
229 END SUBROUTINE print_abort_message
239 FUNCTION next_linebreak(message, pos, rowlen)
RESULT(ibreak)
240 CHARACTER(LEN=*),
INTENT(IN) :: message
241 INTEGER,
INTENT(IN) :: pos, rowlen
246 n = len_trim(message)
247 IF (n - pos <= rowlen)
THEN
250 i = index(message(pos + 1:pos + 1 + rowlen),
" ", back=.true.)
252 ibreak = pos + rowlen - 1
257 END FUNCTION next_linebreak
Central dispatch for basic hooks.
procedure(cp_warn_interface), pointer, public cp_warn_hook
procedure(cp_abort_interface), pointer, public cp_abort_hook
procedure(cp_hint_interface), pointer, public cp_hint_hook
Module that contains the routines for error handling.
integer, save, public warning_counter
subroutine, public cp_abort_handler(location, message)
Abort program with error message.
subroutine, public cp_warn_handler(location, message)
Signal a warning.
subroutine, public cp_error_handling_setup()
Registers handlers with base_hooks.F.
subroutine, public cp_hint_handler(location, message)
Signal a hint.
various routines to log and control the output. The idea is that decisions about where to log should ...
integer function, public cp_logger_get_default_io_unit(logger)
returns the unit nr for the ionode (-1 on all other processors) skips as well checks if the procs cal...
Defines the basic variable types.
integer, parameter, public dp
Machine interface based on Fortran 2003 and POSIX.
integer, parameter, public default_output_unit
subroutine, public m_flush(lunit)
flushes units if the &GLOBAL flag is set accordingly
real(kind=dp) function, public m_walltime()
returns time from a real-time clock, protected against rolling early/easily
Interface to the message passing library MPI.
subroutine, public mp_abort()
globally stops all tasks this is intended to be low level, most of CP2K should call cp_abort()
Perform an abnormal program termination.
subroutine, public print_message(message, output_unit, declev, before, after)
Perform a basic blocking of the text in message and print it optionally decorated with a frame of sta...
Timing routines for accounting.
subroutine, public print_stack(unit_nr)
Print current routine stack.