Skip to content

Instantly share code, notes, and snippets.

@mverleg
Created April 25, 2016 12:30
Show Gist options
  • Save mverleg/71dbbf755ed1cf96589236a69bc64027 to your computer and use it in GitHub Desktop.
Save mverleg/71dbbf755ed1cf96589236a69bc64027 to your computer and use it in GitHub Desktop.
!!
!! 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
@mverleg
Copy link
Author

mverleg commented Jun 2, 2020

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment