 
      subroutine tableintrp(xx, n, x, jlo)
C...Translated by Pacific-Sierra Research VAST-90 2.06G2  10:50:51  10/ 1/01  
C...Switches: -p4 -yb
      use kind_spec

      implicit none
C-----------------------------------------------
C   D u m m y   A r g u m e n t s
C-----------------------------------------------
      integer n, jlo
      real(kind=dp) x
      real(kind=dp), dimension(n) :: xx
C-----------------------------------------------
C   L o c a l   V a r i a b l e s
C-----------------------------------------------
      integer :: jhi, jmid, inc
C-----------------------------------------------
c
c ----------------------------------------------------------------------
c --- correlated table search routine. use jlo from previous call to
c --- get jlo for current value of x. if jlo from previous call is
c --- no good(jlo=0 or jlo=n) then do a binary search.
c --- this routine returns jlo so that
c   xx(jlo) .le. x .le. xx(jlo+1) if jlo = 1
c   xx(jlo) .lt. x .le. xx(jlo+1) if jlo =2,3...n-1
c   it is assumed that xx(j),j = 1,2..n is monotonically
c   increasing; this is NOT checked for.
c   this is a modified version of the Numerical Recipes subroutine HUNT
c ------------------------------------------------------------------ HSJ
c
c
      if (x < xx(1)) then
         jlo = 0                    ! indicates out of range below xx(1)
      else if (x <= xx(2)) then
         jlo = 1                               ! xx(1) .le. x .le. xx(2)
      else if (x <= xx(n)) then                ! xx(2) .lt. x .le. xx(n)
c
c       check if jlo from previous call is usable:
c
         if (jlo==0 .or. jlo==n) then
            jlo = 2
            jhi = n
            go to 15           ! no correlation go directly to bisection
         else                                    ! 1 .le. jlo .lt. n
c
c         bracket x, then use bisection:
c         start with  jlo  from previous call:
c
            inc = 1
            if (x > xx(jlo)) then                ! search up
    4          continue
               jhi = jlo + inc
               if (jhi >= n) then
                  jhi = n
               else if (x > xx(jhi)) then
                  inc = inc + inc
                  jlo = jhi
                  go to 4
               endif
            else
    5          continue
               jhi = jlo
               jlo = jlo - inc
               if (jlo <= 1) then
                  jlo = 1
               else if (x <= xx(jlo)) then
                  inc = inc + inc
                  go to 5
               endif
            endif
         endif
c
c         bisection:
c
   10    continue
         if (jhi - jlo == 1) return 
   15    continue
         jmid = (jhi + jlo)/2
         if (x > xx(jmid)) then
            jlo = jmid
         else                                    ! x .le. xx(jmid)
            jhi = jmid
         endif
         go to 10
c
      else                                       ! x .gt. xx(n)
         jlo = n
      endif
c
      return 
c
      end subroutine tableintrp
