C (c) 1991 The Board of Trustees of the University of Illinois
C          "All Rights Reserved Under the Copyright Laws".


      SUBROUTINE SBOUTY (IEID)
      PARAMETER(NEV=1200)
      PARAMETER(NDATA = 30)
      PARAMETER(NDEP = 20)

      REAL MXREAL,MNREAL
      PARAMETER(MXREAL = 3.4E+38,MNREAL = 0.)
C     NEV = NUMBER  OF EVENTS
C     NDATA = NUMBER OF DATA RECORDED FOR EACH  EVENT.
C     NDEP = DEPTH OF CALL NESTING
      COMMON/PTRAR/PTARR
      INTEGER  PTARR

      COMMON/TIMEAR/TIMAR
      REAL TIMAR(NEV, NDATA)

      COMMON/STACKS/STK
      INTEGER STK(NDEP)

C     TIMING INFO ABOUT SBIN,SBOUT,DOOT,DOIN SUBS OVERHEAD
      COMMON/OVHEAD/SB(3),SBMIN(3),SBMAX(3),SBDIF(3),DOV(3), DOVMIN(3),
     $     DOVMAX(3),DOVDIF(3),COV(3),COVMIN(3),COVMAX(3),COVDIF(3),
     $     FTOV(3),FTOVMN(3),FTOVMX(3),FTOVDF(3)

C     DEFINE THE FUNCTIONS TO BE CALLED 
      REAL RTCW,RTCC,TIM(3)

      INTEGER ID, IEID, PEID

C      PRINT *, 'EXITING FROM ', IEID
C     CALCULATE IEID OF EXIT OF BLOCK = PACKED WITH THE ENTRY BLOCK ID
      ID = IEID - 1

C     THE TIME (WALL AND CPU)
      CALL FUNTIM(TIM)
      RTCC = TIM(1)
      RTCW = TIM(2)

C     DECREASE CALLING DEPTH COUNTER IN PTARR AND MY OWN STACKPTR
C     
      PTARR = PTARR - 1
      PEID = STK(PTARR)

C     DURATIONS (DELTA)
C     INCLUSIVE
      TIMAR(ID,4) = RTCC - TIMAR(ID,1) - COV(1) -FTOV(1)
      IF (TIMAR(ID,4) .LT. 0.) THEN
         TIMAR(ID,4) = 0.
      ENDIF
      TIMAR(ID,5) = RTCW - TIMAR(ID,2) - COV(2) - FTOV(2)
      IF (TIMAR(ID,5) .LT. 0.) THEN
         TIMAR(ID,5) = 0.
      ENDIF
C     EXCLUSIVE
      TIMAR(ID,6) = RTCC - TIMAR(ID,1)-COV(1)-FTOV(1) -TIMAR(ID,8)
      IF (TIMAR(ID,6) .LT. 0.) THEN
         TIMAR(ID,6) = 0.
      ENDIF
C     RESET SUM OF DURATIONS OF CHILDREN
      TIMAR(ID,8) = 0.
C     ADD MY INCLUSIVE DURATION TO MY PARENT'S (CHILDREN DURATION SLOT)
      IF (TIMAR(ID,4) .GT. 0.) THEN
         TIMAR(PEID,8) = TIMAR(PEID,8) + RTCC - TIMAR(ID,1)-COV(1)-
     $        FTOV(1)+SB(1)
      ELSE
         TIMAR(PEID,8) = TIMAR(PEID,8) + SB(1)
      ENDIF
C     ADD DURATIONS TO SUM OF DURATIONS(FOR  AVERAGES)
C     INCLUSIVE
      TIMAR(ID,10) =TIMAR(ID,10)+TIMAR(ID,4)
      TIMAR(ID,11) =TIMAR(ID,11)+TIMAR(ID,5)
C     EXCLUSIVE
      TIMAR(ID,12) =TIMAR(ID,12)+TIMAR(ID,6)
C     UPDATE MINIMUM DURATION
C     INCLUSIVE
      IF (TIMAR(ID,14) .GT. TIMAR(ID,4)) THEN
         TIMAR(ID,14) = TIMAR(ID,4)
      ENDIF
      IF (TIMAR(ID,15) .GT. TIMAR(ID,5)) THEN
         TIMAR(ID,15) = TIMAR(ID,5)
      ENDIF
C     EXCLUSIVE
      IF (TIMAR(ID,16) .GT. TIMAR(ID,6)) THEN
         TIMAR(ID,16) = TIMAR(ID,6)
      ENDIF

C     UPDATE MAX DURATION
C     INCLUSIVE
      IF (TIMAR(ID,18) .LT. TIMAR(ID,4)) THEN
         TIMAR(ID,18) = TIMAR(ID,4)
      ENDIF
      IF (TIMAR(ID,19) .LT. TIMAR(ID,5)) THEN
         TIMAR(ID,19) = TIMAR(ID,5)
      ENDIF
C     EXCLUSIVE
      IF (TIMAR(ID,20) .LT. TIMAR(ID,6)) THEN
         TIMAR(ID,20) = TIMAR(ID,6)
      ENDIF

C     CALCULATE DELTA SQUARE
C     INCLUSIVE
      TIMAR(ID,22) = TIMAR(ID,4)**2
      TIMAR(ID,23) = TIMAR(ID,5)**2
C     EXCLUSIVE
      TIMAR(ID,24) = TIMAR(ID,6)**2

C     ADD DURATIONS TO SUM OF DURATIONS^2(FOR  AVERAGES)     
C     INCLUSIVE
      TIMAR(ID,26) = TIMAR(ID,26) + TIMAR(ID,22)
      TIMAR(ID,27) = TIMAR(ID,27) + TIMAR(ID,23)
C     EXCLUSIVE
      TIMAR(ID,28) = TIMAR(ID,28) + TIMAR(ID,24)
C
C     DURATIONS (DELTA)
C     EXCLUSIVE
      TIMAR(ID,7) = RTCW - TIMAR(ID,2)-FTOV(2)-TIMAR(ID,9) - COV(2)
      IF (TIMAR(ID,7) .LT. 0.) THEN
         TIMAR(ID,7) = 0.
      ENDIF
C     RESET SUM OF DURATIONS OF CHILDREN
      TIMAR(ID,9) = 0.
C     ADD MY INCLUSIVE DURATION TO MY PARENT (CHILDREN DURATION SLOT)
      IF (TIMAR(ID,5) .GT. 0.) THEN
         TIMAR(PEID,9) = TIMAR(PEID,9) + RTCW - TIMAR(ID,2)-COV(2)-
     $        FTOV(2)+SB(2)
      ELSE
         TIMAR(PEID,9) = TIMAR(PEID,9) + SB(2)
      ENDIF

C     ADD DURATIONS TO SUM OF DURATIONS(FOR  AVERAGES)
C     EXCLUSIVE
      TIMAR(ID,13) =TIMAR(ID,13)+TIMAR(ID,7)
C     UPDATE MINIMUM DURATION
C     EXCLUSIVE
      IF (TIMAR(ID,17) .GT. TIMAR(ID,7)) THEN
         TIMAR(ID,17) = TIMAR(ID,7)
      ENDIF

C     UPDATE MAX DURATION
C     EXCLUSIVE
      IF (TIMAR(ID,21) .LT. TIMAR(ID,7)) THEN
         TIMAR(ID,21) = TIMAR(ID,7)
      ENDIF

C     CALCULATE DELTA SQUARE
C     EXCLUSIVE
      TIMAR(ID,25) = TIMAR(ID,7)**2
C     ADD DURATIONS TO SUM OF DURATIONS^2(FOR  AVERAGES)     
C     EXCLUSIVE
      TIMAR(ID,29) = TIMAR(ID,29) + TIMAR(ID,25)

      RETURN
      END
