In CP2K there exist three convenient macros for error handling. They are defined in src/base/base_uses.f90, and are therefore always available. However, these macros can only be used for short messages (approximately less than 7 words), because of Fortran's line length limitation.
CPWARN("A short warning message") CPABORT("A short error message") CPASSERT(2>1) ! For sanity checks only, not for user errors.
For longer messages one can use these two routines:
CALL cp_warn(__LOCATION__,"A long warning message "//& "which can span multiple lines and contains "//& "some valuable advice for the user.") CALL cp_abort(__LOCATION__,"A long error message "//& "with even more valuable advices.")
CPWARN
and cp_warn
are only printed on the first MPI-rank.If you want to…
CPWARN("your short message")
CALL cp_warn(__LOCATION__,"your lengthy message, "//& "which can even span multiple lines")
CPABORT("your short message")
CALL cp_abort(__LOCATION__,"your lengthy message, "//& "which can even span multiple lines")
CPASSERT(your_logical_expression)
IF(.NOT.your_logical_expression) CPABORT("your short message")
IF(.NOT.your_super_complicated_logical_expression_that_takes_alot_of_space)& CPABORT("your short message")
IF(.NOT.your_super_long_logical_expression_that_takes_alot_of_space)& CALL cp_abort(__LOCATION__,"your lengthy message"//& "which again can even span multiple lines")