No subject


Wed Jun 30 14:15:50 EEST 2010


<br>
 =A0$ f2py -m _mymod -h mymod.pyf mymod.f90<br>
<br>
As Pearu mentioned, even the allocatable arrays are then exposed to<br>
python as _mymod.mymod.abc and _mymod.mymod.deg.<br>
<br>
Juergen<br>
<br>
<br>
<br>
Benjamin Kutz wrote (Friday 16 July 2010 14:12:05):<br>
&gt;<br>
&gt; Hi,<br>
&gt;<br>
&gt; thanks for your fast answer.<br>
&gt; I still didn`t got the point. I just want to share these allocatable<b=
r>
&gt; data arrays between the first and the second subroutine.<br>
&gt; I also knew the example out of the f2py manual, but I couldn`t realise=
<br>
&gt; it in my code, due to my limited knowledge in python and wrapping.<br>
&gt; Do you mean, that I have to write a fortran module for each allocatabl=
e?<br>
&gt; What does this module look like?<br>
&gt; At the moment I allocate in Fortan at the beginning with:<br>
&gt;<br>
&gt; =A0 =A0 =A0 =A0subroutine init(abc,deg)<br>
&gt; =A0 =A0 =A0 =A0integer =A0max, max2<br>
&gt; =A0 =A0 =A0 =A0max=3D ...<br>
&gt; =A0 =A0 =A0 =A0max2=3D...<br>
&gt; =A0 =A0 =A0 =A0real =A0 , dimension (:) =A0, allocatable =A0:: abc<br>
&gt; =A0 =A0 =A0 =A0real =A0 , dimension (:,:) =A0, allocatable =A0:: deg<b=
r>
&gt; =A0 =A0 =A0 =A0allocate (abc(max))<br>
&gt; =A0 =A0 =A0 =A0allocate (deg(max,max2))<br>
&gt; =A0 =A0 =A0 =A0call initialxyz (abc,deg)<br>
&gt; =A0 =A0 =A0 =A0end<br>
&gt;<br>
&gt; =A0 =A0 =A0 =A0subroutine calc(abc,deg)<br>
&gt; =A0 =A0 =A0 =A0call solve(abc,deg)<br>
&gt; =A0 =A0 =A0 =A0if ( allocated( abc ) ) then<br>
&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0deallocate (abc)<br>
&gt; =A0 =A0 =A0 =A0...<br>
&gt; =A0 =A0 =A0 =A0endif<br>
&gt;<br>
&gt; I wrap both routines and want to call them one after another from pyth=
on.<br>
&gt; Maybe you can help me with a little example? What does the foo.pyf hav=
e<br>
&gt; to look like?<br>
&gt; The problem is, that I have to wrap with f2py -c foo.pyf *.o. I can&#3=
9;t<br>
&gt; wrap it directly from the foo.f90 routine.<br>
&gt;<br>
&gt; Greetings<br>
&gt; Ben<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; f2py-users mailing list<br>
&gt; <a href=3D"mailto:f2py-users at cens.ioc.ee">f2py-users at cens.ioc.ee</a><b=
r>
&gt; <a href=3D"http://cens.ioc.ee/mailman/listinfo/f2py-users" target=3D"_=
blank">http://cens.ioc.ee/mailman/listinfo/f2py-users</a><br>
&gt;<br>
<br>
<br>
<br>
<br>
------------------------------<br>
<br>
Message: 5<br>
Date: Fri, 16 Jul 2010 17:13:04 +0200<br>
From: Benjamin Kutz &lt;<a href=3D"mailto:kutz at iag.uni-stuttgart.de">kutz at i=
ag.uni-stuttgart.de</a>&gt;<br>
Subject: Re: [f2py] Wraping Fortran code with allocatable arrays.<br>
To: <a href=3D"mailto:f2py-users at cens.ioc.ee">f2py-users at cens.ioc.ee</a><br=
>
Message-ID: &lt;<a href=3D"mailto:4C407700.8070004 at iag.uni-stuttgart.de">4C=
407700.8070004 at iag.uni-stuttgart.de</a>&gt;<br>
Content-Type: text/plain; charset=3DISO-8859-1; format=3Dflowed<br>
<br>
Am 16.07.2010 15:30, schrieb J?rgen Wieferink:<br>
&gt; Hi,<br>
&gt;<br>
&gt; module mymod<br>
&gt; =A0 =A0implicit none<br>
&gt; =A0 =A0real, dimension(:), allocatable :: abc<br>
&gt; =A0 =A0real, dimension(:,:), allocatable :: deg<br>
&gt; contains<br>
&gt; =A0 =A0subroutine init<br>
&gt; =A0 =A0 =A0implicit none<br>
&gt; =A0 =A0 =A0! do stuff on abc, deg<br>
&gt; =A0 =A0end subroutine init<br>
&gt; =A0 =A0subroutine calc<br>
&gt; =A0 =A0 =A0implicit none<br>
&gt; =A0 =A0 =A0! do stuff on abc, deg<br>
&gt; =A0 =A0end subroutine calc<br>
&gt; end module mymod<br>
&gt;<br>
&gt; &gt; From this, you can easily generate the wrapper mymod.pyf from<br>
&gt;<br>
&gt; =A0 =A0$ f2py -m _mymod -h mymod.pyf mymod.f90<br>
&gt;<br>
&gt; As Pearu mentioned, even the allocatable arrays are then exposed to<br=
>
&gt; python as _mymod.mymod.abc and _mymod.mymod.deg.<br>
&gt;<br>
&gt; Juergen<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; Benjamin Kutz wrote (Friday 16 July 2010 14:12:05):<br>
&gt;<br>
&gt;&gt; Hi,<br>
&gt;&gt;<br>
&gt;&gt; thanks for your fast answer.<br>
&gt;&gt; I still didn`t got the point. I just want to share these allocatab=
le<br>
&gt;&gt; data arrays between the first and the second subroutine.<br>
&gt;&gt; I also knew the example out of the f2py manual, but I couldn`t rea=
lise<br>
&gt;&gt; it in my code, due to my limited knowledge in python and wrapping.=
<br>
&gt;&gt; Do you mean, that I have to write a fortran module for each alloca=
table?<br>
&gt;&gt; What does this module look like?<br>
&gt;&gt; At the moment I allocate in Fortan at the beginning with:<br>
&gt;&gt;<br>
&gt;&gt; =A0 =A0 =A0 =A0 subroutine init(abc,deg)<br>
&gt;&gt; =A0 =A0 =A0 =A0 integer =A0max, max2<br>
&gt;&gt; =A0 =A0 =A0 =A0 max=3D ...<br>
&gt;&gt; =A0 =A0 =A0 =A0 max2=3D...<br>
&gt;&gt; =A0 =A0 =A0 =A0 real =A0 , dimension (:) =A0, allocatable =A0:: ab=
c<br>
&gt;&gt; =A0 =A0 =A0 =A0 real =A0 , dimension (:,:) =A0, allocatable =A0:: =
deg<br>
&gt;&gt; =A0 =A0 =A0 =A0 allocate (abc(max))<br>
&gt;&gt; =A0 =A0 =A0 =A0 allocate (deg(max,max2))<br>
&gt;&gt; =A0 =A0 =A0 =A0 call initialxyz (abc,deg)<br>
&gt;&gt; =A0 =A0 =A0 =A0 end<br>
&gt;&gt;<br>
&gt;&gt; =A0 =A0 =A0 =A0 subroutine calc(abc,deg)<br>
&gt;&gt; =A0 =A0 =A0 =A0 call solve(abc,deg)<br>
&gt;&gt; =A0 =A0 =A0 =A0 if ( allocated( abc ) ) then<br>
&gt;&gt; =A0 =A0 =A0 =A0 =A0 =A0 =A0 deallocate (abc)<br>
&gt;&gt; =A0 =A0 =A0 =A0 ...<br>
&gt;&gt; =A0 =A0 =A0 =A0 endif<br>
&gt;&gt;<br>
&gt;&gt; I wrap both routines and want to call them one after another from =
python.<br>
&gt;&gt; Maybe you can help me with a little example? What does the foo.pyf=
 have<br>
&gt;&gt; to look like?<br>
&gt;&gt; The problem is, that I have to wrap with f2py -c foo.pyf *.o. I ca=
n&#39;t<br>
&gt;&gt; wrap it directly from the foo.f90 routine.<br>
&gt;&gt;<br>
&gt;&gt; Greetings<br>
&gt;&gt; Ben<br>
&gt;&gt;<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; f2py-users mailing list<br>
&gt;&gt; <a href=3D"mailto:f2py-users at cens.ioc.ee">f2py-users at cens.ioc.ee</=
a><br>
&gt;&gt; <a href=3D"http://cens.ioc.ee/mailman/listinfo/f2py-users" target=
=3D"_blank">http://cens.ioc.ee/mailman/listinfo/f2py-users</a><br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; f2py-users mailing list<br>
&gt; <a href=3D"mailto:f2py-users at cens.ioc.ee">f2py-users at cens.ioc.ee</a><b=
r>
&gt; <a href=3D"http://cens.ioc.ee/mailman/listinfo/f2py-users" target=3D"_=
blank">http://cens.ioc.ee/mailman/listinfo/f2py-users</a><br>
&gt;<br>
Hi,<br>
<br>
wonderful! As I can see your example does not differ much from that one<br>
in the manual.<br>
But I don&#39;t know why, now I found out how to do it ;)! Maybe it was the=
<br>
heat or the friday afternoon;) or just my &quot;slow&quot; brain :)<br>
Thanks for your quick help and have a nice weekend!<br>
<br>
Greetings<br>
Ben<br>
<br>
<br>
<br>
<br>
------------------------------<br>
<br>
_______________________________________________<br>
f2py-users mailing list<br>
<a href=3D"mailto:f2py-users at cens.ioc.ee">f2py-users at cens.ioc.ee</a><br>
<a href=3D"http://cens.ioc.ee/mailman/listinfo/f2py-users" target=3D"_blank=
">http://cens.ioc.ee/mailman/listinfo/f2py-users</a><br>
<br>
<br>
End of f2py-users Digest, Vol 65, Issue 5<br>
*****************************************<br>
</blockquote></div><br></div>

--0016e65aeed6563734048be93138--



More information about the f2py-users mailing list