*****************************************************************************
      INTEGER FUNCTION MYDECTRK()
c
      IMPLICIT NONE
C
      INCLUDE 'COMMON.TXT'
C
      DOUBLE PRECISION al_p(5),
     &     xout(22),yout(22),zin(22)
C
      REAL ZALIG, DISTX
      REAL PIANO(22)
C
      INTEGER m, i, IFAIL
C
      REAL hmemor(9000000)
      INTEGER Iquest(100)
C
      COMMON / pawcd / hmemor
      save / pawcd /
C
      Common / QUESTd / Iquest
      save / questd /
C
C Begin !
C
      MYDECTRK = 0
C
C Z positions where to calculate the track
C
      PIANO(1) = 0.
      DO I = 2, 22
         IF ( MOD(I,2).EQ.0 ) THEN 
            PIANO(I) = PIANO(I-1) - 8.09
         ELSE
            PIANO(I) = PIANO(I-1) - 10.09
         ENDIF 
      ENDDO
      ZALIG = -263.
C
C     BEGIN WITH THE FISRT TRACK 
C
 10   CONTINUE
C     
C     COPY THE ALFA VECTOR FROM AL_PP TO AL_P FOR THE TRACK "T"
C     
      do m = 1, 5
         al_p(m) = al_pp(m)
      enddo
      if (al_p(5).eq.0.) THEN
      PRINT *,' MYDETECTOR2 - WARNING F77: track with R = 0, discarded'
         GOTO 969
      ENDIF
C
C     CALL THE TRACKING ROUTINE
C
      DO M = 1,2
         DO I = 1,22     
            XOUT(I) = 0.
            YOUT(I) = 0.
            IF (MOD(M,2).EQ.0) THEN
               DISTX = PIANO(I) + ZALIG 
            ELSE
               DISTX = PIANO(I) - 5.81 + ZALIG 
            ENDIF               
            ZIN(I) = distx / 10.
         enddo
         IFAIL = 0
         call DOTRACK(22,ZIN,XOUT,YOUT,AL_P,IFAIL)
         if(IFAIL.ne.0)then
            GOOD = 0
            print *,' MYDETECTOR2 - WARNING F77: tracking failed '
            goto 969
         endif
         DO I = 1, 22
C     
C     CHECK IF XOUT OR YOUT ARE NaN
C     
            IF (XOUT(I).NE.XOUT(I).OR.YOUT(I).NE.YOUT(I)) THEN
               print *,
     &         ' MYDETECTOR2 - WARNING F77: tracking error (NaN values)'                  
               GOTO 969
            ENDIF
C     
         ENDDO
      ENDDO
 969  continue
      
C     

C
C     HERE WE DETERMINE TRACK-RELATED VARIABLES
C
      MYTRKVAR = 18.

 50   CONTINUE
C
      RETURN
      END


