      SUBROUTINE BRIDGE(Q,NQ) 
C***  THIS SUBROUTINE BRIDGES SHORT DATA GAPS IN ARRAY Q WITH     
C     STRAIGHT LINES.  INPUT DATA IS LAST GOOD CHANNEL OF DATA    
C     BEFORE GAP,IX1, FIRST GOOD CHANNEL OF DATA AFTER GAP,IX2,   
C     AND NUMBER,NA, OF CHANNELS ON EACH SIDE OF THE GAP TO 
C     AVERAGE TOGETHER TO DETERMINE Y1 AND Y2.  DEFAULT     
C     OF NA=1.  BRIDGING IS TERMINATED BY A BLANK CARD.     
C     
C     EXTENSION:  IF NA IS SET LESS THAN 0, THEN THE PROGRAM GOES INTO  
C     AN AUTOMATIC MODE WHERE IT IDENTIFIES INTERVALS OF 0'S AND BRIDGES
C     AUTOMATICALLY.    
C     
      DIMENSION Q(1)    
      IAUTO=0     
      PRINT 20    
   20 FORMAT(//,12X,17HDATA GAPS BRIDGED,/,12X,7HCHANNEL,6X,5HOLD Q,    
     19X,5HNEW Q) 
   10 READ *, IX1,IX2,NA
      IF(NA.LT.0)THEN   
        NA=-NA    
        IAUTO=1   
        GO TO 100 
      END IF
      IF(IX1.LE.0) GO TO 99   
      IF(IX1.GE.IX2) GO TO 98 
      IF(NA.LE.0) NA=1  
    3 Y1=0.0
      Y2=0.0
      II=IX1-NA+1 
      IF(II.GT.0)THEN   
        DO 5 I=II,IX1   
    5   Y1=Y1+Q(I)
        Y1=Y1/NA  
      END IF
      II=IX2+NA-1 
      IF(II.LE.NQ)THEN  
        DO 6 I=IX2,II   
    6   Y2=Y2+Q(I)
        Y2=Y2/NA  
      END IF
      IF(Y1.EQ.0.0)THEN 
        IF(Y2.EQ.0.0)THEN     
          PRINT 97,(IX1,IX2,I,Q(I),I=MAX(1,IX1),MIN(IX2,NQ))  
   97     FORMAT(12X,'DRASTIC PROBLEM WITH AUTOMATIC BRIDGING'/   
     *           12X,'IX1 = ',I5,'  IX2 = ',I5,'  DATA ARRAY IS : '/    
     *           (12X,5(I5,2X,1PE13.5)))  
          STOP    
        END IF    
        Y1=Y2     
      ELSE IF(Y2.EQ.0.0)THEN  
        Y2=Y1     
      END IF
      N=IX2-IX1-1 
      DELX=IX2-IX1
      DELY=Y2-Y1  
      DELTA=DELY/DELX   
      II=IX1+1    
      JJ=IX1+N    
      DO 2 I=II,JJ
      Y1=Y1+DELTA 
      IF(I.LT.1.OR.I.GT.NQ)GO TO 2  
      PRINT 21, I,Q(I),Y1     
   21 FORMAT(13X,I5,2(3X,E11.4))    
      Q(I)=Y1     
    2 CONTINUE    
      IF(IAUTO.EQ.1)GO TO 130 
      GO TO 10    
   98 PRINT 50    
   50 FORMAT(12X,17HX1 .GT. X2, STOP. )   
      STOP  
   99 CONTINUE    
      RETURN
  100 IPT1=0
C     
C     IDENTIFY THE FIRST POINT OF THE NEXT SEQUENCE OF ZEROES     
C     
  120 IPT1=IPT1+1 
      IF(IPT1.GT.NQ)RETURN    
      IF(Q(IPT1).NE.0.0)GO TO 120   
      IPT2=IPT1   
C     
C     IDENTIFY THE LAST POINT IN THE INTERVAL   
C     
  125 IPT2=IPT2+1 
      IF(IPT2.LE.NQ.AND.Q(IPT2).EQ.0.0)GO TO 125
      IPT2=IPT2-1 
      IX1=IPT1-1  
      IX2=IPT2+1  
      GO TO 3     
  130 IPT1=IPT2+1 
      GO TO 120   
      END   
