afivo-streamer 1.1
1D/2D/3D streamer simulations with AMR
Loading...
Searching...
No Matches
test_find_index_simple.f90
Go to the documentation of this file.
3
4 implicit none
5
6 integer, parameter :: dp = kind(0.0d0)
7 integer, parameter :: test_size = 1000
8
9 integer :: i
10 integer :: ix_linear, ix_bsearch, ix_adaptive
11 real(dp) :: sorted_list(test_size)
12 real(dp) :: search_value
13
14 do i = 1, test_size
15 sorted_list(i) = sqrt(real(i, dp))
16 end do
17
18 search_value = 0.5_dp * (sorted_list(1) + sorted_list(test_size))
19
20 ix_linear = find_index_linear(sorted_list, search_value)
21 ix_bsearch = find_index_bsearch(sorted_list, search_value)
22 ix_adaptive = find_index_adaptive(sorted_list, search_value)
23
24 if (ix_linear /= ix_bsearch .or. ix_linear /= ix_adaptive) then
25 error stop "Indices are unequal"
26 end if
27
28 if (sorted_list(ix_linear) < search_value) then
29 error stop "Wrong index found"
30 end if
31
32 if (ix_linear > 1) then
33 if (sorted_list(ix_linear-1) >= search_value) then
34 error stop "Wrong index found"
35 end if
36 endif
37
38 print *, "Success! Found index", ix_linear
39
40end program simple_test
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,...
program simple_test