      SUBROUTINE EDITQ(Q,NQ)  
C     
C     ROUTINE TO EDIT BAD POINTS IN Q. THERE ARE 2 MODES :  
C     AUTOMATIC MODE WHERE ALL ZEROS ARE COUNTED AS BAD AND 
C     MANUAL MODE WHERE THE USER SPECIFIES WHICH POINTS TO  
C     REPLACE AND WITH WHAT.  IN AUTOMATIC MODE, THE BAD POINTS   
C     ARE REPLACED BY LINEAR INTERPOLATION.     
C     
      DIMENSION Q(1)    
      READ *,KS,KE,VAL  
      MODE=0
      IF(KS.NE.0.AND.KE.NE.0)THEN   
        MODE=1    
        GO TO 50  
      END IF
      NCHAN=VAL   
      PRINT  10,NCHAN   
   10 FORMAT(12X,8HNCHAN = ,I5/)    
      IPT=0 
C     
C     IDENTIFY THE FIRST POINT OF THE NEXT SEQUENCE OF ZEROES     
C     
   20 IPT=IPT+1   
      IF(IPT.GT.NQ)RETURN     
      IF(Q(IPT).NE.0.0)GO TO  20    
      IPT1=IPT    
C     
C     IDENTIFY THE LAST POINT IN THE INTERVAL   
C     
   25 IPT1=IPT1+1 
      IF(IPT1.LE.NQ.AND.Q(IPT1).EQ.0.0)GO TO  25
      IPT1=IPT1-1 
      C=0.0 
      NSUM=0
      SUM=0.0     
      C1=0.0
      NSUM1=0     
      SUM1=0.0    
C     
C     NOW AVERAGE THE NCHAN POINTS ON EITHER SIDE OF THE GAP
C     
      DO  30 I=1,NCHAN  
        INDEX=IPT-I     
        IF(INDEX.GE.1)THEN    
          C=C+INDEX     
          NSUM=NSUM+1   
          SUM=SUM+Q(INDEX)    
        END IF    
        INDEX=IPT1+I    
        IF(INDEX.LE.NQ)THEN   
          C1=C1+INDEX   
          NSUM1=NSUM1+1 
          SUM1=SUM1+Q(INDEX)  
        END IF    
   30 CONTINUE    
      IF(NSUM.GT.0.OR.NSUM1.GT.0)THEN     
        IF(NSUM.GT.0)THEN     
          SUM=SUM/NSUM  
          C=C/NSUM
        END IF    
        IF(NSUM1.GT.0)THEN    
          SUM1=SUM1/NSUM1     
          C1=C1/NSUM1   
        END IF    
        PRINT  35,IPT,IPT1,C,SUM,C1,SUM1  
   35   FORMAT(12X,'POINTS ',I5,'TO',I5,' INTERPOLATED BETWEEN ' ,
     *         F7.1,',',F12.5,' AND ',F7.1,',',F12.5) 
        DO  40 I=IPT,IPT1     
          IF(NSUM.GT.0.AND.NSUM1.EQ.0)THEN
            Q(I)=SUM    
          ELSE IF(NSUM.EQ.0.AND.NSUM1.GT.0)THEN 
            Q(I)=SUM1   
          ELSE    
            Q(I)=SUM+(SUM1-SUM)*(I-C)/(C1-C)    
          END IF  
   40   CONTINUE  
      END IF
      IPT=IPT1+1  
      GO TO  20   
C     
   50 CONTINUE    
      PRINT 60,KS,KE,(Q(J),J=KS,KE) 
   60 FORMAT(12X,11HOLD Q FROM ,I5,5H  TO ,I5,4H   ://(12X,1P10E12.4    
     *       ))   
      DO 70 J=KS,KE     
        Q(J)=VAL  
   70 CONTINUE    
      PRINT 100,KS,KE,(Q(J),J=KS,KE)
  100 FORMAT(12X,11HNEW Q FROM ,I5,5H  TO ,I5,4H   ://(12X,1P10E12.4    
     *       ))   
      READ *,KS,KE,VAL  
      IF(KS.NE.0.AND.KE.NE.0)GO TO 50     
      RETURN
      END   
