SUBROUTINE FKSTAT
*-- Author : S.Burke / J.V. Morris
      SUBROUTINE FKSTAT
*-----------------------------------------Updates 07/02/92-------                                             
**: FKSTAT 30205.SB. Change FKISUM to subroutine to please UNDEF.                                             
*-----------------------------------------Updates----------------                                             
**********************************************************************                                        
*                                                                    *                                        
* Print out statistics on point rejection                            *                                        
*                                                                    *                                        
**********************************************************************                                        
                                                                        
*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,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                                 
*KEND.                                                                                                        
                                                                        
**********************************************************************                                        
                                                                        
      CALL FKISUM(NBADP,NPL,NBP,NBPMAX)
      CALL FKISUM(NBADB,NPL,NBB,NBBMAX)
      CALL FKISUM(NNEWP,NPL,NNP,NNPMAX)
      CALL FKISUM(NUNRJP,NPL,NUP,NUPMAX)
      CALL FKISUM(NUNRJB,NPL,NUB,NUBMAX)
      CALL FKISUM(NRERJP,NPL,NRP,NRPMAX)
      CALL FKISUM(NFAILP,NPL,NFP,NFPMAX)
      CALL FKISUM(NFAILB,NPL,NFB,NFBMAX)
                                                                        
      WRITE(LUN,*)                                                      
      WRITE(LUN,*)                                                      
      WRITE(LUN,*) '              General point rejection statistics'   
      WRITE(LUN,*)                                                      
      WRITE(LUN,*) '# single points removed     = ',NBP,' out of',NCPRS 
      WRITE(LUN,*) '# points removed in blocks  = ',NBB,' out of',NBPRS 
      WRITE(LUN,*) '# new points                = ',NNP,' out of',NCPAS 
      WRITE(LUN,*) '# single points re-accepted = ',NUP                 
      WRITE(LUN,*) '# block points re-accepted  = ',NUB                 
      WRITE(LUN,*) '# points rejected twice     = ',NRP                 
      WRITE(LUN,*) '# single point failures     = ',NFP                 
      WRITE(LUN,*) '# block point failures      = ',NFB                 
      WRITE(LUN,*)                                                      
                                                                        
      WRITE(LUN,*)                                                      
      WRITE(LUN,*) 'Chi-squared probability cuts were:'                 
      WRITE(LUN,*)                                                      
                                                                        
      WRITE(LUN,1000) X2PCUT,X2CUTB,X2CUTA,X2CUTN                       
      IF (LPRINI) WRITE(LUN,2000) X2PCTI,X2CTBI,X2CTAI,X2CTNI           
                                                                        
 1000 FORMAT(' X2PCUT = ',F6.4/' X2CUTB = ',F6.4/                       
     &       ' X2CUTA = ',F6.4/' X2CUTN = ',F6.4/)                      
 2000 FORMAT(' X2PCTI = ',F6.4/' X2CTBI = ',F6.4/                       
     &       ' X2CTAI = ',F6.4/' X2CTNI = ',F6.4/)                      
                                                                        
      IF (IPR.LT.6) RETURN                                              
                                                                        
      IF (NBP.GT.0) THEN                                                
         WRITE(LUN,*)                                                   
         WRITE(LUN,*) 'Single points removed (percentage by plane)'     
         WRITE(LUN,*)                                                   
         PMAX = 200.D0*NBPMAX/NBP                                       
         DO 100 JPL=1,NPL                                               
            IF (LPOINT .OR. LWIRE(JPL)) THEN                            
               PCT = 100.D0*NBADP(JPL)/NBP                              
               CALL FKHIST(LUN,JPL,PCT,PMAX)
            ENDIF                                                       
 100     CONTINUE                                                       
      ENDIF                                                             
                                                                        
      IF (NBB.GT.0) THEN                                                
         WRITE(LUN,*)                                                   
         WRITE(LUN,*) 'Points in blocks removed (percentage by plane)'  
         WRITE(LUN,*)                                                   
         PMAX = 200.D0*NBBMAX/NBB                                       
         DO 200 JPL=1,NPL                                               
            PCT = 100.D0*NBADB(JPL)/NBB                                 
            CALL FKHIST(LUN,JPL,PCT,PMAX)
 200     CONTINUE                                                       
      ENDIF                                                             
                                                                        
      CALL FKPRHS(LUN,'New points, % by plane',NNEWP,NPL)
      CALL FKPRHS(LUN,'Single points re-accepted, % by plane',
     &                                                    NUNRJP,NPL)   
      CALL FKPRHS(LUN,'Block points re-accepted, % by plane',
     &                                                    NUNRJB,NPL)   
      CALL FKPRHS(LUN,'Points rejected twice, % by plane',NRERJP,NPL)
      CALL FKPRHS(LUN,'Single point failures, % by plane',NFAILP,NPL)
      CALL FKPRHS(LUN,'Block point failures, % by plane',NFAILB,NPL)
                                                                        
      RETURN                                                            
      END                                                               
*                                                                                                             
*-----------------------------------------Updates 21/09/92-------                                             
**: FKTRAN.......SB. Cope better (?) with zero field.                                                         
*-----------------------------------------Updates----------------