C   21/05/81 105211757  MEMBER NAME  USREPTIL (JADESR)      FORTRAN
C   21/04/81 104211851  MEMBER NAME  USERRECL (S)           FORTRAN
      SUBROUTINE USER(INDEX)
C---
C---     USER ROUTINE FOR CUTS AND INTERACTIVE DECISION MAKING.
C---
      IMPLICIT INTEGER*2 (H)
#include "cdata.for"
C---
      COMMON /CTLIM/ ISECLF
      DIMENSION IGG(30)
      DATA NREC/ 0/
C---
C        INDEX=0   INITIAL CALL, BEFORE FIRST EVENT READ.
C              1   CALLED AT THE BEGINNING OF EACH NEW RUN.
C              2   CALLED IMMEDIATELY AFTER EVENT IS READ INTO CDATA.
C              3   LEAD GLASS ENERGIES HAVE BEEN COMPUTED.
C              4   FAST Z VERTEX RECONSTRUCTION HAS BEEN DONE.
C              5   INNER DETECTOR PATTERN RECOGNITION HAS BEEN RUN.
C              6   ENERGIES CLUSTERS IN THE LEAD GLASS HAVE BEEN FOUND.
C              7   TRACKS AND CLUSTERS HAVE BEEN ASSOCIATED.
C              8   MUON CHAMBER TRACKING HAS BEEN DONE.
C              9   MUON AND INNER DETECTOR TRACKS HAVE BEEN ASSOCIATED.
C             10   UNUSED
C             11   WRITE EVENT IMMEDIATELY WITHOUT FURTHER ANALYSIS.
C             12   END PROGRAM.
C---
C---     CHECK WHETHER CALL AT END OF JOB
      IF(INDEX.EQ.100) GOTO 1100
C
      GO TO (1001,1002,1003,1004,1005,1006,1007,1008,1009,1010),INDEX
C---
C---     INDEX=0 INITIALIZATION.
C---
      ISECLF=5
      IHEAD=IBLN('HEAD')
      IJETC=IBLN('JETC')
      IJHTL=IBLN('JHTL')
      IPATR=IBLN('PATR')
      NWRIT=0
      DO 3910  I = 1,30
3910  IGG(I) = 0
      INDEX=INDEX+1
      RETURN
C
 1001 CONTINUE
      IHHEAD=2*IDATA(IHEAD)
      NRUN=HDATA(IHHEAD+10)
      INDEX=INDEX+1
      RETURN
C
 1002 CONTINUE
      NREC=NREC+1
      IHHEAD=IDATA(IHEAD)*2
      NEVT=HDATA(IHHEAD+11)
C
C     NO NEW PATREC IF NO PATR-BANK OR NO TRACKS
C
      IPPATR=IDATA(IPATR)
      IGG(1) = IGG(1) + 1
C     IF(IPPATR.LE.0) GO TO 11
C     IF(IDATA(IPPATR+2).LE.0) GOTO 11
C
C     CHANGED TO NO PATREC IF OLD EXISTS 18.5.81 A. PETERSEN
      IF(IPPATR.GT.0.AND.IDATA(IPPATR+2).GT.0) IGG(2) = IGG(2) + 1
      IF(IPPATR.GT.0.AND.IDATA(IPPATR+2).GT.0) GOTO 11
C
      IPJETC=IDATA(IJETC)
      IF(IPJETC.LE.0) WRITE(6,100) NREC,NRUN,NEVT
  100 FORMAT(1X,' NO JETC BANK. SEQ NO. RUN AND EVENT = ',3I6)
      IF(IPJETC.LE.0) IGG(3) = IGG(3) + 1
      IF(IPJETC.LE.0) GO TO 11
      IGG(4) = IGG(4) + 1
      NA=IDATA(IPJETC-3)
      NR=IDATA(IPJETC-2)
      IPJETC=IDATA(IPJETC-1)
C     IF(IPJETC.LE.0) WRITE(6,101) NREC,NRUN,NEVT
C 101 FORMAT(1X,' NO SECOND JETC BANK. SEQ NO. RUN AND EVENT = ',3I6)
      IF(IPJETC.LE.0) IGG(5) = IGG(5) + 1
      IF(IPJETC.LE.0) GO TO 13
      CALL BDLS(NA,NR)
   13 CONTINUE
      IPJHTL=IDATA(IJHTL)
      IF(IPJHTL.LE.0) GO TO 14
      NA=IDATA(IPJHTL-3)
      NR=IDATA(IPJHTL-2)
      CALL BDLS(NA,NR)
      GO TO 13
   14 CONTINUE
      IPPATR=IDATA(IPATR)
      IF(IPPATR.LE.0) GO TO 15
      NA=IDATA(IPPATR-3)
      NR=IDATA(IPPATR-2)
      CALL BDLS(NA,NR)
      GO TO 14
   15 CONTINUE
      CALL BGAR(IGA)
      IF(IGA.NE.1) IGG(6) = IGG(6) + 1
      IF(IGA.NE.1.AND.IPJETC.GT.0) IGG(7) = IGG(7) + 1
      IF(IGA.NE.1.AND.IPJETC.GT.0) WRITE(6,102) IGA,NREC,NRUN,NEVT
  102 FORMAT(1X,' BGAR ERROR     ',I6,'    SEQ NO RUN AND EVT = ',3I6)
      CALL JETCAL
      IND=0
      CALL PATREC(IND)
      GO TO 11
C
 1003 CONTINUE
      INDEX=INDEX+1
      RETURN
C
 1004 CONTINUE
      INDEX=INDEX+1
      RETURN
C
 1005 CONTINUE
      INDEX=INDEX+1
      RETURN
C
 1006 CONTINUE
      INDEX=INDEX+1
      RETURN
C
 1007 CONTINUE
      INDEX=INDEX+1
      RETURN
C
 1008 CONTINUE
      INDEX=INDEX+1
      RETURN
C
 1009 CONTINUE
      INDEX=INDEX+1
      RETURN
C
 1010 CONTINUE
      INDEX=INDEX+1
      RETURN
C---     END OF JOB: FINAL CALCULATIONS + PRINTOUT
 1100 CONTINUE
      WRITE(6,1291) IGG
1291  FORMAT(' IGG ',10I8)
      RETURN
C---
C---     RETURNS FOR STEERING ANALYSIS TO DESIRED NEXT STEP.
C---     'GO TO 1' MEANS REJECT EVENT AND GO TO NEXT EVENT.
C---
    1 CONTINUE
      INDEX=1
      RETURN
    2 CONTINUE
      INDEX=2
      RETURN
    3 CONTINUE
      INDEX=3
      RETURN
    4 CONTINUE
      INDEX=4
      RETURN
    5 CONTINUE
      INDEX=5
      RETURN
    6 CONTINUE
      INDEX=6
      RETURN
    7 CONTINUE
      INDEX=7
      RETURN
    8 CONTINUE
      INDEX=8
      RETURN
    9 CONTINUE
      INDEX=9
      RETURN
   10 CONTINUE
      INDEX=10
      RETURN
   11 CONTINUE
      INDEX=11
      RETURN
   12 CONTINUE
      INDEX=12
      RETURN
      END
