Now I am using the f2py
to call Python function from Fortran code. I have tried a very easy example but it didn't work.
Fortran90 code:
subroutine foo(fun,r)
external fun
integer ( kind = 4 ) i
real ( kind = 8 ) r
r=0.0D+00
do i= 1,5
r=r+fun(i)
enddo
end
using the commandline:
f2py -c -m callback callback.f90
Python code:
import callback
def f(i):
return i * i
print callback.foo(f)
Error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: `Required argument 'r' (pos 2) not found`