[f2py] How to use module parameters in dimension()
Jose Amoreira <[email protected]> Thu, 16 Feb 2012 12:53:18 +0000
| Newsgroups | gmane.comp.python.f2py.user |
|---|---|
| Message-ID | <[email protected]> |
--===============6637518347313163061==
Content-Type: multipart/alternative; boundary="nextPart3220678.lm7N2hrU1I"
Content-Transfer-Encoding: 7Bit
--nextPart3220678.lm7N2hrU1I
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset="utf-8"
Hello
I have a module that defines the dimension of an array as a parameter, =
and a=20
subroutine in that module that computes and returns that array dimensio=
n:
1 module tests
2 implicit none
3 integer, parameter:: n=3D3 !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=3D 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 in=
to a=20
python module with f2py, the process fails with exit status 1, stating =
that:=20
"In function =E2=80=98f2py_rout_tests_tests_calc=E2=80=99:
/tmp/tmpZZiuce/src.linux-x86_64-2.7/testsmodule.c:230:14: error: =E2=80=
=98n=E2=80=99=20
undeclared (first use in this function)"
I find it strange that this failure only occurs if array z is a dummy a=
rgument=20
of the calc subroutine. Otherwise, as in the listing below, f2py doesn'=
t=20
complain.
1 module tests
2 implicit none
3 integer, parameter:: n=3D3
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=3D0.
12 x=3D 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 fo=
r f2py=20
to compile a fortran module containing subroutines with parametrized di=
mension=20
dummy arguments?
Thanks,
Jose Amoreira
--nextPart3220678.lm7N2hrU1I
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset="utf-8"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/=
REC-html40/strict.dtd">
<html><head><meta name=3D"qrichtext" content=3D"1" /><style type=3D"tex=
t/css">
p, li { white-space: pre-wrap; }
</style></head><body style=3D" font-family:'Monospace'; font-size:9pt; =
font-weight:400; font-style:normal;">
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">Hel=
lo</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">I h=
ave a module that defines the dimension of an array as a parameter, and=
a subroutine in that module that computes and returns that array dimen=
sion:</p>
<p style=3D"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px=
; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0p=
x; "> </p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> 1 =
module tests</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> 2 =
implicit none</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> 3 =
integer, parameter:: n=3D3 !Dimension of arrays</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> 4<=
/p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> 5 =
contains</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> 6<=
/p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> 7 =
subroutine calc(t,z)</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> 8 =
real, intent(in):: t</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> 9 =
real, dimension(n), intent(out):: z</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">10 =
z=3D 2*n + t</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">11 =
end subroutine calc</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">12 =
end module tests</p>
<p style=3D"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px=
; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0p=
x; "> </p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">Thi=
s 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, statin=
g that: </p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">&qu=
ot;In function =E2=80=98f2py_rout_tests_tests_calc=E2=80=99:</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">/tm=
p/tmpZZiuce/src.linux-x86_64-2.7/testsmodule.c:230:14: error: =E2=80=98=
n=E2=80=99 undeclared (first use in this function)"</p>
<p style=3D"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px=
; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0p=
x; "> </p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">I f=
ind it strange that this failure only occurs if array z is a dummy argu=
ment of the calc subroutine. Otherwise, as in the listing below, f2py d=
oesn't complain.</p>
<p style=3D"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px=
; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0p=
x; "> </p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> 1 =
module tests</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> 2 =
implicit none</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> 3 =
integer, parameter:: n=3D3</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> 4<=
/p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> 5 =
contains</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> 6<=
/p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> 7 =
subroutine calc(t,x)</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> 8 =
real,intent(in):: t</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> 9 =
real,intent(out):: x</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">10 =
real,dimension(n):: z</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">11 =
z=3D0.</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">12 =
x=3D 2*n + t</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">13 =
end subroutine calc</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">14 =
end module tests</p>
<p style=3D"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px=
; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0p=
x; "> </p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">So,=
my problem: is there any way to fix this? I mean, is it possible for f=
2py to compile a fortran module containing subroutines with parametrize=
d dimension dummy arguments?</p>
<p style=3D"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px=
; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0p=
x; "> </p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">Tha=
nks,</p>
<p style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin=
-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">Jos=
e Amoreira</p></body></html>
--nextPart3220678.lm7N2hrU1I--
--===============6637518347313163061==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
f2py-users mailing list
f2py-users-Y4l6ocDipWCuvFJfX82//[email protected]
http://cens.ioc.ee/mailman/listinfo/f2py-users
--===============6637518347313163061==--