Added check for too many iterations in binary_search.

This commit is contained in:
Paul Romano 2011-11-29 15:41:30 -05:00
parent f4111ec63c
commit 44012b9b9d

View file

@ -4,6 +4,8 @@ module search
use error, only: fatal_error
use global, only: message
integer, parameter :: MAX_ITERATION = 64
contains
!===============================================================================
@ -20,6 +22,7 @@ contains
integer :: L
integer :: R
integer :: n_iteration
real(8) :: testval
L = 1
@ -30,6 +33,7 @@ contains
call fatal_error()
end if
n_iteration = 0
do while (R - L > 1)
! Check boundaries
@ -49,6 +53,13 @@ contains
elseif (val < testval) then
R = array_index
end if
! check for large number of iterations
n_iteration = n_iteration + 1
if (n_iteration == MAX_ITERATION) then
message = "Reached maximum number of iterations on binary search."
call fatal_error()
end if
end do
array_index = L