Compiler Library/XL Reference Manual (32650-90029)
A-4
A FORTRAN Example Using XLIBTRAP
The libtrap_test program in the above example can also be written FORTRAN
77/XL using the ON statement:
PROGRAM libtrap_test
IMPLICIT NONE
REAL x,y,NaN
INTEGER INaN
EQUIVALENCE (NaN, INaN)
DATA INaN / Z'7FF0' / ! bit pattern for single- precision NaN
ON EXTERNAL ERROR CALL ERROR ! Set up the trap.
PRINT *, 'Calling sqrt with', NaN
x=sqrt (NaN)
PRINT *, 'x should be -999.0. x=',X
PRINT *, 'This should be the last line before an abort.'
y=alog (NaN)
PRINT *, 'This line should NOT be printed.'
END
SUBROUTINE ERROR (errornum, result, operand 1, operand 2)
IMPLICIT NONE
INTEGER*2 errornum
REAL result, sqrt_default, operand1, operand2
INTEGER sqrt_errornum, abort
!Declare the constants.
PARAMETER (sqrt_default= -999.0)
PARAMETER (sqrt_errornum=10, abort=0)
print *, 'In ERROR, params =', errornum, result, operand1
!Test for SQRT
IF (errornum .eq. sqrt_errornum) THEN
!If so, set the default of -999.0 and continue
result=sqrt_default
ELSE
! Abort if it is not SQRT.
print *, 'Errornum set to ABORT.'
errornum = abort
ENDIF
END
Error Messages
1 MESSAGE ATAN2(X,Y): X=Y=0.0 OR X=Y=INFINITY OR ANY OF X
AND Y=NaN
CAUSE Both of the arguments are zero or infinity, or any
of the arguments is a NaN.
ACTION Change the arguments so both of them are not zero
or infinity, and neither is a NaN.
PROCEDURE ATAN2 or ATAN2'
3 MESSAGE DATAN2(X,Y): X=Y=0.0 OR X=Y=INFINITY OR ANY OF X
AND Y=NaN