      PROGRAM EXC
C
C Purpose: demonstrates changing numeric error handling
C from passive to active in NDP Fortran-386
C To compile for an 80287:
C       f77 exc.f -n0
C To compile for an 80387:
C       f77 exc.f -n2
C To compile for an mW1167:
C       f77 exc.f -n4
C

C An NDP Fortran-386's default response to a division by
C zero is passive error handling. That is, the coprocesor
C will set the appropriate error bit in its status word,
C return an infinity signed with the exclusive OR of the
C signs of the operands, and continue processing. Here the
C programmer has decided that a division by zero is so
C serious a flaw that the proper response is MicroWay's
C default active error handling, i.e, dump the the state of
C the coprocessor to the standard output device and exit
C to the operating system. Therefore he has used ENAB_EX
C to unmask the zero-divide bit in the control word.
C

C       IM      1               All NDPs.
C       DM      2               80x87 only
C       ZM      4               All NDPs.
C       OM      8               All NDPs.
C       UM      16              All NDPs.
C       PM      32              All NDPs.
C       UOM     64              Weitek only.
C       DCM     128             Weitek only.

      INTEGER IM,DM,ZM,OM,UM,PM,OUM,DCM
      PARAMETER(IM=1,DM=2,ZM=4,OM=8,UM=16,PM=32,OUM=64,DCM=128)

C Error value returned by ENAB_EX
      INTEGER*4 EVAL
      PARAMETER (EVAL=-1)
      INTEGER*4 EVAL SAVE_CW, EMASK
      INTEGER*4 ENAB_EX
      REAL*8 X,Y,Z

      X = 1.0
      Y = 0.0

C Enable zero divide exception trap
      EMASK = ZM
      SAVE_CW = ENAB_EX(EMASK)

      IF (SAVE_CW .EQ. EVAL) THEN
           WRITE (*,100)
           WRITE (*,101) 'Problem in ENAB_EX'
           WRITE (*,101) CHAR(7)
           WRITE (*,100)
           STOP
      END IF
  100 FORMAT (1X)
  101 FORMAT (1X,A)

C Force divison by zero
      Z = X / Y

      WRITE (*,102) 'The quotient is ',Z
  102 FORMAT (1X,A,D20.14)

      END
