c
c  %W%
c
        real function interpp(x,xs,ys,npts,ymin,ymax)
c
        dimension xs(npts),ys(npts)
c
        if(xs(2) - xs(1) .ge. 0.0)then
            imin = 1
            imax = npts
            inc = 1
        else
            imin = npts
            imax = 1
            inc = -1
        endif
c
        if(x.lt.xs(imin))then
            interpp = ymin
            return
        else if(x.gt.xs(imax))then
            interpp = ymax
            return
        endif
c
        ihi = imin
1       ihi = ihi + inc
        if(x.gt.xs(ihi))goto 1
        ilow = ihi - inc
        deltay = ys(ihi) - ys(ilow)
        deltax = xs(ihi) - xs(ilow)
        change = x - xs(ilow)
        interpp = ys(ilow) + change*deltay/deltax
        return
        end
