30 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'cp_error_handling'
59 CHARACTER(len=*),
INTENT(in) :: location, message
63 CALL delay_non_master()
69 CALL print_abort_message(message, location, unit_nr)
83 CHARACTER(len=*),
INTENT(in) :: location, message
93 CALL print_message(
"WARNING in "//trim(location)//
' :: '//trim(adjustl(message)), unit_nr, 1, 1, 1)
105 CHARACTER(len=*),
INTENT(in) :: location, message
110 IF (unit_nr > 0)
THEN
111 CALL print_message(
"HINT in "//trim(location)//
' :: '//trim(adjustl(message)), unit_nr, 1, 1, 1)
120 SUBROUTINE delay_non_master()
122 REAL(kind=
dp) :: t1, wait_time
129 wait_time = wait_time + 1.0_dp
135 IF (wait_time > 0.0_dp)
THEN
138 IF (
m_walltime() - t1 > wait_time .OR. t1 < 0)
EXIT
142 END SUBROUTINE delay_non_master
151 SUBROUTINE print_abort_message(message, location, output_unit)
152 CHARACTER(LEN=*),
INTENT(IN) :: message, location
153 INTEGER,
INTENT(IN) :: output_unit
155 INTEGER,
PARAMETER :: img_height = 8, img_width = 9, screen_width = 80, &
156 txt_width = screen_width - img_width - 5
157 CHARACTER(LEN=img_width),
DIMENSION(img_height),
PARAMETER :: img = [
" ___ ",
" / \ "&
158 ,
" [ABORT] ",
" \___/ ",
" | ",
" O/| ",
" /| | ",
" / \ "]
160 CHARACTER(LEN=screen_width) :: msg_line
161 INTEGER :: a, b, c, fill, i, img_start, indent, &
162 msg_height, msg_start
166 a = 1; b = -1; msg_height = 0
167 DO WHILE (b < len_trim(message))
168 b = next_linebreak(message, a, txt_width)
170 msg_height = msg_height + 1
174 IF (img_height > msg_height)
THEN
175 msg_start = (img_height - msg_height)/2 + 1
179 img_start = msg_height - img_height + 2
183 WRITE (unit=output_unit, fmt=
"(A)")
""
186 WRITE (unit=output_unit, fmt=
"(T2,A)") repeat(
"*", screen_width - 1)
190 DO i = 1, max(img_height - 1, msg_height)
191 WRITE (unit=output_unit, fmt=
"(A)", advance=
'no')
" *"
192 IF (i < img_start)
THEN
193 WRITE (unit=output_unit, fmt=
"(A)", advance=
'no') repeat(
" ", img_width)
195 WRITE (unit=output_unit, fmt=
"(A)", advance=
'no') img(c)
198 IF (i < msg_start)
THEN
199 WRITE (unit=output_unit, fmt=
"(A)", advance=
'no') repeat(
" ", txt_width + 2)
201 b = next_linebreak(message, a, txt_width)
202 msg_line = message(a:b)
204 fill = (txt_width - len_trim(msg_line))/2 + 1
205 indent = txt_width - len_trim(msg_line) - fill + 2
206 WRITE (unit=output_unit, fmt=
"(A)", advance=
'no') repeat(
" ", indent)
207 WRITE (unit=output_unit, fmt=
"(A)", advance=
'no') trim(msg_line)
208 WRITE (unit=output_unit, fmt=
"(A)", advance=
'no') repeat(
" ", fill)
210 WRITE (unit=output_unit, fmt=
"(A)", advance=
'yes')
"*"
214 WRITE (unit=output_unit, fmt=
"(A)", advance=
'no')
" *"
215 WRITE (unit=output_unit, fmt=
"(A)", advance=
'no') img(c)
216 indent = txt_width - len_trim(location) + 1
217 WRITE (unit=output_unit, fmt=
"(A)", advance=
'no') repeat(
" ", indent)
218 WRITE (unit=output_unit, fmt=
"(A)", advance=
'no') trim(location)
219 WRITE (unit=output_unit, fmt=
"(A)", advance=
'yes')
" *"
222 WRITE (unit=output_unit, fmt=
"(T2,A)") repeat(
"*", screen_width - 1)
225 WRITE (unit=output_unit, fmt=
"(A)")
""
227 END SUBROUTINE print_abort_message
237 FUNCTION next_linebreak(message, pos, rowlen)
RESULT(ibreak)
238 CHARACTER(LEN=*),
INTENT(IN) :: message
239 INTEGER,
INTENT(IN) :: pos, rowlen
244 n = len_trim(message)
245 IF (n - pos <= rowlen)
THEN
248 i = index(message(pos + 1:pos + 1 + rowlen),
" ", back=.true.)
250 ibreak = pos + rowlen - 1
255 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.