FKHUNT COMMENTS
*-- Author : Stephen Burke
      LOGICAL FUNCTION FKHUNT(JPL,S,C,IERR)
*-----------------------------------------Updates 27/07/93-------                                             
**: FFHUNT 30907 RP. Farm changes.                                                                            
*-----------------------------------------Updates 03/05/93-------                                             
**: FKHUNT 30907 SB. Extra argument to FFRAD.                                                                 
*-----------------------------------------Updates 07/02/92-------                                             
**: FKHUNT 30205.SB. Remove unused HCHI variable.                                                             
**: FKHUNT 30205.SB. Initialise IFAIL1 to please UNDEF.                                                       
*-----------------------------------------Updates 24/01/92-------                                             
**: FKHUNT 30205.SB. Check for wrong drift sign in debug mode.                                                
*-----------------------------------------Updates----------------                                             
**********************************************************************                                        
*                                                                    *                                        
* Look for a new digitisation                                        *                                        
*                                                                    *                                        
* ERROR CONDITIONS;                                                  *                                        
*                                                                    *                                        
*       IERR =   0 ; normal termination                              *                                        
*   ->  IERR = 101 ; invalid probability cut                         *                                        
*   ->  IERR = 103 ; invalid value in MES array                      *                                        
*   ->  IERR = 104 ; invalid value in MES array, or internal error   *                                        
*       IERR =  12 ; covariance of residuals not positive definite   *                                        
*                                                                    *                                        
*   ->  Fatal errors                                                 *                                        
*                                                                    *                                        
* Fatal errors all give a return value of .FALSE., and no changes    *                                        
* are made; they are consequently recoverable.                       *                                        
*                                                                    *                                        
**********************************************************************                                        
*KEEP,FKECODE.                                                                                                
*KEND.                                                                                                        
*KEEP,FKNPL.                                                                                                  
*                                                                                                             
* 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.                                                                        
*                                                                                                             
* /FKPROJ/                                                                                                    
* /FKFILT/                                                                                                    
* /FKSMTH/                                                                                                    
* /FKINT/                                                                                                     
* /FKRSID/                                                                                                    
* /FKTRUE/                                                                                                    
* /FKDBG/                                                                                                     
*KEEP,FFSTEE.                                                                                                 
*KEEP,FFGEO.                                                                                                  
*KEEP,FKFLAG.                                                                                                 
*KEEP,FKMEAS.                                                                                                 
*KEEP,FKCONS.                                                                                                 
*KEEP,FKSMTH.                                                                                                 
*KEEP,FKRJCT.                                                                                                 
*KEEP,FKDBG.                                                                                                  
*KEEP,FFWBI.                                                                                                  
* Work bank indices (note that INDKTR is *NOT* a work bank index!)                                            
*KEEP,FRLORA.                                                                                                 
*KEND.                                                                                                        
*KEEP,BCS.                                                                                                    
*KEEP,FTANG.                                                                                                  
*     Statement functions for track angle corrections...                                                      
*     (assumes COMMON FRLORA present)                                                                         
*                                                                                                             
*KEEP,STFUNCT.                                                                                                
*     index of element before row number IROW                                                                 
*     index of L'th element  of row number IROW                                                               
*     L'th integer element of the IROW'th row of bank with index IND                                          
*     L'th real element of the IROW'th row of bank with index IND                                             
*KEND.                                                                                                        
**********************************************************************                                        
* Don't try to replace existing points                                                                        
* Don't look outside the tracker!                                                                             
*                                                                                                             
* Work out the cell number and drift for the supplied state                                                   
* vector, and then search for a match in the digi bank                                                        
*                                                                                                             
         CALL FFPCEL(S,JPLFT(JPL),ICELL,DRIFT)
            CALL FKERR(IUTIL,IROUT,IFATAL,IINF3,IERR)
         CALL FFPHNT(ICELL,DRIFT,JDIG)
         CALL FFRCEL(S,JPLFT(JPL),ICELL,IWEDGE,DRIFT)
            CALL FKERR(IUTIL,IROUT,IFATAL,IINF3,IERR)
         CALL FFRHNT(ICELL,DRIFT,IWEDGE,JDIG)
* Give up if nothing was found, or if we just found the same point                                            
* Disallow point sharing                                                                                      
* If there's something here, save it in case we change our mind                                               
         CALL UCOPY(WMES(1,JPL),WTEMP,4)                                                               
         CALL UCOPY(CMES(1,1,JPL),CTEMP,8)                                                             
         CALL UCOPY(HMES(1,1,JPL),HTEMP,8)                                                             
*                                                                                                             
* Fill the measurement arrays                                                                                 
*                                                                                                             
         CALL FFPLAN(JDIG)
* Always include radius                                                                                       
         CALL FFRAD(JDIG,0)
* Event T0 correction                                                                                         
      CALL FFEVT0(DEVT0,ZNOM,VXYZ)
      CALL GUFLD(R,B)                                                                                  
* Track angle, time-of-flight and propagation time                                                            
      CALL FFCORR(JPL,S,ZNOM,VXYZ,DEVT0,B(3),DCORR)
*                                                                                                             
* See if the chi**2 is acceptable                                                                             
*                                                                                                             
      CALL FKLRSD(JPL,S,C,3,RES,CRES,CHISQ,IFAIL)
* Update the LTRPL array                                                                                      
      IF (LTRUTH) CALL FFCHTR(JPL,MES(JPL),JDIG)
* Histogram residuals                                                                                         
      IF (MOD(IHFK/10,10).GT.0) CALL FKANAL(JPL,RES,CHISQ,0,0)
      IF (IFAIL.EQ.0 .AND. CHISQ.LT.FKCHPR(4,MES(JPL),IFAIL1)) THEN
* New point, starting from scratch                                                                            
*                                                                                                             
* The new point failed the chi**2 cut, so tidy up                                                             
*                                                                                                             
      IF (IFAIL.NE.0) CALL FKERR(IUTIL,IROUT,IWARN,IFAIL,IERR)
      IF (IFAIL1.NE.0) CALL FKERR(IUTIL,IROUT,IFAIL1/100,IFAIL1,IERR)
         CALL UCOPY(WTEMP,WMES(1,JPL),4)                                                               
         CALL UCOPY(CTEMP,CMES(1,1,JPL),8)                                                             
         CALL UCOPY(HTEMP,HMES(1,1,JPL),8)                                                             
*