Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. integer function binsearch(tab, el)
  2. implicit none
  3.  
  4. real, intent(in) :: tab(:), el
  5. integer :: a, b, mid
  6.  
  7. a = 1
  8. b = size(tab)
  9.  
  10. do while (b - a > 1)
  11. mid = (a + b)/2
  12. if (el >= tab(mid)) then
  13. a = mid
  14. else
  15. b = mid
  16. endif
  17. ! if (el < tab(mid + 1)) exit ! BAD OPTIMIZATION !
  18. enddo
  19.  
  20. binsearch = a
  21. end function binsearch
  22.  
  23. foo = binsearch(tab, el)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement