Rückruf Python aus Fortran

Jetzt benutze ich dief2py Python-Funktion aus Fortran-Code aufrufen. Ich habe ein sehr einfaches Beispiel ausprobiert, aber es hat nicht funktioniert.

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

über die Kommandozeile:

f2py -c -m Rückruf Rückruf.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`

Antworten auf die Frage(2)

Ihre Antwort auf die Frage