C   14/03/84 508301932  MEMBER NAME  GGCCTL   (S)           FORTRAN
C   28/09/78 001101647  MEMBER NAME  GGCCTL   (S)           FORTRAN
      SUBROUTINE GGCCTL(*)
C
C     H.WRIEDT      16-11-78  14:30
C     LAST MODIFICATION   10.01.80  16:50
C
C     ORIGINALLY WRITTEN AS 'LGCCTL' BY S.YAMADA
C     AS TO BE FOUND ON YAMLGSRC.S
C
C
C---  CONTROL SUBROUTINE FOR GGCLUS
C---  THIS IS CREATED TO FIND CLUSTERS IN THE TWO FORWARD LG-DETECTORS
C---  SEPARATELY
C
      IMPLICIT INTEGER*4 (G), INTEGER*2 (H)
      LOGICAL LCOLIN
C
      COMMON /CWORK/ IWORK1(42),LNG,HPOINT(4),HGGADC(2,192),IWORK2(263),
     &               ID,HTRACK(3),HCLST,HCLBEC(2),HNCLST,HCOL,HTYPE,HER,
     &               HCORR,HPBLAT,HDUMIN(2),HSCAL(36),HWORD(2),ACOLAN,
     &               ETOT(3),ENTOT(3),IWORK3(16),HCLMAP(2,51),
     &               CLSPRP(13,51),IWORK4(16),HLUADC(16),HACC,HWORK1,
     &               IWORK5(611),HSMADC(14),LCOLIN
C***  COMMON /CGGADC/ LNG,HPOINT(4),HGGADC(2,192)
C***  COMMON /CLUADC/ HLUADC(16)
C***  COMMON /CGGADD/ HSMADC(14)
      COMMON /CGGPRM/ ITH,MAXCLS
C***  COMMON /CGGCLS/ NCLST,NCLBEC(2),HCLMAP(2,51),CLSPRP(10,51),ACOLAN,
C*** &                LCOLIN
C
C---- HCLST = NO.OF THE LOCATED CLUSTERS.
C---- HCLMAP(J)=THE INDEX OF THE FIRST MEMBER OF THE J-TH CLUSTER
C               IN THE HGGADC.
C
      DIMENSION GGADC(192)
      EQUIVALENCE (GGADC(1),HGGADC(1,1))
      DIMENSION IHIT(2), HIT(2)
C
      DATA ICOUNT/0/
C
      COMMON/ CGGVRN/ NVRSN(20)
      DATA NVCODE/178120712/
      NVRSN(6) = NVCODE
C
C---  EVENTS WITH NO BLOCKS ARE REJECTED HERE
CCC*  MESSAGE FOR THE CALLING PROGRAM HAS TO BE FORESEEN YET
      IF(LNG.LE.2) RETURN
      IERT = 0
C
C---- SORT ADC-DATA IN ADDRESS ORDER  (RAW DATA SHOULD BE IN ORDER  BUT
C                           TO MAKE IT SURE)
CCC   CALL GGSORT
C
C---  POINTERS
C---  HPOINT(1): FIRST ADDRESS OF -Z-DETECTOR PART (ALWAYS 1)
C---  HPOINT(2): FIRST ADDRESS OF +Z-DETECTOR PART
C---  HPOINT(3): FIRST ADDRESS OF LUMINOSITY COUNTERS
C---  HPOINT(4): LAST ADDRESS + 1
C
C---  SEPARATE ADCS OF LUMINOSITY COUNTERS AND LEAD GLASS SUMS
      INDI = (HPOINT(3)+1)/2
      INDF = (HPOINT(4)-1)/2
      IF (INDF.LT.INDI) GOTO 69
        DO 60 I = INDI,INDF
        HADDR = HGGADC(1,I)
        IF (HADDR.LE.191) GOTO 68
        IF (HADDR.GE.208) GOTO 61
        HLUADC(HADDR-191) = HGGADC(2,I)
        GOTO 60
   61   IF (HADDR.LE.215.OR.HADDR.GE.230) GOTO 68
        HSMADC(HADDR-215) = HGGADC(2,I)
        GOTO 60
   68   ICOUNT = ICOUNT + 1
        IF (ICOUNT.GT.20) GOTO 60
        WRITE(6,601) HADDR,HGGADC(2,I),HPOINT
  601   FORMAT(' *** SEVERE ADDRESS ERROR DETECTED IN GGCCTL: ',6I10)
   60   CONTINUE
      LNG = INDI + 1
   69 CONTINUE
C
C---  CHECK WHETHER MIRROR-IMAGE BLOCK (ON OPPOSITE SIDE) IS HIT TOO,
C---  THEN: 'LCOLIN = .TRUE.'
C---  LOOP IS LEFT AFTER THE FIRST FOUND PAIR OF BLOCKS,
C---  EVEN IF THERE ARE MORE
        DO 30 JP = 1,2
        HIT(JP) = (HPOINT(JP+1)-HPOINT(JP))/2
 30     IHIT(JP) = (HPOINT(JP)+1)/2
C
C---  LOOKING FOR COLLINEAR BLOCKS ONLY DONE FOR EVENTS WITH NO TAGGING
C     TRIGGER
      IF (HACC.NE.0) GOTO 10
C
      NHIT1 = HIT(1)
      NHIT2 = HIT(2)
      IHIT1M = IHIT(1)-1
      IHIT2M = IHIT(2)-1
      LCOLIN = .FALSE.
      IF (NHIT1.LT.1) GOTO 10
      NHIT2L = IHIT2M+NHIT2
        DO 50 NN1 = 1,NHIT1
        IF (NN1.GT.NHIT2L) GOTO 10
          DO 50 NN2 = 1,NHIT2
          IF (HGGADC(1,IHIT1M+NN1).NE.(HGGADC(1,IHIT2M+NN2)-96)) GOTO 5000010300
          LCOLIN = .TRUE.
C         WRITE(6,600) HGGADC(1,IHIT1M+NN1)
 600      FORMAT(' ','AT LEAST ONE COLINEAR PAIR OF BLOCKS IS HIT',
     &           '(BLOCK NO.',I3,')')
          GOTO 10
 50     CONTINUE
C
C---- CLUSTER FINDING IS DONE FOR EACH DETECTOR SEPARATELY
   10   DO 20 JP=1,2
        NHIT = HIT(JP)
        INIT = IHIT(JP)
        CALL GGCLUS(JP,INIT,NHIT,IER)
        IERT = IERT+IER
   20   CONTINUE
C---  REWRITE POINTERS AFTER LUMINOSITY ADCS ARE TAKEN OUT
C***  BE CAREFUL, HPOINT(3) AND HPOINT(4) ARE INTERCHANGED ACCORDING
C***  TO THE ORIGINAL JADE-COMPUTER NOTE #16
      HPOINT(4) = 0
C
      HCLBEC(2) = HCLBEC(2)-HCLBEC(1)
      IF(IERT) 101,100,101
  100 RETURN
  101 RETURN 1
      END
