Elias Assmann
2013-04-30 13:09:07 UTC
Hi,
I am able to use f2py in simple cases, but I ran into a problem with
callbacks. Using the ``callback.f’’ example from the user's guide:
C FILE: CALLBACK.F
SUBROUTINE FOO(FUN,R)
EXTERNAL FUN
INTEGER I
REAL*8 R
Cf2py intent(out) r
R = 0D0
DO I=-5,5
R = R + FUN(I)
ENDDO
END
C END OF FILE CALLBACK.F
my Python session looks like this:
Python 2.7.3 (default, Aug 1 2012, 05:14:39)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
r = foo(fun,[fun_extra_args])
Required arguments:
fun : call-back function
Optional arguments:
fun_extra_args := () input tuple
Return objects:
r : float
Call-back functions:
def fun(i): return r
Required arguments:
i : input int
Return objects:
r : float
... print "f:", i
... return i*i
...
f: -4
f: -3
f: -2
f: -1
f: 0
f: 1
f: 2
f: 3
f: 4
f: 5
0.0
If I modify ``callback.f’’ to print the return value of every call to
``f’’, that value is always 0.
Any pointers? My Fortran compiler is gfortran, gcc version 4.6.3
(Ubuntu/Linaro 4.6.3-1ubuntu5).
Elias
I am able to use f2py in simple cases, but I ran into a problem with
callbacks. Using the ``callback.f’’ example from the user's guide:
C FILE: CALLBACK.F
SUBROUTINE FOO(FUN,R)
EXTERNAL FUN
INTEGER I
REAL*8 R
Cf2py intent(out) r
R = 0D0
DO I=-5,5
R = R + FUN(I)
ENDDO
END
C END OF FILE CALLBACK.F
my Python session looks like this:
Python 2.7.3 (default, Aug 1 2012, 05:14:39)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
import callback
print callback.foo.__doc__
foo - Function signature:print callback.foo.__doc__
r = foo(fun,[fun_extra_args])
Required arguments:
fun : call-back function
Optional arguments:
fun_extra_args := () input tuple
Return objects:
r : float
Call-back functions:
def fun(i): return r
Required arguments:
i : input int
Return objects:
r : float
... print "f:", i
... return i*i
...
callback.foo(f)
f: -5f: -4
f: -3
f: -2
f: -1
f: 0
f: 1
f: 2
f: 3
f: 4
f: 5
0.0
If I modify ``callback.f’’ to print the return value of every call to
``f’’, that value is always 0.
Any pointers? My Fortran compiler is gfortran, gcc version 4.6.3
(Ubuntu/Linaro 4.6.3-1ubuntu5).
Elias