      SUBROUTINE LOCATION (XX,N,X,J)
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C
C  Given an array XX of length N, and given a value X, returns a value J such
C  that X is between XX(J) and XX(J+1).  XX must be monotonic, either
C  increasing or decreasing.  J=0 or J=N is returned to indicate that X is
C  out of range.
C
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
      DIMENSION XX(N)
      JL=0
      JU=N+1
   10 IF(JU-JL.GT.1)THEN
          JM=(JU+JL)/2
          IF((XX(N).GT.XX(1)).EQV.(X.GT.XX(JM)))THEN
              JL=JM
          ELSE
              JU=JM
          ENDIF
      GO TO 10
      ENDIF
      J=JL
      RETURN
      END

