SUBROUTINE FKEND
*-- Author : S.Burke / J.V. Morris
      SUBROUTINE FKEND
*-----------------------------------------Updates 13/02/92-------                                             
**: FKEND 30205.SB.  Cosmetic change to printout.                                                             
*-----------------------------------------Updates----------------                                             
**********************************************************************                                        
*                                                                    *                                        
* Print out statistics on point rejection and errors                 *                                        
*                                                                    *                                        
**********************************************************************                                        
                                                                        
*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,FKCNTL.                                                                                                 
      COMMON /FKCNTL/ LUN,IPR,ITR,IPL,JSTART,JSTOP,JLAST,JSTEP          
*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,FKLERR.                                                                                                 
      PARAMETER(NROUT=20,NCODE=50)                                      
      COMMON /FKLERR/ NMERR(NCODE,NROUT),NUERR(NCODE,NROUT)             
     &,               NFAT,NERR,NOFL,NUFL,IULAST,IRLAST,MAXERR          
*KEND.                                                                                                        
                                                                        
**********************************************************************                                        
                                                                        
      WRITE(LUN,*)                                                      
      WRITE(LUN,*)                                                      
      WRITE(LUN,*) '              *** Kalman Filter error summary ***'  
      WRITE(LUN,*)                                                      
      WRITE(LUN,*)                                                      
      WRITE(LUN,*) 'Number of fatal errors     = ',NFAT                 
      WRITE(LUN,*) 'Total number of errors     = ',NERR                 
      WRITE(LUN,*)                                                      
                                                                        
      IF (NOFL.GT.0) WRITE(LUN,1000) NOFL                               
      IF (NUFL.GT.0) WRITE(LUN,1100) NUFL                               
                                                                        
* Printout level set by IPR                                                                                   
      IF (IPR.LT.2) THEN                                                
         ISTEP = 9                                                      
      ELSE                                                              
         ISTEP = 1                                                      
      ENDIF                                                             
                                                                        
      IULAST = 0                                                        
      DO 200 IROUT=1,NROUT,ISTEP                                        
         IFLAG = 0                                                      
         DO 50 ICODE=1,NCODE                                            
            IF (NMERR(ICODE,IROUT).GT.0) IFLAG = 1                      
 50      CONTINUE                                                       
         IF (IFLAG.EQ.1) THEN                                           
            IRLAST = IROUT                                              
            CALL FKPRNT(0,0)
            DO 100 ICODE=1,NCODE                                        
               NUM = NMERR(ICODE,IROUT)                                 
               IF (NUM.GT.0) CALL FKPRNT(NUM,ICODE)
 100        CONTINUE                                                    
         ENDIF                                                          
 200  CONTINUE                                                          
                                                                        
      IF (IPR.LT.4) RETURN                                              
                                                                        
      IULAST = 1                                                        
      DO 400 IROUT=1,NROUT                                              
         IFLAG = 0                                                      
         DO 250 ICODE=1,NCODE                                           
            IF (NUERR(ICODE,IROUT).GT.0) IFLAG = 1                      
 250     CONTINUE                                                       
         IF (IFLAG.EQ.1) THEN                                           
            IRLAST = IROUT                                              
            CALL FKPRNT(0,0)
            DO 300 ICODE=1,NCODE                                        
               NUM = NUERR(ICODE,IROUT)                                 
               IF (NUM.GT.0) CALL FKPRNT(NUM,ICODE)
 300        CONTINUE                                                    
         ENDIF                                                          
 400  CONTINUE                                                          
                                                                        
 1000 FORMAT(/' *** FKERR called ',I6,' times with routine or error'/   
     &        ' *** codes out of range'/)                               
 1100 FORMAT(/' *** FKERR called ',I6,' times with negative routine'/   
     &        ' *** or error codes'/)                                   
                                                                        
* Point rejection statistics                                                                                  
      IF (LPOINT .OR. LBLOCK) CALL FKSTAT
                                                                        
      RETURN                                                            
      END                                                               
*