assert,assert_alloc, assert_directory_present, $\ldots$


The Fortran90 module misc_utils contains a few routines to test an assertion and return an error message if it is false.

Location in HEALPix directory tree: src/f90/mod/misc_utils.F90 

SUBROUTINES:
call assert(test [, msg, errcode])

    if test is true, proceeds with normal code execution. If test is false, issues a standard error message (unless msg is provided) and stops the code execution with the status errcode (or 1 by default).  

call assert_alloc(status, code, array)

    if status is 0, proceeds with normal code execution. If not, issues an error message indicating a problem during memory allocation of array in program code, and stops the code execution.  

call assert_directory_present(directory)

    issues an error message and stops the code execution if the directory named directory can not be found  

call assert_not_present(filename)

    issues an error message and stops the code execution if a file with name filename already exists.  

call assert_present(filename)

    issues an error message and stops the code execution if the file named filename can not be found.  

call fatal_error([msg])

call fatal_error

    issue an (optional user defined) error message and stop the code execution.  


ARGUMENTS

name & dimensionality kind in/out description
       
test LGT IN result of a logical test
msg OPTIONAL CHR IN character string describing nature of error
errorcode OPTIONAL I4B IN error status given to code interruption
status I4B IN value of the stat flag returned by the F90 allocate command
code CHR IN name of program or code in which allocation is made
array CHR IN name of array allocated
directory CHR IN directory name (contains a '/')
filename CHR IN file name


EXAMPLE:

program my_code
use misc_utils
real, allocatable, dimension(:) :: vector
integer :: status
real :: a = -1.

allocate(vector(12345),stat=status)
call assert_alloc(status, 'my_code', 'vector')

call assert_directory_present('/home')

call assert(a > 0., 'a is NEGATIVE !!!')

end program my_code
Will issue a error message and stops the code if vector can not be allocated, will stop the code if '/home' is not found, and will stop the code and complain loudly about it because a is actually negative.

Version 3.31, 2017-01-06