search_1D Subroutine

public subroutine search_1D(array, nlow, value)

search by bisection for 1D array

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: array(:)

Array to search

integer(kind=int64), intent(out) :: nlow

index of found value

real(kind=wp), intent(in) :: value

value to find in 1D array


Source Code

    subroutine search_1D(array, nlow, value)
        !! search by bisection for 1D array
        
        !> Array to search
        real(kind=wp),       intent(in)  :: array(:)
        !> index of found value
        integer(kind=int64), intent(out) :: nlow
        !> value to find in 1D array
        real(kind=wp),       intent(in)  :: value
        
        integer :: nup, middle
        
        nup = size(array)
        nlow = 1
        middle = int((nup+nlow)/2.)

        do while((nup - nlow) > 1)
            middle = int((nup + nlow)/2.)
            if(value > array(middle))then
                nlow = middle
            else
                nup = middle   
            end if
        end do
    end subroutine search_1D