NuMFor 9f2ab49 (2024-04-08)
Numerical (Modern) Fortran. Library for Simple Numerical computing
searchsorted Interface Reference

searchsorted: Find index where an element should be inserted in an array to maintain order. More...

Public Member Functions

pure integer function searchsorted_dp (x, elem)
 Search in an array of real(dp) elements.
 
pure integer function searchsorted_i (x, elem)
 Search in an array of integer elements.
 
pure integer function searchsorted_idp (x, elem)
 Search the position of a real number in an array of integer elements.
 
pure integer function searchsorted_dpi (x, elem)
 Search the position of an integer number in an array of real elements.
 

Detailed Description

searchsorted: Find index where an element should be inserted in an array to maintain order.

Find the index into an ascending sorted array x such that, if elem was inserted after the index, the order of x would be preserved.

Note
Bisection is used to find the required insertion point if number of elements is higher of a certain threshold
If elem is outside the limits of x then:
  • If below the vector then (first-1) is returned.
  • If above the vector then "last index" is returned.

Examples:

With real numbers:

...
USE arrays, only: searchsorted
...
real(dp), dimension(6) :: a = [1._dp, 3._dp, 5._dp,9._dp, 32._dp, 124._dp]
real(dp) :: elem
integer :: n
elem = 6.34_dp
n = searchsorted(a, elem)

will give n = 3, while

n = searchsorted(a, 0.5_dp)

will give n = 0 and

n = searchsorted(a, 1000._dp)

will give n = 6

Member Function/Subroutine Documentation

◆ searchsorted_dp()

pure integer function searchsorted_dp ( real(dp), dimension(:), intent(in) x,
real(dp), intent(in) elem )

Search in an array of real(dp) elements.

See also
searchsorted documentation
Parameters
[in]xArray sorted in ascending order
[in]elemelement to insert
Returns
index of closest edge to the left of elem

◆ searchsorted_dpi()

pure integer function searchsorted_dpi ( real(dp), dimension(:), intent(in) x,
integer, intent(in) elem )

Search the position of an integer number in an array of real elements.

See also
searchsorted documentation
Parameters
[in]xArray sorted in ascending order
[in]elemelement to insert
Returns
index of closest edge to the left of elem

◆ searchsorted_i()

pure integer function searchsorted_i ( integer, dimension(:), intent(in) x,
integer, intent(in) elem )

Search in an array of integer elements.

See also
searchsorted documentation
Parameters
[in]xArray sorted in ascending order
[in]elemelement to insert
Returns
index of closest edge to the left of elem

◆ searchsorted_idp()

pure integer function searchsorted_idp ( integer, dimension(:), intent(in) x,
real(dp), intent(in) elem )

Search the position of a real number in an array of integer elements.

See also
searchsorted documentation
Parameters
[in]xArray sorted in ascending order
[in]elemelement to insert
Returns
index of closest edge to the left of elem

The documentation for this interface was generated from the following file: