FPKPKR COMMENTS
*-- Author :   I.O.Skillicorn
      SUBROUTINE FPKPKR
*D: FPLPKR.......SM. Fix small bug.                                                                           
**: FPKPKR 30907 RP. Farm changes.                                                                            
**----------------------------------------------------------------------                                      
*                                                                                                             
*                                                                                                             
*     Searches for closest segment to track K in the R-Phi                                                    
*     direction which is sufficiently close in the radial direction.                                          
*     Separation is Rmean*delta-phi, where Rmean is                                                           
*     mean of planar segment and radial predicted R's and delta-phi                                           
*     is separation in Phi.                                                                                   
*                                                                                                             
*                                                                                                             
*KEEP,FRDIMS.                                                                                                 
*KEEP,FH1WORK.                                                                                                
*    Planar geometry                                                                                          
*                                                                                                             
*    Radial geometry                                                                                          
*                                                                                                             
*    Radial data...                                                                                           
*                                                                                                             
*    Planar Data                                                                                              
*                                                                                                             
*    Pointers into DIGI bank for IOS labelled hits                                                            
*                                                                                                             
*    Track segment data                                                                                       
*                                                                                                             
*    Fit data                                                                                                 
*                                                                                                             
*                                                                                                             
*KEEP,FPTVTX.                                                                                                 
**the common/VERTEX/ becomes /VERTVV/ (in analogy to /VERTFF/) on the                                         
** 17/6/91, since it is in conflict with the VERTEX module (g.bernardi)                                       
** (note that all these common names should start by F in this deck...)                                       
*KEEP,FRH3FT.                                                                                                 
*     Common for RETRAC results (SJM)                                                                         
*KEEP,FPPRAM.                                                                                                 
C                                                                                                             
C---  MAXSEG is maximum number of segments per supermodule                                                    
C---  MAXCON is maximum number of amibiguous segments associatable with                                       
C---         one segment                                                                                      
C---  LIMSTO is maximum number of 2 cluster planes intersections to be                                        
C---         stored per supermodule                                                                           
C---  MSEGLM is maximum number of clusters that can be found before                                           
C---         connectivity considered                                                                          
C---  MAXCLU is maximum number of clusters that can be found after                                            
C---         forming non-connected set    MUST BE 50 IF RUN WITH OLD RCW                                      
C---         (cluster = 3/4 digits found in a straight line in one                                            
C---          4-wire orientation)                                                                             
C                                                                                                             
C---                                                                                                          
*KEEP,FPLSEG.                                                                                                 
C---                                                                                                          
C---                                                                                                          
*KEEP,FPTFLG.                                                                                                 
*KEEP,FPTPAR.                                                                                                 
*KEEP,FDIFLG.                                                                                                 
*KEND.                                                                                                        
*     Common for track parameter errors...                                                                    
*     Common for segment numbers...                                                                           
*     COMMON FOR PLANAR PATREC  ...                                                                           
C     POINTER TO RADIAL ASSOCIATED WITH NPP'TH PLANAR                                                         
C     COMMON FOR RADIALS ASSOCIATED WITH PLANAR TRACKS                                                        
*     Local arrays...                                                                                         
*     ESTABLISH CUT VALUES                                                                                    
C     ALLOW A 1/2  CM ROAD IN DRIFT                                                                           
C     VERY GENEROUS RADIUS CUT   10.0 cm                                                                      
C                                                                                                             
C                                                                                                             
C---   Loop over supermodules                                                                                 
C                                                                                                             
C                                                                                                             
C---  CALCULATE PLANAR PREDICTION FOR SEGMENT IN THIS SUPERMODULE                                             
C                                                                                                             
C                                                                                                             
C---  RR AND PHI CALCULATED FOR THIS Z AS PREDICTED BY PLANARS                                                
C                                                                                                             
C     WRITE(*,*)' PRED PHI,R ',PHI,RR                                                                         
*                                                                                                             
*---- Loop over the Radial Segments..                                                                         
*                                                                                                             
*     check FTFIT has not killed segment                                                                      
*                                                                                                             
*     Check that this segment hasn't been used already...                                                     
*                                                                                                             
*     R AND PHI FOR RADIAL SEGMENT                                                                            
*     PRINT 3000,ISM,IP,PHI,PHIPLA                                                                            
CIOS  PHIPLA = AMOD(PHIPLA,PI2)                                                                               
*     Believe the radial segment prediction in the 'drift' direction                                          
*     only. More-or-less ignore rad radius...                                                                 
C     CHECK IN CORRECT PHI-REGION ***  9/12/93   ****                                                         
*   DIAGNOSTIC Plots...                                                                                       
C      PLOT DISTANCE OF RADIAL POINTS FROM PREDICTION                                                         
      CALL SHS(701+ISM,0.,DRE-DRMM)                                                                    
C     REPLACE DRPHI                                                                                           
      CALL FTLFT(XX,YY,LL,0,AT,BT,EE)
        CALL SHS(701   , 0, DR )                                                                       
C   END ADDITION                                                                                              
C     WRITE(*,*)' DRMIN,ISMIN,DRM ',DRMIN,ISMIN,DRM                                                           
C     PRINT 3000,ISM,IP,PHI,PHIPLA,RPL,DELP,DRPHI                                                             
C                                                                                                             
C---  End of loop over radial segments for supermodule                                                        
C                                                                                                             
*  Diagnostics                                                                                                
C      PLOT DISTANCE OF RADIAL POINTS FROM PREDICTION                                                         
        CALL SHS(700, 0, DRMIN)                                                                        
*  Diagnostics End.                                                                                           
C                                                                                                             
C---  Build list of radial hits and mark segment and hits used                                                
C                                                                                                             
C     EXPECTED D(DRIFT)/DZ                                                                                    
        CALL SHS(704+ISM,0.,DRE-DRMM)                                                                  
        CALL SHS(704+ISM,0.,DRE-DRMM)                                                                  
        CALL SHS(704+ISM,0.,DRE-DRMM)                                                                  
      CALL FTLFT(XX,YY,LL,0,AT,BT,EE)
      CALL FTLFT(XX,YYY,LL,0,AD,BD,EE)
      CALL SHS(708,0,AT)                                                                               
      CALL SHS(699,0,AD-DDDZ)                                                                          
**********************************************************                                                    
*   Diagnostics...                                                                                            
C     CALCULATE VELOCITY CORRECTION                                                                           
      CALL SHS(750+ISM,0,VFAC)                                                                         
*   Diagnostics end.                                                                                          
*       Mark radial segment used...                                                                           
C       PRINT2000,(IRPT(LK,ISMIN,ISM),LK=1,12)                                                                
C       POINTER TO RADIAL SEGMENT # ASSOCIATED WITH                                                           
C       NPP'TH PLANAR TRACK                                                                                   
C                                                                                                             
C---  End of loop over supermodules                                                                           
C  NEXT LINE SHOWS FINAL SELECTION                                                                            
CDEB  WRITE(*,*)' DRMIN DRM ',ISM,DRMIN,DRM,ISMIN                                                             
C     PRINT 1000,K,(IRR(II,K),II=1,36),LRR(1,K),LRR(2,K),LRR(3,K)                                             
*