C   09/03/79 008180717  MEMBER NAME  @LGTEST                FORTRAN
C
C    S.YAMADA   09-03-79  10:25
C     LAST MODIFICATION   09-03-79  23:25
C
C---- SIMPLE TEST PROGRAM FOR LGANAL FOR REAL DATA.
C
C
      IMPLICIT INTEGER *2 (H)
C
      COMMON /BCS/ IDATA(24000)
      DIMENSION  ADATA(24000),HDATA(48000)
      EQUIVALENCE (IDATA(1),ADATA(1)), (HDATA(1),IDATA(1))
C
#include "clgwork1.for"
C
      COMMON /CLGPRM/ ITH,MAXCLS,IRLTHD,IRLTH2,IRLTH3, ZVRTX,DZ
C
      COMMON /CLGMSB/ MSGVAL(5)
      COMMON /CTPCNS/ EBMGEV, BKGAUS
      DATA HRAN/0/
C
C---- INITIALIZATION
      DATA NUNITO,RPATR,RHEAD,RALGN,RLGCL/2,4HPATR,4HHEAD,4HALGN,4HLGCL/
      DATA RTRIG/4HTRIG/
      CALL BINT(24000,4000,500,0)
      CALL BINT1(200,100,10,0)
C     CALL BWRO( NUNITO, 1558, 2)
C        SET UP POINTERS BEFOREHAND
          IPHEAD = IBLN(RHEAD)
          IPTRIG = IBLN(RTRIG)
          IPPATR = IBLN(RPATR)
          IPALGN= IBLN(RALGN)
          IPLGCL= IBLN(RLGCL)
C
      CALL LGINIT
C     ITH = 45
C
C
        DO 1000 N=1,50
C       NTIM=JUHR(2)
C       IF(NTIM.EQ.2) GO TO 300
C
        DATA NUNITI/1/
        CALL BREAD(NUNITI,&200,&200)
C----   TEMPORARY SUBROUTINE TO MODIFY THE M.C. 'PATR' FORMAT.
C
C        CALL HPRS(RHEAD,0)
          NPHEAD = IDATA(IPHEAD)
          IF(NPHEAD.LE.0) GO TO 20
          NHHEAD = NPHEAD+NPHEAD
          HEXP=HDATA(NHHEAD+ 9)
          HRUN=HDATA(NHHEAD+10)
          CALL KALIB2
          HRAN=HRUN
        NPTRIG=IDATA(IPTRIG)
        IF(NPTRIG.LT.1) GO TO 20
        HBIT  =HDATA(NPTRIG+NPTRIG+10)
      WRITE(6,6000) N,HEXP,HRUN,HDATA(NHHEAD+11),HBIT
 6000 FORMAT(1H0,20(1H*),'REC#,EXP,RUN,EV#,TRG',4I6,Z8,50(1H*),/)
C
C
C----     TEST DUMP
         CALL PRALGN(0,0,10)
C        CALL PRALGN(1,0,10)
         CALL LGCALB(&20)
         CALL PRALGN(1,0,10)
C     IF(II.EQ.II) GO TO 20
C     PRALGN(I,J,K); I;0='ALGL'/0, 1='ALGN'/1
C                    J;0=NODECODING, 1=CRATE-SLOT, 2=IPHI-Z
C                    K=NO. DATA TO BE PRINTED PER LINE
          NPPATR = IDATA(IPPATR)
C       CALL PRLGCL
        CALL LGANAL
C
C----   DUMP THE RESULTS
CCCC    CALL LGSHOW
C       CALL LGADCD(2,5)
C       CALL PRALGN(1,0,10)
C       CALL PRALGN(1,2,10)
C
C----   CLUSTER DUMP
C       CALL PRLGCL
C
C----   SECOND STEP ANALYSIS
C       POINTERS OF THE NECESSARY BANKS
        NPALGN =IDATA(IPALGN)
        NPLGCL=IDATA(IPLGCL)
        IF(NPLGCL) 90,90,10
C
C----   SOME BANK IS MISSING
   90   MSGVAL(1) =  NPPATR
        MSGVAL(2) =  NPALGN
        MSGVAL(3) =  NPLGCL
        CALL LGMESG( 1, 2 )
        GO TO 20
C
   10   CALL LGCDIR( NPPATR, NPALGN, NPLGCL )
C
C       CALL BPRS(RPATR,NNN)
C       PRINT INNER DET.CHARGE TRACK TRACING RESULT
        CALL PRCLGC
C----   PRINT CHARGE AND LG-CLUSTER MATCHING TABLE
C       CALL PRITOL(3)
CCC     CALL PRCLGC
C       CALL PRLGCL
C       CALL LGESHW
        CALL PRLGCL
C----               PRINT 'PATR'
C                   NNN = IDATA(NPPR-2)
C                   CALL BPRS(RPATR,NNN)
C
20      CONTINUE
C       CALL BSLW
C       CALL BFIXP
C       CALL BWRITE(NUNITO)
        CALL BSLT
        CALL BDLG
C
 1000   CONTINUE
C//////////////
CCCC  CALL TMLOG(0)
C//////////////
      GO TO 100
  200 MSGVAL(1) = N
      CALL LGMESG( 1,1 )
      GO TO 100
300   WRITE(6,6200) N,(HDATA(HNPHD+J),J=9,11)
6200  FORMAT(' TIME OUT AT REC#,EXP#,RUN#,EV#',10I6)
100   CONTINUE
C     CALL BMLT(0,DUMMY)
C     CALL BFIXP
C     CALL BWRITE(NUNITO)
      CALL BSLT
      CALL BDLG
      STOP
      END
