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

Paul Anton Letnes paul.anton.letnes at gmail.com
Mon Feb 20 04:02:10 EST 2012


Hi,

I was just thinking that you could probably avoid the whole issue by using assumed-shape arrays. This actually gives you more checks and balances when using e.g. bounds checking with your fortran compiler (gfortran: -fbounds-check). Explicit size does not, afaik.

Paul

module tests
implicit none

contains

subroutine calc(t,z)
implicit none
real, intent(in):: t
real, dimension(:), intent(out):: z
integer :: n
    n = size(z)
    z = 2*n + t
end subroutine calc
end module tests


On 16. feb. 2012, at 18:49, Jose Amoreira wrote:

> 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
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user




More information about the SciPy-User mailing list