C   03/10/77 310281222  MEMBER NAME  TRCOIL   (S)           FORTRAN
      SUBROUTINE TRCOIL(PV,R,*)
C
C      TRACK PARTICLES THROUGH  COIL
C      PV = USUAL PARTICLE VECTOR OF DIMENSION 10
C           FIRST FOUR ARE FOURVECTOR COMPONENTS SEE TRCDET
C     R  = THREE DIMENSIONAL RADIUS VECTOR
C     PV AND R ARE OVER WRITTEN UPON RETURN
C
C     TRACKING STOPS IN FRONT OF THE LEAD GLASS, EITHER IN THE
C     CENTRAL PART OR IN FRONT OF THE END CAP BLOCKS
C     RETURN 1 IS USED IF PARTICLES MISS THE LEAD GLASS ARRAYS
C
C   LAST CHANGE 26.10.1983    W. BARTEL
C
C
      COMMON/CGEO1/BKGAUS, RPIP,DRPIP,XRLPIP, RBPC,DRBPC,XRLBPC,
     *             RITNK,DRITNK,XRLTKI, R0ROH,DR0ROH,XR0ROH,
     *             R1ROH,DR1ROH,XR1ROH, R2ROH,DR2ROH,XR2ROH,
     *             R3ROH,DR3ROH,XR3ROH, ROTNK,DROTNK,XRLTKO,
     *             RTOF,DRTOF,XRTOF, RCOIL, DRCOIL, XRCOIL,
     *             ZJM,DZJM,XRZJM, ZJP,DZJP,XRZJP,
     *             ZTKM,DZTKM,XRZTKM, ZTKP,DZTKP,XRZTKP,
     *             ZBPPL,ZBPMI,ZTOFPL,ZTOFMI,
     *             XRJETC,
     *             RLG,ZLGPL,ZLGMI,OUTR2,CTLIMP,CTLIMM,DELFI,
     *             BLXY,BLZ,BLDEP,ZENDPL,ZENDMI,DEPEND,
     *             XHOL1,XHOL2,YHOL1,YHOL2
      DIMENSION PV(10),R(3)
      DATA ITRCL /0/
C
C      DRIFT THROHGH FIELD FREE SPACE
C
      IF( PV(6) .LT. .01 ) RETURN 1
C
      PVX=PV(1)/PV(6)
      PVY=PV(2)/PV(6)
      PVZ=PV(3)/PV(6)
      PVXY=PVX**2+PVY**2
      IF(PVXY.LT.1.E-5) RETURN 1
      R1=R(1)**2+R(2)**2
      DR2=(RLG**2-R1)/PVXY
      PVR=R(1)*PVX+R(2)*PVY
      PVR=PVR/PVXY
      PRVBAR = PVR**2 + DR2
      IF(PRVBAR.GE.0.) GO TO 371
C
C ERROR THAT WILL POSSIBLY LEAD TO NEG. ARGUMENT IN SQRT.
C                                                 26.10.83 W.B.
      ITRCL = ITRCL + 1
      IF(ITRCL.LT.11) WRITE(6,374) R(1),R(2),R(3),(PV(K),K=1,6)
374   FORMAT(' TRCOIL ERROR, R(1),R(2),R(3),P1/6 ',3E12.4)
C
371   XL=-PVR+SQRT(PRVBAR)
C
      R(1)=R(1)+XL*PVX
      R(2)=R(2)+XL*PVY
      R(3)=R(3)+XL*PVZ
C
      IF( ZLGMI.GE.R(3).OR.R(3).GE.ZLGPL ) GO TO 1000
      RETURN
C
C      FOLLOW PARTICLE TO THE FACE OF THE END CAP COUNTERS
C
 1000 CONTINUE
      RABS=0.
      DO 1001 I3=1,3
 1001 RABS=RABS+R(I3)**2
      RABS=SQRT(RABS)
      DO 1002 I3=1,3
 1002 R(I3)=R(I3)/RABS
      ZLAM=ZENDPL/R(3)
      IF( R(3).LT.0. ) ZLAM=ZENDMI/R(3)
      DO 1003 I3=1,3
 1003 R(I3)=ZLAM*R(I3)
      CALL ENDCLG(R,NCL,&9000)
      RETURN
 9000 RETURN1
      END
