locate Function

public function locate(xx, x)

Arguments

Type IntentOptional Attributes Name
real(kind=8), intent(in), DIMENSION(:) :: xx
real(kind=8), intent(in) :: x

Return Value integer


Called by

proc~~locate~2~~CalledByGraph proc~locate~2 locate proc~cinter~2 cinter proc~cinter~2->proc~locate~2 proc~finter2d~2 finter2d proc~finter2d~2->proc~locate~2 proc~finter~2 finter proc~finter~2->proc~locate~2

Source Code

  function locate(xx,x)
    REAL(8), DIMENSION(:), INTENT(IN) :: xx
    REAL(8), INTENT(IN) :: x
    INTEGER :: locate
    INTEGER :: n,jl,jm,ju
    LOGICAL :: ascnd
    n=size(xx)
    ascnd = (xx(n) >= xx(1))
    jl=0
    ju=n+1
    do
       if (ju-jl <= 1) exit
       jm=(ju+jl)/2
       if (ascnd .eqv. (x >= xx(jm))) then
          jl=jm
       else
          ju=jm
       end if
    end do
    if (x == xx(1)) then
       locate=1
    else if (x == xx(n)) then
       locate=n-1
    else
       locate=jl
    end if
  END FUNCTION locate