c c c
 
      subroutine linint(x,y,xtab,ytab,ntab)
c
c     Given a value of x return a value of y based on interpolation
c     within a table of y values (ytab) corresponding to the x values
c     contained in the array xtab.  The subroutine assumes that the
c     values in xtab increase monotonically.  Efficiency is increased
c     by remembering the table points used in the last call (ilast)
c     xtab and ytab are provided through the argument list as is their
c     length ntab.
c
c    John Mahaffy 2/12/95
c
      real xtab(ntab),ytab(ntab)
c
      save ilast
c
      data ilast/1/
c
c    Start the search from the last point of table use index
c
      if (x.le.xtab(ilast+1)) then
c
c    Search down the table from point of last use
c
          do 20 i1=ilast,1,-1
              if(x.ge.xtab(i1)) go to 60
  20          continue
          write(6,*) 'x = ', x, '  is below the table range'  
          stop
      else
c
c    Search up the table from point of last use
c
          do 40 i1=ilast+1,ntab-1
              if(x.le.xtab(i1+1)) go to 60
  40          continue
          write(6,*) 'x = ', x, '  is above the table range'
          stop
      endif
c
c   Bounding points found, interpolate
c
  60  wx=(x-xtab(i1))/(xtab(i1+1)-xtab(i1))
      y=(1-wx)*ytab(i1)+wx*ytab(i1+1)
      ilast=i1
      return
      end
c
c c