C+ C NAME: C nrLocate C PURPOSE: C Find the position of X in an array XX C CATEGORY: C Math: table searching C CALLING SEQUENCE: subroutine nrLocate(N,XX,X,J) C INPUTS: C N integer dimension of array XX C XX real array; MUST be monotonic C X real value for which position in XX is required C OUTPUTS: C J integer index of array XX such that X lies between C XX(J) and XX(J+1) C - if X < X(1) then J=0 C - if X > X(N) then X=N C RESTRICTIONS: C The array XX must be monotonic (increasing or decreasing). C NO CHECK IS MADE TO ENSURE THIS IS THE CASE. C PROCEDURE: C See Numerical Recipes, par. 3.4, p. 90 C Uses standard bisection procedure. C See href=nrHunt= if a good initial guess is available C MODIFICATION HISTORY: C JUN-1993, Paul Hick (UCSD/CASS; pphick@ucsd.edu) C- integer N real XX(N) real X integer J JL = 0 JU = N+1 do while (JU-JL .gt. 1) JM = (JU+JL)/2 if ( (XX(N) .gt. XX(1)) .eqv. (X .gt. XX(JM)) ) then JL = JM else JU = JM end if end do J = JL return end