[f2py] help using f2py
Jose Amoreira
ljmamoreira at gmail.com
Tue Jan 12 02:58:25 EET 2010
Hello!
This is probably a stupid question, but...
I'm having a hard time trying to define a python module from a fortran
subroutine having other subroutines in the list of arguments.
Consider the following subroutine (sub), which takes as argument a real array
(x), the dimension (n) of that array and another subroutine (other_sub) that
is to be called by sub :
file sub.f95
----------------------------------------------
subroutine sub(x,other_sub,n)
integer::n
real, dimension(n)::x
external:: other_sub
call other_sub(x)
end subroutine sub
----------------------------------------------
When I run this through f2py, all I get is a bunch of errors:
Part of the output of f2py -m sub -c sub.f95:
----------------------------------------------
creating /tmp/tmpyHp76U/tmp
creating /tmp/tmpyHp76U/tmp/tmpyHp76U
creating /tmp/tmpyHp76U/tmp/tmpyHp76U/src.linux-x86_64-2.6
compile options: '-I/tmp/tmpyHp76U/src.linux-x86_64-2.6 -
I/usr/lib64/python2.6/site-packages/numpy/core/include -
I/usr/include/python2.6 -c'
gcc: /tmp/tmpyHp76U/src.linux-x86_64-2.6/fortranobject.c
gcc: /tmp/tmpyHp76U/src.linux-x86_64-2.6/submodule.c
/tmp/tmpyHp76U/src.linux-x86_64-2.6/submodule.c: In function
‘cb_other_sub_in_sub__user__routines’:
/tmp/tmpyHp76U/src.linux-x86_64-2.6/submodule.c:306: error: ‘n’ undeclared
(first use in this function)
/tmp/tmpyHp76U/src.linux-x86_64-2.6/submodule.c:306: error: (Each undeclared
identifier is reported only once
/tmp/tmpyHp76U/src.linux-x86_64-2.6/submodule.c:306: error: for each function
it appears in.)
/tmp/tmpyHp76U/src.linux-x86_64-2.6/submodule.c: In function
‘cb_other_sub_in_sub__user__routines’:
/tmp/tmpyHp76U/src.linux-x86_64-2.6/submodule.c:306: error: ‘n’ undeclared
(first use in this function)
/tmp/tmpyHp76U/src.linux-x86_64-2.6/submodule.c:306: error: (Each undeclared
identifier is reported only once
/tmp/tmpyHp76U/src.linux-x86_64-2.6/submodule.c:306: error: for each function
it appears in.)
error: Command "gcc -pthread -fno-strict-aliasing -DNDEBUG -fmessage-length=0
-O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -
fasynchronous-unwind-tables -g -fwrapv -fPIC -I/tmp/tmpyHp76U/src.linux-
x86_64-2.6 -I/usr/lib64/python2.6/site-packages/numpy/core/include -
I/usr/include/python2.6 -c /tmp/tmpyHp76U/src.linux-x86_64-2.6/submodule.c -o
/tmp/tmpyHp76U/tmp/tmpyHp76U/src.linux-x86_64-2.6/submodule.o" failed with
exit status 1
-------------------------------------
I just don't get it!
I don't know if it is related but, if I change argument x to a scalar (instead
of an array), then f2py executes fine and the python module is generated.
Also, both variants (array or scalar x) compile without any errors or
warnings, using gfortran.
Can anybody explain me what I am doing wrong, please? Thanks in advance.
Jose Amoreira
More information about the f2py-users
mailing list