C   08/09/82 209092236  MEMBER NAME  LGBTDCA  (S)           FORTRAN
      SUBROUTINE LGBTDC( CBTDC, JFLLGT )
C
C     S.YAMADA   09-05-82   12:00      COPIED FROM F22YAM.PHANAL.S
C                                      ON 27-05-82
C     LAST MOD.  09-09-82  17:55       COPIED FROM F22YAM.LGCALIB.S
C
C---- LG-BARREL TOF
C
#include "cdata.for"
C
      INTEGER *4 NRUNBN(5)/2010241,2010263,2010361,2011440,2011803/
      DATA NMAX/5/
      REAL       TBASE(5)/   52.66,  92.69,  70.74,  91.80,  90.47/
C
      DATA ISTART/0/
      IF( ISTART ) 1001,1000,1001
 1000 WRITE(6,600)
  600 FORMAT('0 FOR LGB-TDC NEW VERSION (LGBTDCA) IS USED.',/)
      ISTART = 1
C
 1001 CBTDC = 0.
      JFLLGT = 0
C
C---- RUN NUMBER
      NPHD2 = 2*IDATA( IBLN('HEAD') )
      IF( NPHD2.LE.0 ) GO TO 90
      NRUN = HDATA(NPHD2+9)*100000 + HDATA(NPHD2+10)
      IF( NRUN.LT.2010055 ) GO TO 90
C---- TOTAL BARREL ENERGY
      NPCL = IDATA( IBLN('LGCL') )
      IF( NPCL.LE.0 )  GO TO 90
C     GET THE RUN-BIN NUMBER
        DO 1 N=1,NMAX
        IF( NRUN.LE.NRUNBN(N) ) GO TO 2
    1   CONTINUE
C
C---- CALIBRATION IS NOT READY YET.
      IFLLGT = 1
      N = NMAX
C
    2 TBASEN = TBASE(N)
C
C---- 'ATST' BANK
      NPATST = IDATA( IBLN('ATST') )*2
      IF( NPATST.EQ.0 ) GO TO 90
      BTDC = HDATA( NPATST+17 )
C---- CORECTION OF SLEWING
      ETOTB = ADATA( NPCL+12 )
      IF( ETOTB.LE.0. ) ETOTB = 0.045
CCC   CBTDC = 0.1*BTDC -33.25/SQRT(ETOTB) + 0.36*ETOTB -TBASEN
      CBTDC = 0.1*BTDC -33.25/SQRT(ETOTB) + 0.24*ETOTB -TBASEN
C
C---- CORECTION OF THETA.
      CALL CLOC( NPCL, 'LGCL', 1)
      NCLSB = IDATA(NPCL+8)
      IF( NCLSB.LE.0 ) GO TO 100
      IP3 = NPCL+IDATA(NPCL+3)-1
      NSTEP = IDATA(NPCL+25)
      ESHS = 0.
      ESTHS = 0
        DO 3 N=1,NCLST
        NB = IP3+(N-1)*NSTEP
        IF( IDATA(NB+1).NE.0 ) GO TO 4
        ESHS = ESHS + ADATA(NB+16)
        ESTHS = ESTHS + ADATA(NB+16)*ABS(ADATA(NB+11))
    3   CONTINUE
    4 IF(ESHS.LE.0 ) GO TO 90
      AVTH = ESTHS/ESHS
      DTTHET = 10.0/SQRT(1.0-AVTH**2)-10.0
      CBTDC = CBTDC-DTTHET
C
C---- TEST PLOT
CCC   CALL HFILL( 11, CBTDC, AVTH, 1.0)
C
  100 RETURN
C
   90 JFLLGT = 2
      RETURN
      END
