6 integer,
parameter :: dp = kind(0.0d0)
7 integer,
parameter :: test_size = 1000
10 integer :: ix_linear, ix_bsearch, ix_adaptive
11 real(dp) :: sorted_list(test_size)
12 real(dp) :: search_value
15 sorted_list(i) = sqrt(real(i, dp))
18 search_value = 0.5_dp * (sorted_list(1) + sorted_list(test_size))
24 if (ix_linear /= ix_bsearch .or. ix_linear /= ix_adaptive)
then
25 error stop
"Indices are unequal"
28 if (sorted_list(ix_linear) < search_value)
then
29 error stop
"Wrong index found"
32 if (ix_linear > 1)
then
33 if (sorted_list(ix_linear-1) >= search_value)
then
34 error stop
"Wrong index found"
38 print *,
"Success! Found index", ix_linear
A Fortran 90 module for creating lookup tables. These tables can be used to efficiently interpolate o...
pure integer function, public find_index_bsearch(list, val)
Binary search of sorted list for the smallest ix such that list(ix) >= val. On failure,...
pure integer function, public find_index_adaptive(list, val)
Adaptive search (combination of linear and binary search) of sorted list for the smallest ix such tha...
pure integer function, public find_index_linear(list, val)
Linear search of sorted list for the smallest ix such that list(ix) >= val. On failure,...