[comp.sys.sun] exception handling in FORTRAN

rwn@cs.utexas.edu (Ralph Noack) (12/12/88)

We too were shocked that flt pt exceptions were not being taken. Took me a
while to figure it out and longer to figure out how to turn it on. Here is
what we do under SunOS 4.0(I can send similiar for 3.x, they are
different.

We either link in a subroutine or include the code from a file such as

      include '/usr/local/trap.i'

where /usr/local/trap.i contains

      external abort
      ieeer= ieee_handler('set','common',abort)
      if (ieeer .ne. 0) then
        write (0,'(''ieee_flags returned status='',i5)') ieeer
        stop 'ieee_flags'
      endif

The difficulty is that 4.0 has lots of problems and debugging is one of
them. With this include as the first executable statement in the main,
tracebacks are incorrect. To alleviate this I created a subroutine which I
added to /usr/lib/libF77.a I think. Replace the include above by the call

      call trapfltpt

with the subroutine being:

      subroutine trapfltpt
      external abort
      ieeer= ieee_handler('set','common',abort)
      if (ieeer .ne. 0) then
        write (0,'(''ieee_flags returned status='',i5)') ieeer
        stop 'ieee_flags'
      endif
      return 
      end

either works fine regardless of floating pt hardware.

-- 
Ralph W. Noack (817)-273-2860
Univ. of Tx at Arlington, Aerospace Eng. Dept. Box 19018 Arlington, Tx 76019
..!{killer,texsun}!utacfd!rwn

ok@sun.com (Richard A. O'Keefe) (12/20/88)

texbell!killer!utacfd!rwn@cs.utexas.edu (Ralph Noack) writes:
>We too were shocked that flt pt exceptions were not being taken.

You shouldn't have been:  that's what the IEEE 754 standard _specifies_.
The standard recommends that there should be some way of enabling
exceptions, but it is not required.  Sun followed the letter of the
standard.  (I agree that it is a pain.)