C   12/03/84 412051637  MEMBER NAME  TAGSUM   (S)           FORTRAN
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C
C    THIS SUBROUTINES SUMS ALLL ADC DATA IN ARRAY CATAG ONE END OR THE
C    OTHER TO GIVE THE VALUE OF SUM.
C
C JPART - INPUT - SIGN DETERMINES WHICH END TAGGER IS ANALYSED
C                  JPART > 0 = > +Z
C                  JPART < 0 = > -Z
C
C  SUM - OUTPUT - SUM OF ENERGY
C
C RETURN 1 IF SUM IS A CRAZY VALUE
C
C   A.J.FINCH  10/12/92
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C
       SUBROUTINE TAGSUM(JPART,SUM,*)
C
C-----------------------------------------------------------------------
C                            MACRO CGRAPH .... GRAPHICS COMMON
C-----------------------------------------------------------------------
C
      LOGICAL DSPDTL,SSTPS,PSTPS,FREEZE
C
      COMMON / CGRAPH / JUSCRN,NDDINN,NDDOUT,IDATSV(11),ICREC,MAXREC,
     +                  LSTCMD,ACMD,LASTVW,ISTANV,
     +                  SXIN,SXAX,SYIN,SYAX,XMIN,XMAX,YMIN,YMAX,
     +                  DSPDTL(30),SSTPS(10),PSTPS(10),FREEZE(30),
     +                  IREADM,LABEL,LSTPS(10),IPSVAR
C
C------- END OF MACRO CGRAPH -------------------------------------------
C
C
C
C
C------------ C O M M O N    C W O R K   F O R   T A G A N -------------
C
C
       COMMON/CWORK/MARK,IFLMRK,IMC,NCLST,NNEI,
     *              ISTMZ,ISTPZ,IENDMZ,IENDPZ,
     *              SIGX,SIGY,SIGEN,
     *              CAND(3),CLUS(9,2),CMAP(10,9),
     *              SADC(32,2),CATAG(192)
C
C
C CWORK - WORKSPACE USED ONLY ONCE PER EVENT FOR INTERNAL PROCESSING
C ==================================================================
C
C MARK   ->  WHICH 'MARK' OF TAGGER - 1 = 1981,2
C                                   - 2 = 1983 ONWARDS
C
C IFLMRK ->  SET TO '1' BY TAGMRK
C
C IMC    ->  SET TO '1' BY TAGMRK IF MC DATA
C
C CATAG  ->  CONTAINS THE ADC CONTENTS UNPACKED FROM ATAG
C
C SADC   ->  COMMON FOR ADC'S AFTER SORTING  (SORT 1)
C
C CMAP(I,1...9) ->  ADDRESS OF ADC'S IN CLUSTER I,SORT23 PUTS THESE IN
C                   ORDER OF ENERGY.
C
C CAND(3) ->  X, Y, AND ENERGY OF A FOUND CLUSTER IN AFTER CLSPS
C
C SIGX,SIGY,SIGEN ->  ERROR ON X, Y, AND ENERGY AFTER CLSPS
C
C CLUS(9,2) ->  ADC ADDRESS AND CONTENTS OF CLUSTERS - SORTED BY ENERGY
C
C NCLST   ->  NUMBER OF CLUSTERS THIS END
C ISTMZ   ->  POINTER TO START OF -Z DATA IN CATAG ( ALWAYS  1       )
C ISTPZ   ->  POINTER TO START OF +Z DATA IN CATAG ( EITHER 33 OR 25 )
C IENDMZ  ->  POINTER TO   END OF -Z DATA IN CATAG ( EITHER 32 OR 24 )
C IENDPZ  ->  POINTER TO   END OF +Z DATA IN CATAG ( EITHER 64 OR 48 )
C
C A.J.FINCH 24/2/84
C MODIFIED 12/3/84 CATAG PUT TO END AND INCREASED TO 192
C  TO ALLOW IT TO BE USED FOR 1979,80 TAGGER IN GRAPHICS
C LAST MOD : J. NYE  30/05/84  RE-ORGANIZED INCLUDING IFLMRK
C
C
C-----------------------------------------------------------------------
C
C
       DATA ICOUNT / 0 /
C
C = == CODE ===
C
C GET THE RELEVANT POINTERS
C
       ISTART = ISTMZ
       IEND   = IENDMZ
       IF ( JPART .GT. 0 ) ISTART = ISTPZ
       IF ( JPART .GT. 0 ) IEND   = IENDPZ
C
C CALCULATE SUM
C
       SUM = 0.0
       DO 10 I = ISTART,IEND
          SUM = SUM + CATAG(I)
 10    CONTINUE
       IF ( (SUM .LT. 50000.0) .AND. (SUM .GE. 0.0) ) RETURN
C
C
C----------------------------------- ERROR MESSAGES -------------------
C
C
       IF ( NDDINN .NE.  0 ) RETURN 1
       IF ( ICOUNT .GE. 10 ) RETURN 1
       WRITE(6,600) SUM
 600   FORMAT(/,' *** WARNING MESSAGE FROM TAGGING ROUTINE - TAGSUM -',
     *        /,'  SUM HAS A CRAZY VALUE  ',E10.2)
       WRITE(6,603)
 603   FORMAT(1X,' LARGE VALUES MAY BE CAUSED BY DIRTY',
     *           ' BEAM CONDITIONS OR EXTREME PEDESTAL FLUCTUATION')
       WRITE(6,602)
 602   FORMAT(1X,' RAW TAGGING ADC BANK -ATAG- WILL BE PRINTED ',/,/)
       CALL HPRS('ATAG',0)
       ICOUNT = ICOUNT + 1
       IF ( ICOUNT .EQ. 10 ) WRITE(6,601)
 601   FORMAT(' * NO MORE ERROR MESSAGES FROM TAGSUM WILL BE PRINTED')
       RETURN 1
       END
