Re: [f2py] Question about reading fortran codes in Python
Hariprasath Ganesan <[email protected]> Sat, 24 Nov 2012 23:47:41 +0100
| Newsgroups | gmane.comp.python.f2py.user |
|---|---|
| Message-ID | <CA+hFtnV1tyk-QeF8Qt=-gP2WPadUYiaOzJoSwA8P++aAmLYhTA@mail.gmail.com> |
--===============3202701841735216376==
Content-Type: multipart/alternative; boundary=0016e6d77ec3da2b7304cf457c6c
--0016e6d77ec3da2b7304cf457c6c
Content-Type: text/plain; charset=ISO-8859-1
Hi Tamal,
I would propose you a simple trick....First of all make sure that your
complex Fortran code is bug free....Once that is done ....you can play it
with f2py....
I will quote you a short example by the way...
---------------------------------------------------------------
subroutine main(list of arguments)
implicit none
! Declaration part
!f2py call
-----
call example(list of arguments)
-----
----
end subroutine main
subroutine example(list of arguments)
implicit none
! Declaration part
--------------------
---------------------
end subroutine example
-------------------------------------------------------------------------------------------------------------------
In the above mentioned example both the subroutines are in the same file
say "check.f90"......But you should notice one thing that your utility
subroutine named "example " do not have a f2py declaration part...because
it will make internal calls among Fortran subroutines by "call" statement
in your subroutine named "main" ,which python..i.e f2py need not to know
necessarily....I hope you got my point.....
In a similar fashion you can develop a complex subroutines callable &
executable by f2py.....
NOTE: If you are getting an error....Reasons could be the following...
1.) Datatype Incompatibility between Python and Fortran...
2.) No of arguments mismatch during call
3.) wrong Fortran Syntax in the source code
4.) Logical error (but usually don't affect f2py compilation)
I hope,I tried to address your problem,,,,,
Regards,
Hari.
On Sat, Nov 24, 2012 at 7:10 PM, Razibul Islam <tamal105-/[email protected]> wrote:
> Hello Hari,
> Thanks for the answer. I am also a new user of f2py. I have a little bit
> similar problem. I have a code which consists of several file and function.
> I have tried to compile single function with f2py and it works. But could
> you please tell me how to compile a complete program with several files and
> subroutines?
> Thanks in Advance
>
> Razib
>
> ------------------------------
> *From:* Hariprasath Ganesan <[email protected]>
> *To:* Bahtiyor Zohidov <bahtiyor_zohidov-JGs/[email protected]>; For users of the f2py
> program <f2py-users-Y4l6ocDipWCuvFJfX82//[email protected]>
> *Sent:* Tuesday, November 20, 2012 3:24 PM
> *Subject:* Re: [f2py] Question about reading fortran codes in Python
>
> Hi Bahithyor,
>
> Let we assume you have an executable Fortran file say name.f90 ( I assumed
> Fortran 90)....Then if you are using Linux and I assumed that you have
> Python,numpy and f2py installed readily...
>
> Open your command terminal....type f2py...
> You will see an usage message on Terminal with version & license detail at
> the end....
>
> then type the command as follows on terminal
> (eg: My Fortran file - Hello.f90)
>
> $ f2py -c -m tom Hello.f90
>
> --------------------------------------
> If your Fortran file is bug free then you would see a file named 'tom.so'
> which is basically a shared object file readable by python will get
> generated....
>
> For more insight I would give you an example...which I tried first.....
>
> My Fortran code:
> ---------------------------------------------------------------------------
>
> SUBROUTINE CHECK (A)
> INTEGER :: A
> PRINT*, "YOUR f2py IS WORKING FINE"
> PRINT*, "ENTERED VALUE IS =",A
> END SUBROUTINE
>
> -------------------------------------------------------------
> 1.) Save the above script as Hello.f90
> 2.) In terminal type " f2py -c -m tom Hello.f90"
> 3.) type ls in terminal
> 4.) you should see "tom.so" now
>
> 5.) type python in terminal
> 6.)you will get into interpreter
> >>> import tom
> >>> tom.check(2)
> YOUR f2py IS WORKING FINE
> ENTERED VALUE IS = 2
>
>
> *************** GOOD LUCK **************************
>
> REGARDS,
> HARI.
>
>
>
> On Tue, Nov 20, 2012 at 9:59 AM, Bahtiyor Zohidov <
> bahtiyor_zohidov-JGs/[email protected]> wrote:
>
> Dear Python users
>
> I would like to know how to import Fortran codes to Python(Because I have
> fortran codes which I should use them in Python) .. I tried to setup f2py.
> I couldn't figure out the steps of setup and what to do. I am beginner in
> f2py. Please, help me!!!
>
> _______________________________________________
> f2py-users mailing list
> f2py-users-Y4l6ocDipWCuvFJfX82//[email protected]
> http://cens.ioc.ee/mailman/listinfo/f2py-users
>
>
>
> _______________________________________________
> f2py-users mailing list
> f2py-users-Y4l6ocDipWCuvFJfX82//[email protected]
> http://cens.ioc.ee/mailman/listinfo/f2py-users
>
>
>
> _______________________________________________
> f2py-users mailing list
> f2py-users-Y4l6ocDipWCuvFJfX82//[email protected]
> http://cens.ioc.ee/mailman/listinfo/f2py-users
>
>
--0016e6d77ec3da2b7304cf457c6c
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Hi Tamal,<div><br></div><div>I would propose you a simple trick....First of=
all make sure that your complex Fortran code is bug free....Once that is d=
one ....you can play it with f2py....</div><div><br></div><div>I will quote=
you a short example by the way... =A0</div>
<div><br></div><div>-------------------------------------------------------=
--------</div><div><br></div><div>subroutine main(list of arguments)</div><=
div>=A0 =A0=A0</div><div>=A0 =A0 implicit none</div><div>! =A0 Declaration =
part</div>
<div><br></div><div>!f2py call</div><div>=A0 =A0 -----</div><div>=A0 =A0 ca=
ll example(list of arguments)</div><div>=A0 =A0 -----</div><div>=A0 =A0 ---=
-</div><div><br></div><div>end subroutine main</div><div>subroutine example=
(list of arguments)</div>
<div>=A0 =A0=A0implicit none</div><div>! =A0 Declaration part</div><div>=A0=
=A0 --------------------</div><div>=A0 =A0---------------------</div><div>=
<br></div><div>end subroutine example</div><div><br></div><div>------------=
---------------------------------------------------------------------------=
----------------------------</div>
<div><br></div><div>In the above mentioned example both the subroutines are=
in the same file say "check.f90"......But you should notice one =
thing that your utility subroutine named "example " do not have a=
f2py declaration part...because it will make internal calls among Fortran =
subroutines by "call" statement in your subroutine named "ma=
in" ,which python..i.e f2py need not to know necessarily....I hope you=
got my point.....</div>
<div><br></div><div>In a similar fashion you can develop a complex subrouti=
nes callable & executable by f2py.....</div><div><br></div><div>NOTE: I=
f you are getting an error....Reasons could be the following...</div><div>
<br></div><div>1.) =A0Datatype Incompatibility between Python and Fortran..=
.</div><div>2.) =A0No of arguments mismatch during call</div><div>3.) =A0wr=
ong Fortran Syntax in the source code</div><div>4.) =A0Logical error (but =
=A0usually don't affect f2py compilation)</div>
<div><br></div><div>I hope,I tried to address your problem,,,,,</div><div><=
br></div><div>Regards,</div><div>Hari.</div><div><br><div class=3D"gmail_qu=
ote">On Sat, Nov 24, 2012 at 7:10 PM, Razibul Islam <span dir=3D"ltr"><<=
a href=3D"mailto:tamal105-/[email protected]" target=3D"_blank">tamal105-/[email protected]</=
a>></span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><div><div style=3D"font-size:12pt;font-famil=
y:times new roman,new york,times,serif">Hello Hari,<br>Thanks for the answe=
r. I am also a new user of f2py. I have a little bit similar problem. I hav=
e a code which consists of several file and function. I have tried to compi=
le single function with f2py and it works. But could you please tell me how=
to compile a complete program with several files and subroutines?<br>
Thanks in Advance <br><div><br></div><div>Razib<br></div><div></div><div><b=
r></div> <div style=3D"font-family:times new roman,new york,times,serif;fo=
nt-size:12pt"> <div style=3D"font-family:times new roman,new york,times,ser=
if;font-size:12pt">
<div dir=3D"ltr"> <font face=3D"Arial"> <hr size=3D"1"> <b><span style=3D=
"font-weight:bold">From:</span></b> Hariprasath Ganesan <<a href=3D"mail=
to:[email protected]" target=3D"_blank">[email protected]</a>&g=
t;<br> <b><span style=3D"font-weight:bold">To:</span></b> Bahtiyor Zohidov
<<a href=3D"mailto:bahtiyor_zohidov-JGs/[email protected]" target=3D"_blank">bahtiyor=
_zohidov-JGs/[email protected]</a>>; For users of the f2py program <<a href=3D"mail=
to:f2py-users-Y4l6ocDipWCuvFJfX82//[email protected]" target=3D"_blank">f2py-users-Y4l6ocDipWCuvFJfX82//[email protected]</a>>=
<br>
<b><span style=3D"font-weight:bold">Sent:</span></b> Tuesday, November 20,=
2012 3:24 PM<br> <b><span style=3D"font-weight:bold">Subject:</span></b> R=
e: [f2py] Question about reading fortran codes in Python<br> </font> </div>
<div><div class=3D"h5"> <br>
<div>Hi Bahithyor,<br><br>Let we assume you have an executable Fortran file=
say name.f90 ( I assumed Fortran 90)....Then if you are using Linux and I =
assumed that you have Python,numpy and f2py installed readily...<br><br>
Open your command terminal....type f2py...<br>
You will see an usage message on Terminal with version & license detail=
at the end....<br><br>then type the command as follows on terminal<br>(eg:=
My Fortran file - Hello.f90)<br><br>$ f2py -c -m tom Hello.f90<br><br>
--------------------------------------<br>If your Fortran file is bug free =
then you would see=A0 a file named 'tom.so' which is basically a sh=
ared object file readable by python will get generated....<br><br>For more =
insight I would give you an example...which I tried first.....<br>
<br>My Fortran code:<br>---------------------------------------------------=
------------------------<br><pre>SUBROUTINE CHECK (A)
INTEGER :: A
PRINT*, "YOUR f2py IS WORKING FINE"
PRINT*, "ENTERED VALUE IS =3D",A
END SUBROUTINE<br><br>-----------------------------------------------------=
--------<br>1.) Save the above script as Hello.f90<br>2.) In terminal type =
" f2py -c -m tom Hello.f90"<br>3.) type ls in terminal<br>4.) you=
should see "tom.so" now<br>
5.) type python in terminal<br>6.)you will get into interpreter<br> >=
>> import tom<br> >>> tom.check(2)<br> YOUR f2py IS WO=
RKING FINE<br> ENTERED VALUE IS =3D 2<br><br><br>*************** GOO=
D LUCK **************************<br>
<br>REGARDS,<br>HARI.<br></pre><br><br><div>On Tue, Nov 20, 2012 at 9:59 AM=
, Bahtiyor Zohidov <span dir=3D"ltr"><<a rel=3D"nofollow" href=3D"mailto=
:bahtiyor_zohidov-JGs/[email protected]" target=3D"_blank">bahtiyor_zohidov-JGs/[email protected]</a>&g=
t;</span> wrote:<br>
<blockquote style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-l=
eft:1ex">
<div>Dear Python users<br><br>I would like to know how to import Fortran co=
des to Python(Because I have fortran codes which I should use them in Pytho=
n) .. I tried to setup f2py. I couldn't figure out the steps of setup a=
nd what to do. I am beginner in f2py. Please, help me!!!</div>
<br>_______________________________________________<br>
f2py-users mailing list<br>
<a rel=3D"nofollow" href=3D"mailto:f2py-users-Y4l6ocDipWCuvFJfX82//[email protected]" target=3D"_blank=
">f2py-users-Y4l6ocDipWCuvFJfX82//[email protected]</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></blockquote></div><br>
</div><br>_______________________________________________<br>f2py-users mai=
ling list<br><a href=3D"mailto:f2py-users-Y4l6ocDipWCuvFJfX82//[email protected]" target=3D"_blank">f2=
py-users-Y4l6ocDipWCuvFJfX82//[email protected]</a><br><a href=3D"http://cens.ioc.ee/mailman/listinfo/=
f2py-users" target=3D"_blank">http://cens.ioc.ee/mailman/listinfo/f2py-user=
s</a><br>
<br><br> </div></div></div> </div> </div></div><br>_______________________=
________________________<br>
f2py-users mailing list<br>
<a href=3D"mailto:f2py-users-Y4l6ocDipWCuvFJfX82//[email protected]">f2py-users-Y4l6ocDipWCuvFJfX82//[email protected]</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></blockquote></div><br></div>
--0016e6d77ec3da2b7304cf457c6c--
--===============3202701841735216376==
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
--===============3202701841735216376==--