FXLFIT COMMENTS
*-- Author :   I.O.Skillicorn
      SUBROUTINE FXLFIT(NPAR)
C     3/2/92 SEARCH FOR BAD POINTS AND REFIT                                                                  
*KEEP,BOSMDL.                                                                                                 
C     ------BOSMDL                                                                                            
C     ------                                                                                                  
*KEND.                                                                                                        
C     XX ADDED FOR RESIDUAL CHECK - MEDFIT                                                                    
      CALL STEXT(IHX+250,4,' TIME0 PLANAR FIT          ' )                                             
      CALL BHS(IHX+250,0,50,-1.,1.)                                                                    
      CALL STEXT(IHX+251,4,' TIME0 PLANAR FIT          ' )                                             
      CALL BHS(IHX+251,0,50,-0.1,0.1)                                                                  
      CALL STEXT(IHX+252,4,' CHI   PLANAR FIT          ' )                                             
      CALL BHS(IHX+252,0,50,0.,10.)                                                                    
      CALL STEXT(IHX+253,4,' TIME0 PLANAR FIT CHI <5    ' )                                            
      CALL BHS(IHX+253,0,50,-1.,1.)                                                                    
      CALL STEXT(IHX+254,4,' TIME0 PLANAR FIT CHI <5   ' )                                             
      CALL BHS(IHX+254,0,50,-0.1,0.1)                                                                  
      CALL STEXT(IHX+255,4,' ERROR IN T0      FIT CHI <5   ' )                                         
      CALL BHS(IHX+255,0,50,0.0,0.025)                                                                 
      CALL STEXT(IHX+256,4,' # POINTS IN T0 FIT          ' )                                           
      CALL BHS(IHX+256,0,50,0.0,100. )                                                                 
      CALL STEXT(IHX+257,4,' RESIDUAL CHI < 5  PLANARS  M0  ' )                                        
      CALL BHS(IHX+257,0,50,-5.0,5.0 )                                                                 
      CALL STEXT(IHX+258,4,' RESIDUAL CHI < 5  PLANARS  M1  ' )                                        
      CALL BHS(IHX+258,0,50,-5.0,5.0 )                                                                 
      CALL STEXT(IHX+259,4,' RESIDUAL CHI < 5  PLANARS  M2  ' )                                        
      CALL BHS(IHX+259,0,50,-5.0,5.0 )                                                                 
      CALL STEXT(IHX+260,4,' RESIDUAL CHI < 5  RADIALS  M0 ' )                                         
      CALL BHS(IHX+260,0,50,-5.0,5.0 )                                                                 
      CALL STEXT(IHX+261,4,' RESIDUAL CHI < 5  RADIALS  M1 ' )                                         
      CALL BHS(IHX+261,0,50,-5.0,5.0 )                                                                 
      CALL STEXT(IHX+262,4,' RESIDUAL CHI < 5  RADIALS  M2 ' )                                         
      CALL BHS(IHX+262,0,50,-5.0,5.0 )                                                                 
CC    CALL STEXT(IHX+263,4,' SCALE FACTOR CHI < 5 ' )                                                         
CC    CALL BHS(IHX+263,0,50,0.9,1.1)                                                                          
      CALL STEXT(IHX+264,4,' SCALE FACTOR FOR RADIAL DRIFT CHI< 5 ')                                   
      CALL BHS(IHX+264,0,50,-1.0,1.0)                                                                  
C     NEXT 2 LINES FOR T0 FIT *************************                                                       
C******************************************************                                                       
C     FIRST FIT                                                                                               
      CALL  FXFIT(X,YY,SSIG,NNDATA,A,MA,LISTA,MFIT,COVAR,NCVM,CHISQ)
C     WRITE(*,*)' CHI 1 ',CHI                                                                                 
**    IF(CHI.GT.2.0)THEN                                                                                      
C     REMOVE BAD POINTS AND REFIT                                                                             
**    RMAX=0.                                                                                                 
**    DO 3100 I=1,NNDATA                                                                                      
**    ARES(I)=ABS(RES(I))                                                                                     
**    INX(I)=I                                                                                                
**    IF(ABS(RES(I)).GT.RMAX)RMAX=ABS(RES(I))                                                                 
C     CALL SORTFL(ARES,INX,NNDATA)                                                                            
*     DO 3110 I=1,NNDATA                                                                                      
C     PRINT 2002,I,INX(I),ARES(INX(I))                                                                        
*     IF(ABS(RES(I)).GT.RMAX/1.5)THEN                                                                         
***   SSIG(I)=1000.                                                                                           
*     ENDIF                                                                                                   
*3110 CONTINUE                                                                                                
C     EXAMINE RESIDUALS WITH MEDFIT - REJECT IF > 2.5 * MEAN                                                  
C     ROBUST STR LINE FIT (LEAST ABSOLUTE DEVIATION)                                                          
**    CALL MEDFIT(XX,RES,NNDATA,AR,BR,ABDEV)                                                                  
C     WRITE(*,*)' MEDFIT RESIDUALS ',ABDEV                                                                    
**    DO 3300 I=1,NNDATA                                                                                      
**    RR=RES(I)-(AR+BR*XX(I))                                                                                 
C     PRINT2002,I,I,RR                                                                                        
C     TEMP REMOVAL OF POINT REJECT                                                                            
**    IF(ABS(RR).GT.2.5*ABDEV)SSIG(I)=1000.                                                                   
C     REFIT AFTER POINT REJECT                                                                                
**    CALL  FLFIT(X,YY,SSIG,NNDATA,A,MA,LISTA,MFIT,COVAR,NCVM,CHISQ)                                          
**    CHI=CHISQ/FLOAT(NNDATA)                                                                                 
C     WRITE(*,*)' CHI 2 ',CHI                                                                                 
**    RMAX=0.                                                                                                 
**    DO 3200 I=1,NNDATA                                                                                      
**    ARES(I)=ABS(RES(I))                                                                                     
**    INX(I)=I                                                                                                
*     IF(ABS(RES(I)).GT.RMAX)RMAX=ABS(RES(I))                                                                 
*     CALL SORTFL(ARES,INX,NNDATA)                                                                            
*     DO 3210 I=1,NNDATA                                                                                      
C     PRINT 2002,I,INX(I),ARES(INX(I))                                                                        
*     IF(ABS(RES(I)).GT.RMAX/1.5)THEN                                                                         
*     SSIG(I)=1000.                                                                                           
*     ENDIF                                                                                                   
*3210 CONTINUE                                                                                                
**    ENDIF                                                                                                   
CC    PRINT 1000,MOD,NNDATA,CHI                                                                               
CC    PRINT1001,(A(KK),KK=1,MFIT-1)                                                                           
C     PRINT1001,(A(KK),KK=1,MFIT  )                                                                           
CC    PRINT1002,A(50)                                                                                         
      CALL SHS(IHX+250,0,A(50))                                                                        
      CALL SHS(IHX+251,0,A(50))                                                                        
      CALL SHS(IHX+252,0,CHI)                                                                          
      CALL SHS(IHX+253,0,A(50))                                                                        
      CALL SHS(IHX+254,0.,A(50))                                                                       
      CALL SHS(IHX+255,0.,DTZ)                                                                         
      CALL SHS(IHX+256,0.,FLOAT(NNDATA))                                                               
C     SCALE FACTOR = 1/FACTOR FOR DRIFT VELOCITY CHANGE                                                       
C     IE BETTER DRIFT VEL = DV ORIGINAL/SF                                                                    
CCC   SF=SF1/SF2                                                                                              
C     WRITE(*,*)' FTZFIT SF ',SF                                                                              
CCC   IF(ABS(SF-1.0).LT.0.1)CALL SHS(IHX+263,0.,SF)                                                           
**********************************************************************                                        
C     SELECT ANGLE OF  WIRES -1.57,-2.62,-0.52    Y,U,V                                                       
C     THSEL=-0.52                                                                                             
C     THSEL=-2.62                                                                                             
**********************************************************************                                        
C     WRITE(*,*)' THET ',I,THET(I)                                                                            
C                                                                                                             
C                                                                                                             
C                                                                                                             
C                                                                                                             
C                                                                                                             
*************************************************************                                                 
C     MODULE TO BE STUDIED HAS SSIG MULTPILIED BY 100.                                                        
C     IN FTZFIT                                                                                               
C                                                                                                             
C     PLANAR RESIDULALS                                                                                       
**************ANGLE SELECTION********************************                                                 
CX    IF(ABS(THET(I)-THSEL).LT.0.50)THEN                                                                      
*************************************************************                                                 
C     RADIAL RESIDUALS                                                                                        
CX    ENDIF                                                                                                   
*