c This subroutine can be used to catch NDP EXCEPTIONS.
c To find what procedure an exception has occurred in, see
c the example of USER_DEBUG(a,b,n).  Once the procedure is known,
c add CALL CHECK(identifier) at strategic places.
c Every time CHECK is called, it will check the STATUS WORD.
c If a problem has occurred since the last invocation to CHECK,
c the error will be printed with the identifier.

	subroutine check(i)
	character*10 temp
	data temp / 10H(' ',i1,$) /
	integer j, stndpsw, k
1	Format (' ',a,$)
	j = stndpsw()
	if (0.lt.(j.and.127)) then
	  k=0
10	  k=k+1
	  if (i.ge.10**k) goto 10
	  temp(7:7) = char(48+k)
	  Print 1, 'Before Check #'
	  Print temp, i
	  If (0.lt.(J.AND. 1)) Print 1,', Invalid Operation'
	  If (0.lt.(J.AND. 2)) Print 1,', Denormal'
	  If (0.lt.(J.AND. 4)) Print 1,', Zero Divide'
	  If (0.lt.(J.AND. 8)) Print 1,', Overflow'
	  If (0.lt.(J.AND.16)) Print 1,', Underflow'
	  If (0.lt.(J.AND.32)) Print 1,', Precision'
	  If (0.lt.(J.AND.64)) Print 1,', Stack Fault'
	  Print *,'.'
	  call clrndpex
	end if
	end

c This subroutine can be used to catch MEMORY PROTECTION FAULTS.
c To find what procedure the problem is happening in, write down
c the address given in CS:EIP.  From the DOS prompt, type this line:
c TYPE {filename}.MAP | FIND "codeseg" | SORT /+15 > p2.map
c This line will sort the map file into a new file called p2.map.
c p2.map will have all procedures listed in increasing order of
c memory address.  Find what 2 memory addresses the CS:EIP number is
c between; the MEMORY PROTECTION FAULT is in the first procedure.
c In that procedure, add CALL DUM(identifier 1-26) at strategic places.
c Every time the program passes this point, it will print a letter
c (A-Z corresponding to the identifier), followed by the number
c of times the program has passed this point.

	subroutine dum(k)
	character*11 temp
	integer i(26)
	data i,temp / 26*0,11H(' A',I1,$) /
	i(k) = i(k) + 1
	j = 0
10	j = j + 1
	if (i(k).ge.10**j) goto 10
	temp(4:4) = char(64+k)
	temp(8:8) = char(48+j)
	print temp, i(k)
	end
