SUBROUTINE FKLPAS
*-- Author : S.Burke / J.V. Morris
      SUBROUTINE FKLPAS(JPL,NDROP,IERR)
**********************************************************************                                        
*                                                                    *                                        
* Point acquisition during smoothing (at plane JPL)                  *                                        
*                                                                    *                                        
* ERROR CONDITIONS;                                                  *                                        
*       IERR =   0  ; normal termination                             *                                        
*   ->  IERR =   1  ; smoothed vector missing                        *                                        
*   ->  IERR =   2  ; LMES(JPL) set on entry, but IRJCT(JPL) > 1     *                                        
*   ->  IERR =   3  ; LMES(JPL) not set by FKLOOK or FKHUNT          *                                        
*   ->  IERR =   4  ; internal error (IFLAG=0 in call to FKLRFL)     *                                        
*       IERR =   7  ; measurement covariance n.p.d. (not added)      *                                        
*       IERR =  11  ; smoothed covariance n.p.d. (not added)         *                                        
*       IERR =  12  ; covariance of smoothed residuals n.p.d.        *                                        
*       IERR =  16  ; theta > pi/2 (reset to pi/4)                   *                                        
*       IERR =  17  ; theta > 1 (warning)                            *                                        
*                                                                    *                                        
*   ->  `Fatal' error                                                *                                        
*                                                                    *                                        
* `Fatal' means that a serious problem occurred, but all errors      *                                        
* are recoverable as no changes are made.                            *                                        
*                                                                    *                                        
* Error codes from FKHUNT are passed back unchanged, but these are   *                                        
* not yet defined.                                                   *                                        
*                                                                    *                                        
**********************************************************************                                        
                                                                        
      IMPLICIT DOUBLE PRECISION (A-H,O-Z)                               
      LOGICAL FKLOOK,FKHUNT
                                                                        
      PARAMETER (IUTIL=0,IROUT=9)                                       
*KEEP,FKECODE.                                                                                                
      PARAMETER (IWARN=0,IFATAL=1,IFPRO=2,IFFLT=3,IFSMO=4,IFPRS=5,      
     &           IFPAS=6,IFPAF=7)                                       
      PARAMETER (IINF1=1,IINF2=2,IINF3=3,IINV=4,IDONE=5)                
      PARAMETER (IICV=6,IMCV=7,IOCV=11,IRCV=12,IOVCV=13,                
     &           ITHGP2=16,ITHG1=17)                                    
      PARAMETER (IFREE=20,IFREE1=30,IFREE2=40,IFREE3=50)                
*KEND.                                                                                                        
                                                                        
*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,FKFLAG.                                                                                                 
      LOGICAL LPRO,LFIL,LSMT,LMES,LRAD,LRPRO,LRFIL,LRSMT,LPOINT,LBLOCK  
      COMMON /FKFLAG/ LPRO(NPL),LFIL(NPL),LSMT(NPL),LMES(NPL)           
     &,               LRAD(NPL),LRPRO,LRFIL,LRSMT,LPOINT,LBLOCK         
*KEEP,FKRJCT.                                                                                                 
      DOUBLE PRECISION CHITOT,X2PCUT,X2CUTB,X2CUTA,X2CUTN               
     &,                       X2PCTI,X2CTBI,X2CTAI,X2CTNI               
      LOGICAL LWIRE,LPRINI                                              
      COMMON /FKRJCT/ X2PCUT,X2CUTB,X2CUTA,X2CUTN                       
     &,               X2PCTI,X2CTBI,X2CTAI,X2CTNI                       
     &,               CHITOT(NPL),NDF(NPL)                              
     &,               NBLOCK(NPL),NBADP(NPL),NBADB(NPL)                 
     &,               NFAILP(NPL),NFAILB(NPL),NNEWP(NPL)                
     &,               NUNRJP(NPL),NUNRJB(NPL),NRERJP(NPL)               
     &,               NCPRS,NBPRS,NCPAS,NPASS,IRJCT(NPL)                
     &,               LWIRE(NPL),LPRINI                                 
*KEEP,FKSMTH.                                                                                                 
*KEEP,FKRSID.                                                                                                 
*KEEP,FKTRUE.                                                                                                 
*KEND.                                                                                                        
                                                                        
**********************************************************************                                        
                                                                        
      IERR = 0                                                          
                                                                        
      IF (.NOT.LSMT(JPL)) THEN                                          
         CALL FKERR(IUTIL,IROUT,IWARN,IINF1,IERR)
         RETURN                                                         
      ENDIF                                                             
                                                                        
      NCPAS = NCPAS + 1                                                 
                                                                        
*                                                                                                             
* See if there's a new digi - first look for a completely new one ...                                         
* (If there's already a measurement, there may be a problem. FKHUNT                                           
* should check for this, and unhook the existing measurement if                                               
* necessary.)                                                                                                 
*                                                                                                             
      IFAIL = 0                                                         
      IF (.NOT.FKHUNT(JPL,SSMT(1,JPL),CSMT(1,1,JPL),IFAIL)) THEN
         IF (IFAIL.NE.0) CALL FKERR(IUTIL,IROUT,IWARN,IFAIL,IERR)
*                                                                                                             
* No luck, so if a point was previously rejected here, see if it                                              
* can go back again (but don't try more than once).                                                           
* If NDROP = JPL we just rejected this point, so don't try to                                                 
* put it back!                                                                                                
*                                                                                                             
         IF (NDROP.EQ.JPL .OR. IRJCT(JPL).LE.1) RETURN                  
* LMES(JPL) should not be set if IRJCT(JPL) is positive                                                       
         IF (LMES(JPL)) THEN                                            
            CALL FKERR(IUTIL,IROUT,IWARN,IINF3,IERR)
            RETURN                                                      
         ENDIF                                                          
         IF (.NOT.FKLOOK(JPL,SSMT(1,JPL),CSMT(1,1,JPL),IFAIL)) RETURN
      ENDIF                                                             
                                                                        
      IF (IFAIL.NE.0) CALL FKERR(IUTIL,IROUT,IFAIL/100,IFAIL,IERR)
* This shouldn't happen!                                                                                      
      IF (IFAIL.GT.100) RETURN                                          
                                                                        
*                                                                                                             
* A new point has been found, so put it in                                                                    
*                                                                                                             
      CALL FKLRFL(JPL,2,IFAIL)
      IF (IFAIL.NE.0) CALL FKERR(IUTIL,IROUT,IWARN,IFAIL,IERR)
      IF (IFAIL.GE.100) RETURN                                          
                                                                        
      IF (LRSMT) THEN                                                   
         CALL FKLRSD(JPL,SSMT(1,JPL),CSMT(1,1,JPL),-3,
     &               RSMT(1,JPL),CRSMT(1,1,JPL),CHISMT(JPL),IFAIL)      
         IF (IFAIL.NE.0) CALL FKERR(IUTIL,IROUT,IWARN,IFAIL,IERR)
      ENDIF                                                             
                                                                        
      IF (LTRUE) THEN                                                   
         CALL FKRST(JPL,IFAIL)
         IF (IFAIL.NE.0) CALL FKERR(IUTIL,IROUT,IWARN,IFAIL,IERR)
      ENDIF                                                             
                                                                        
* Only count a genuinely new point                                                                            
      IF (IRJCT(JPL).EQ.0) NNEWP(JPL) = NNEWP(JPL) + 1                  
                                                                        
      NDROP = JPL                                                       
                                                                        
      RETURN                                                            
      END                                                               
*