C   11/12/78 003112237  MEMBER NAME  LGAVDE   (SOURCE)      FORTRAN
      SUBROUTINE LGAVDE(ZAV,NPCLS,JEG,DEP)
C
C     S.YAMADA  11-12-78  14:55
C     LAST MODIFICATION    08-03-79   22:35
C     LAST MODIFICATION    13-09-79   20:00 BY Y.WATANABE
C
C----   AVERAGE DEPTH OF THE SHOWER IS CALCULATED BY ITERATION.
C                    FOR END CAP PARTS
C
      IMPLICIT INTEGER *2 (H)
C
      COMMON /BCS/ IDATA(6000)
      INTEGER *2 HDATA(12000)
      REAL ADATA(6000)
      EQUIVALENCE (HDATA(1),IDATA(1)), (ADATA(1),IDATA(1))
      COMMON /CLGDMS/ X0,RADIUS(6),RADSX0(6),THX0(4),
     $                ZEND(2),ZENDX0(2),ZWID(2),ZGAP(2),PHWID(2),
     $                ZECAP(4),ZECAPX(4),THECPX(2)
C
      COMMON /CLGPRM/ ITH,MAXCLS,IRLTHD,IRLTH2,IRLTH3, ZVRTX
      COMMON /CLGMSB/ MSGVAL,AMSGV1,AMSG2
      DATA JEGBB/1/
C     SPECIAL VERSION FOR BHABHA
C
      EMEV =ADATA(NPCLS+2)*1000.
      ZAV1 = ABS(ZAV-ZVRTX)
      DEPO = 0.
      R2   = ADATA(NPCLS+4)**2+ADATA(NPCLS+5)**2
C
C---- AVERAGE SHOWER DEPTH ALONG THE AXIS = SM
      SM = SHMAX(EMEV,JEGBB)
C
      NTRY = 0
    4 NTRY = NTRY+1
      IF(NTRY.GT.20) GO TO 21
      DEP = SM/SQRT(1.0+R2/(ZAV1+DEPO)**2)
      IF(ABS(DEP-DEPO)/DEP.LE.0.01) GO TO 3
      DEPO = DEP
      GO TO 4
C
   21 MSGVAL = NTRY
      AMSGV1 = DEPO
      AMSGV2 = DEP
      CALL LGMESG( 10,1)
C
    3 RETURN
      END
