SUBROUTINE FILHTS
*-- Author :    Stephen J. Maxfield   21/11/92
        SUBROUTINE FILHTS(ITRK, ILIST,
     +               NMRAD, IRPNT, IRSGN, IFRP,                         
     +               NMPLA, IPPNT, IPSGN, IFPP,                         
     +               ZBEG)                                              
*                                                                                                             
*     Builds lists of pointers into FRRE and FRPE banks for                                                   
*     hits on the track ITRK. ILIST tells which pointers to go                                                
*     for (rad-based tracks or pla-based tracks.                                                              
*                                                                                                             
*     The first radial and planar hit is found and the Z of the                                               
*     first hit (radial or planar) on the track (where the track                                              
*     parameters will be given)                                                                               
*                                                                                                             
*                                                                                                             
*                                                                                                             
*KEEP,BOSMDL.                                                                                                 
C     ------BOSMDL                                                                                            
      LOGICAL       BEGJOB,ENDRUN,BEGRUN,REVENT,ENDJOB,OTHDAT           
      COMMON/BOSMDL/BEGJOB,ENDRUN,BEGRUN,REVENT,ENDJOB,OTHDAT,          
     +              LCCRUN,NCCRUN,NEVENT,                               
     +              IHA,IBS,IDB,IDATEL,LUP,ISN,JSN                      
      SAVE  /BOSMDL/                                                    
C     ------                                                                                                  
*KEEP,FRDIMS.                                                                                                 
      PARAMETER (MAXHTS=200)                                            
      PARAMETER (NUMWPL=36)                                             
      PARAMETER (MAXTRK=200)                                            
      PARAMETER (MXTTRK=900)                                            
      PARAMETER (MAXTR3=200)                                            
      PARAMETER (MAXHPW=2)                                              
      PARAMETER (MAXDIG=2000)                                           
      PARAMETER (NUMRWR=1727)                                           
      PARAMETER (NUMPWR=1151)                                           
*KEEP,FH1WORK.                                                                                                
       COMMON/FGMIOS/                                                   
*    Planar geometry                                                                                          
     + ZPP(140),C(140),S(140),ITYPE(140),WZERO(140),WSPACE,             
*                                                                                                             
*    Radial geometry                                                                                          
     + ZP(36),PHW(36),WS(36)                                            
*                                                                                                             
       COMMON/H1WORK/                                                   
*    Radial data...                                                                                           
     + WW(MAXHTS,36),DRI(MAXHTS,36),RM(MAXHTS,36),                      
     + NDP(36),  NW(MAXHTS,36), DWS(MAXHTS,36),                         
*                                                                                                             
*    Planar Data                                                                                              
     + NDPW(NUMWPL),DW(MAXHTS,NUMWPL),                                  
     + DRIW(MAXHTS,NUMWPL),NDW(MAXHTS,NUMWPL),                          
     + WWP(MAXHTS,NUMWPL),                                              
     + IPHOLE(MAXHTS,NUMWPL),                                           
*                                                                                                             
*    Pointers into DIGI bank for IOS labelled hits                                                            
     +  IPFRRE(MAXHTS,36),IPFRPE(MAXHTS,36),NFRRE,NFRPE,                
     +  IRPIOS(MAXDIG,2), IPPIOS(MAXDIG,2),                             
*                                                                                                             
*    Track segment data                                                                                       
     + NTRAKS(3),IRPT(12,MAXTRK,3),SDRFT(12,MAXTRK,3),                  
*                                                                                                             
*    Fit data                                                                                                 
     + PCOSL(MAXTRK,3),PSINL(MAXTRK,3),PHZL(MAXTRK,3),                  
     + DPCOSL(MAXTRK,3),DPSINL(MAXTRK,3),                               
     + DPHZL(MAXTRK,3),CHSQ(MAXTRK,3),RZI(MAXTRK,3),                    
     + RPCOSG(MAXTRK),RPSING(MAXTRK),                                   
     + PHZG(MAXTRK),CC(3,MAXTRK),ZIG(MAXTRK),                           
     + IRADG(36,MAXTRK),PHIG(36,MAXTRK),                                
     + IG,SDRADG(36,MAXTRK),                                            
     + R1,Z1,RFIT(MAXTRK,3),                                            
     + CHG(MAXTRK),                                                     
     + PPA(MAXTRK,3),  ZZA(MAXTRK,3),                                   
     + GPA(MAXTRK,3),GZA(MAXTRK,3)                                      
*                                                                                                             
*                                                                                                             
*KEEP,FRH3FT.                                                                                                 
*     Common for RETRAC results (SJM)                                                                         
      COMMON/FRH3FT/ IRN(36,MAXTRK),SDN(36,MAXTRK),                     
     +              IRP(36,MAXTRK),SDP(36,MAXTRK),                      
     +              IG2,IGTTRK(MAXTRK),                                 
     +              CHISQ(MAXTRK),NUMDF(MAXTRK),                        
     +              FITX(MAXTRK),FITY(MAXTRK),FITZ(MAXTRK),             
     +              FITTH(MAXTRK),FITPH(MAXTRK),                        
     +              FITCU(MAXTRK),FTCOV(15,MAXTRK)                      
*KEND.                                                                                                        
      COMMON/FTPPBK/NPP,IPP(36,100),CHPP(100),LP(3,100)                 
      COMMON/FTPPBS/SPP(36,100)                                         
      COMMON/FTRRBK/IRR(36,MAXTRK),SRR(36,MAXTRK),LRR(3,MAXTRK)         
      COMMON/FPLNK/KTIP(3,50),LPP(3,100)                                
      COMMON/FKLOC/KLOC(100)                                            
                                                                        
      DIMENSION IRPNT(36), IPPNT(36)                                    
      DIMENSION IRSGN(36), IPSGN(36)                                    
      IFPP =  0                                                         
      NMPLA=  0                                                         
      IFRP =  0                                                         
      NMRAD=  0                                                         
      ZBEGR = 1000.                                                     
      ZBEGP = 1000.                                                     
      KFPWIR = 1000                                                     
      KFRWIR = 1000                                                     
      DO 200 KMOD=0, 2                                                  
                                                                        
        DO 300 IWIR=1,12                                                
*         Planars                                                                                             
          KWIR   = IWIR + KMOD*12                                       
          IF(ILIST.EQ.1) THEN                                           
           JP     = IRP(KWIR,ITRK)                                      
           SIGP   = SDP(KWIR, ITRK)                                     
          ELSE                                                          
           JP     = IPP(KWIR,ITRK)                                      
           SIGP   = SPP(KWIR, ITRK)                                     
          ENDIF                                                         
                                                                        
          IF( SIGP .GT. 0) THEN                                         
             JPSIGN = 0                                                 
          ELSE                                                          
             JPSIGN = 1                                                 
          ENDIF                                                         
                                                                        
          IF( JP .NE. 0) THEN                                           
           IF(IPFRPE(JP,KWIR) .NE. 0) THEN                              
            NMPLA  = NMPLA  + 1                                         
            IF(IFPP.EQ.0) THEN                                          
              IFPP = IPFRPE(JP,KWIR)                                    
              ZBEGP= ZPP(KWIR)                                          
              KFPWIR = KWIR                                             
            ENDIF                                                       
            IPPNT(NMPLA) = IPFRPE(JP,KWIR)                              
            IPSGN(NMPLA) = JPSIGN                                       
           ELSE                                                         
            CALL ERRLOG(125,'S:FILHTS: Planar pointer list corrupted')                                 
           ENDIF                                                        
          ENDIF                                                         
 300    CONTINUE                                                        
        DO 400 IWIR=1,12                                                
*         Radials                                                                                             
          KWIR = IWIR + KMOD*12                                         
          IF(ILIST.EQ.1) THEN                                           
           JR     = IRN(KWIR,ITRK)                                      
           SIGR   = SDN(KWIR, ITRK)                                     
          ELSE                                                          
           JR     = IRR(KWIR,ITRK)                                      
           SIGR   = SRR(KWIR, ITRK)                                     
          ENDIF                                                         
                                                                        
          IF( SIGR .GT. 0) THEN                                         
             JRSIGN = 0                                                 
          ELSE                                                          
             JRSIGN = 1                                                 
          ENDIF                                                         
                                                                        
          IF( JR .NE. 0) THEN                                           
           IF(IPFRRE(JR,KWIR) .NE. 0) THEN                              
            NMRAD  = NMRAD  + 1                                         
            IF(IFRP.EQ.0) THEN                                          
              IFRP  = IPFRRE(JR,KWIR)                                   
              ZBEGR = ZP(KWIR)                                          
              KFRWIR = KWIR                                             
            ENDIF                                                       
            IRPNT(NMRAD) = IPFRRE(JR,KWIR)                              
            IRSGN(NMRAD) = JRSIGN                                       
           ELSE                                                         
            CALL ERRLOG(126,'S:FILHTS: Radial pointer list corrupted')                                 
           ENDIF                                                        
          ENDIF                                                         
 400    CONTINUE                                                        
                                                                        
 200  CONTINUE                                                          
                                                                        
                                                                        
      ZBEG   = ZBEGP                                                    
      IF(ZBEGR.LT.ZBEGP)ZBEG=ZBEGR                                      
                                                                        
      RETURN                                                            
      END                                                               
*