c***************************************************************************** INTEGER FUNCTION locate(xx,x) ! find left index of interval of xx includes x c routine de localisation dans une table d'entiers c fonction PRIVATE du module mod_interv c entrées c xx: tableau strictement croissant d'entiers c x;: point à localiser c Auteurs: fonction extraite du module SAHA-S d'Anna et al. c--------------------------------------------------------- IMPLICIT NONE REAL*8, DIMENSION(:), INTENT(IN) :: xx REAL*8, INTENT(IN) :: x c INTEGER locate ! locals INTEGER :: n,jl,jm,ju LOGICAL :: ascnd c---------------------------------------------------- n=size(xx) ascnd = (xx(n) >= xx(1)) ! check for acsendance of xx jl=0 ! low boundary ju=n+1 ! upper boundary do while (ju-jl > 1) jm=(ju+jl)/2 if (ascnd .eqv. (x >= xx(jm))) then jl=jm else ju=jm end if enddo if (x == xx(1)) then locate=1 else if (x == xx(n)) then locate=n-1 else locate=jl end if RETURN END FUNCTION locate