Find the locations in t0 that bracket t
Start with a quick search and finish with direct
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(in) | :: | t | Position of desired value |
||
real(kind=wp), | intent(in), | dimension(:) | :: | t0 | t values of data |
Index of lower t0 value which brakets t
Nodes of different colours represent the following:
Solid arrows point from a procedure to one which it calls. Dashed arrows point from an interface to procedures which implement that interface. This could include the module procedures in a generic interface or the implementation in a submodule of an interface in a parent module.
function findInterval(t,t0) result(o)
!! Find the locations in t0 that bracket t
!!
!! Start with a quick search and finish with direct
real(wp),intent(in)::t
!! Position of desired value
real(wp),dimension(:),intent(in)::t0
!! t values of data
integer::o
!! Index of lower t0 value which brakets t
integer::L,M,H
L = 1
H = size(t0)
do while(H-L>5)
M = (L+H)/2
if( t>=t0(M) ) then
L = M
else
H = M
end if
end do
o = directSearch(t,t0(L:H))+(L-1)
contains
function directSearch(t,t0) result(o)
!! Search entried linearlly until span is found
real(wp),intent(in)::t
real(wp),dimension(:),intent(in)::t0
integer::o
integer::N,k
N = size(t0)
do k=1,N-1
if( t<t0(k) ) exit
end do
o = k-1
end function directSearch
end function findInterval