Re: [f2py] Question about reading fortran codes in Python
Hariprasath Ganesan <[email protected]> Tue, 20 Nov 2012 15:24:52 +0100
| Newsgroups | gmane.comp.python.f2py.user |
|---|---|
| Message-ID | <CA+hFtnVsr+9x9tx4xXE-AY6ys8yu3bx+hrjv3gep+D_qFGBynA@mail.gmail.com> |
--===============1531285224512446462==
Content-Type: multipart/alternative; boundary=f46d043be1e054aec304ceedff54
--f46d043be1e054aec304ceedff54
Content-Type: text/plain; charset=ISO-8859-1
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
>
>
--f46d043be1e054aec304ceedff54
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
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 assum=
ed that you have Python,numpy and f2py installed readily...<br><br>Open you=
r 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 class=3D"literal-block">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 class=3D"gmail_quote">On Tue, N=
ov 20, 2012 at 9:59 AM, Bahtiyor Zohidov <span dir=3D"ltr"><<a href=3D"m=
ailto:bahtiyor_zohidov-JGs/[email protected]" target=3D"_blank">bahtiyor_zohidov-JGs/[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>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 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>
--f46d043be1e054aec304ceedff54--
--===============1531285224512446462==
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
--===============1531285224512446462==--