[SciPy-User] How to use module parameters in dimension()

Jose Amoreira ljmamoreira at gmail.com
Thu Feb 16 12:49:41 EST 2012


Hello
I have a module that defines the dimension of an array as a parameter, and a 
subroutine in that module that computes and returns that array dimension:

 1 module tests
 2 implicit none
 3 integer, parameter:: n=3      !Dimension of arrays
 4
 5 contains
 6
 7 subroutine calc(t,z)
 8 real, intent(in):: t
 9 real, dimension(n), intent(out):: z
10    z= 2*n + t
11 end subroutine calc
12 end module tests

This simple example works fine in fortran. But when I try to turn it into a 
python module with f2py, the process fails with exit status 1, stating that: 
"In function ‘f2py_rout_tests_tests_calc’:
/tmp/tmpZZiuce/src.linux-x86_64-2.7/testsmodule.c:230:14: error: ‘n’ 
undeclared (first use in this function)"

I find it strange that this failure only occurs if array z is a dummy argument 
of the calc subroutine. Otherwise, as in the listing below, f2py doesn't 
complain.

 1 module tests
 2 implicit none
 3 integer, parameter:: n=3
 4
 5 contains
 6
 7 subroutine calc(t,x)
 8 real,intent(in):: t
 9 real,intent(out):: x
10    real,dimension(n):: z
11    z=0.
12    x= 2*n + t
13 end subroutine calc
14 end module tests

So, my problem: is there any way to fix this? I mean, is it possible for f2py 
to compile a fortran module containing subroutines with parametrized dimension 
dummy arguments? Or am I missing some trivial tweak here?

Thanks,
Jose Amoreira
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20120216/418f3004/attachment.html>


More information about the SciPy-User mailing list