      subroutine hunt(xx,n,x,jlo)
*
* Given an array XX of length N, and given a value X, returns a 
* value jlo such that x is between xx(jlo) and xx(jlo+1).  XX must
* be monotonic, either increasing or decreasing.
*
      implicit double precision(a-h,o-z)

      dimension xx(n)
      logical ascnd
*
* Is table ascending (.TRUE.) or decending (.FALSE.)?
*
      ascnd = xx(n) .gt. xx(1)
*
* Input guess not useful, go straight to bisection
*
      if ( jlo .le. 0 .or. jlo .gt. n) then
          jlo = 0
          jhi = n + 1
          goto 3
      endif
*
* set hunting increment
*
      inc = 1
*
* hunt up
*
      if ( x .ge. xx(jlo) .eqv. ascnd) then
1         jhi = jlo + inc
          if (jhi .gt. n) then
              jhi = n+1
          else if ( x .ge. xx(jhi) .eqv. ascnd) then
              jlo = jhi
              inc = inc + inc
              goto 1
          endif
      else
*
* hunt down
*
          jhi = jlo
2         jlo = jhi - inc
          if ( jlo .lt. 1 ) then
              jlo = 0
          else if ( x.lt.xx(jlo) .eqv.ascnd) then
              jhi = jlo
              inc= inc+inc
              goto 2
          endif
      endif
3     if ( jhi-jlo .eq. 1) return
      jm = (jhi+jlo) / 2
      if ( x .gt. xx(jm) .eqv. ascnd) then
          jlo=jm
      else
          jhi = jm
      endif
      goto 3
      end

************************************************************************

