|
Next: Adding documentation Up: Completing a Thorn Previous: Providing Runtime Information Contents Error handling, warnings and code terminationError handling, ... The Cactus function CCTK_VWarn() and its accompanying CCTK_WARN macro should be used to issue warning messages during code execution. Along with the warning message, an integer is given to indicate the severity of the warning. The warning severity indicates whether the message is actually printed to standard error and whether the code should be stopped. A level 0 warning indicates the highest severity, with higher numbers indicating lower severity.By default, a Cactus run will abort on a level 0 warning and will report level 1 and severer warnings to screen. This behaviour can be amended using command line arguments, as described in Section A3.1. For example, to provide a warning which will be printed to standard error but which will not terminate the code for a run with default options, a level 1 warning should be used. The syntax from Fortran is call CCTK_WARN(1, "Your warning message") and from C CCTK_WARN(1, "Your warning message"); Note that CCTK_WARN is just a macro which expands to a call to the internal function CCTK_Warn(). The macro automatically includes the name of the thorn, the source file name and line number of the warning in the function call. (For this reason it is important for Fortran code that capital letters are always used in order to expand the macro). If the Flesh parameter cctk_full_warnings is set to true, then the source file name and line number will be printed to standard error along with the originating processor number, the thorn name and the warning message. The default is to omit the source file name and line number. Note that the routine CCTK_VWarn() can only be called from C because Fortran doesn't know about variable argument lists. So including variables in the warning message using CCTK_WARN is currently more tricky, since you need to build the string to be output. For example, in C you would just write
int myint;
double myreal;
CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,
"Your warning message, including %f and %d",
myreal, myint);
But in Fortran you have to do the following:
integer myint
real myreal
character*200 message
write (message, '("Your warning message, including ",g12.7," and ",i8)') myreal, myint
call CCTK_WARN (1, message(1:len_trim(message)))
In Fortran 90, you can also do:
integer myint
real myreal
character(200) message
write (message, '("Your warning message, including ",g12.7," and ",i8)') myreal, myint
call CCTK_WARN (1, trim(message))
The Flesh will be implementing standard error return codes which can be used by the thorns, although this is not yet ready. In general, thorns should attempt to handle errors without terminating, and warning messages should be liberally used.
Next: Adding documentation Up: Completing a Thorn Previous: Providing Runtime Information Contents |