Created
April 25, 2016 12:30
-
-
Save mverleg/71dbbf755ed1cf96589236a69bc64027 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!! | |
!! f2py -c -m search search.f90 | |
!! | |
subroutine find_first(needle, haystack, haystack_length, index) | |
!! | |
!! Find the first index of `needle` in `haystack`. | |
!! | |
implicit none | |
integer, intent(in) :: needle | |
integer, intent(in) :: haystack_length | |
integer, intent(in), dimension(haystack_length) :: haystack | |
!f2py intent(inplace) haystack | |
integer, intent(out) :: index | |
integer :: k | |
index = -1 | |
do k = 1, haystack_length | |
if (haystack(k)==needle) then | |
index = k - 1 | |
exit | |
endif | |
enddo | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@hech92 Yeah Python knows this information, just Fortran doesn't, so Python can fill it in automatically before calling Fortran. And because it's always the same logic, it can be in the wrapper code so you don't have to do it.