SUBROUTINE FFCHTR
*-- Author : Stephen Burke
      SUBROUTINE FFCHTR(JPL,JTYPE,JDIG)
*-----------------------------------------Updates 02/06/92-------                                             
**: FVCHTR.......SB. Change loop indices to please farm.                                                      
*-----------------------------------------Updates 24/01/92-------                                             
**: FFCHTR 30205.SB. Check to see if the drift sign is correct.                                               
*-----------------------------------------Updates----------------                                             
**********************************************************************                                        
*                                                                    *                                        
* Update LTRPL for a new digi (found by FKHUNT)                      *                                        
*                                                                    *                                        
**********************************************************************                                        
                                                                        
*KEEP,FKNPL.                                                                                                  
      CHARACTER*5 CKDBG                                                 
      PARAMETER (CKDBG='FKDBG')                                         
      PARAMETER (NPL=72)                                                
      LOGICAL LTRUE,LFIRST,LTRPL,LTRPLD                                 
      DOUBLE PRECISION TRUE,RTRUE,CHITRU,SPRO,CPRO,SFIL,CFIL            
     &,                SSMT,CSMT,SSMTR,CSMTR,DPRO,CBPRO,QPRO,QGAIN      
     &,                RPRO,CRPRO,RFIL,CRFIL,RSMT,CRSMT,CHIFIL,CHISMT   
*                                                                                                             
* Per-track values can go in H1WORK; note that LTRUE and LFIRST must                                          
* be set at least per event.                                                                                  
*                                                                                                             
* This is about 36k words long; the remaining common blocks are                                               
* about 3.6k in total. Some of this could be in /H1WORK/, but the                                             
* blocks would have to be reorganised.                                                                        
*                                                                                                             
      COMMON /H1WORK/                                                   
* /FKPROJ/                                                                                                    
     &                SPRO(5,NPL),CPRO(5,5,NPL)                         
* /FKFILT/                                                                                                    
     &,               SFIL(5,NPL),CFIL(5,5,NPL)                         
* /FKSMTH/                                                                                                    
     &,               SSMT(5,NPL),CSMT(5,5,NPL)                         
     &,               SSMTR(5,NPL),CSMTR(5,5,NPL)                       
* /FKINT/                                                                                                     
     &,               DPRO(5,5,NPL),CBPRO(5,5,NPL),QPRO(5,5,NPL)        
     &,               QGAIN(5,5,NPL),IAPROX,LFIRST                      
* /FKRSID/                                                                                                    
     &,               RPRO(2,NPL),CRPRO(2,2,NPL),RFIL(2,NPL)            
     &,               CRFIL(2,2,NPL),RSMT(2,NPL),CRSMT(2,2,NPL)         
     &,               CHIFIL(NPL),CHISMT(NPL)                           
* /FKTRUE/                                                                                                    
     &,               TRUE(5,NPL),RTRUE(5,NPL),CHITRU(NPL),LTRUE        
* /FKDBG/                                                                                                     
     &,               LTRPL(NPL),LTRPLD(NPL)                            
*KEEP,FFWBI.                                                                                                  
* Work bank indices (note that INDKTR is *NOT* a work bank index!)                                            
      PARAMETER (NWBI=10)                                               
      COMMON /FFWBI/ INDRSX(2),INDX(2),INDKX(2),INDPUR                  
     &,              INDKTR,INDKTX,INDTPR                               
*KEEP,FFDBG.                                                                                                  
      CHARACTER*5 CFDBG                                                 
      CHARACTER*6 CFKDBG                                                
      PARAMETER (CFDBG='FFDBG',CFKDBG='FFKDBG')                         
      PARAMETER (NTRACK=1000)                                           
      COMMON /FFDBG/ ITRTR(2,NTRACK),ITRNF(5,NTRACK),JTRTR              
*KEEP,FKDBG.                                                                                                  
*KEEP,BCS.                                                                                                    
      INTEGER      NHROW,NHCOL,NHLEN                                    
      PARAMETER   (NHROW = 2, NHCOL = 1, NHLEN=2)                       
      INTEGER      NBOSIW                                               
      PARAMETER   (NBOSIW=1000000)                                      
      INTEGER      IW(NBOSIW)                                           
      REAL         RW(NBOSIW)                                           
      COMMON /BCS/ IW                                                   
      EQUIVALENCE (RW(1),IW(1))                                         
      SAVE   /BCS/                                                      
*KEEP,STFUNCT.                                                                                                
*     index of element before row number IROW                                                                 
      INDR(IND,IROW)=IND+2+IW(IND+1)*(IROW-1)                           
*     index of L'th element  of row number IROW                                                               
      INDCR(IND,L,IROW)=INDR(IND,IROW) + L                              
*     L'th integer element of the IROW'th row of bank with index IND                                          
      IBTAB(IND,L,IROW)=IW(INDCR(IND,L,IROW))                           
*     L'th real element of the IROW'th row of bank with index IND                                             
      RBTAB(IND,L,IROW)=RW(INDCR(IND,L,IROW))                           
*KEND.                                                                                                        
                                                                        
**********************************************************************                                        
                                                                        
      IF (INDRSX(JTYPE).LE.0) THEN                                      
         LTRPL(JPL)  = .TRUE.                                           
         LTRPLD(JPL) = .TRUE.                                           
         RETURN                                                         
      ENDIF                                                             
                                                                        
      LTRPL(JPL)  = .FALSE.                                             
      LTRPLD(JPL) = .FALSE.                                             
                                                                        
      ILOOP = IW(INDRSX(JTYPE)+2)                                       
      DO 100 JHIT=1,ILOOP                                               
         IFLAG = IBTAB(INDRSX(JTYPE),1,JHIT)                            
         JSTR  = IBTAB(INDRSX(JTYPE),2,JHIT)                            
         IDIG  = IBTAB(INDRSX(JTYPE),3,JHIT)                            
         IF (JSTR.EQ.JTRTR .AND. IFLAG.LT.512 .AND. IDIG.EQ.JDIG) THEN  
            LTRPL(JPL) = .TRUE.                                         
            ISGN = MOD(IBTAB(INDX(JTYPE),2,JDIG),2)                     
            IF (MOD(IFLAG,2).EQ.ISGN) LTRPLD(JPL) = .TRUE.              
            RETURN                                                      
         ENDIF                                                          
 100  CONTINUE                                                          
                                                                        
      RETURN                                                            
      END                                                               
*