|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> |
|
<HTML> |
|
<HEAD> |
|
<META name="Author" content="Pearu Peterson"> |
|
|
|
<META name="Keywords" content="fortran,python,interface,f2py,f2py2e,wrapper,fpig"> |
|
<TITLE>F2PY - Fortran to Python Interface Generator</TITLE> |
|
<LINK rel="stylesheet" type="text/css" href="/styles/userstyle.css"> |
|
</HEAD> |
|
|
|
<BODY> |
|
|
|
<H1>F2PY ­ Fortran to Python Interface Generator</H1> |
|
by <em>Pearu Peterson</em> |
|
|
|
<h2>What's new?</h2> |
|
|
|
See <a href="NEWS.txt">NEWS.txt</a> for the latest changes in <code>f2py</code>. |
|
<dl> |
|
<dt> July ??, 2002 |
|
<dd> Implemented prototype calculator, complete tests for scalar F77 |
|
functions, --help-compiler option. Fixed number of bugs and |
|
removed obsolete features. |
|
<dt> April 4, 2002 |
|
<dd> Fixed a nasty bug of copying one-dimensional non-contiguous arrays. |
|
(Thanks to Travis O. for pointing this out). |
|
<dt> March 26, 2002 |
|
<dd> Bug fixes, turned off F2PY_REPORT_ATEXIT by default. |
|
<dt> March 13, 2002 |
|
<dd> MAC support, fixed incomplete dependency calculator, minor bug fixes. |
|
<dt> March 3, 2002 |
|
<dd> Fixed memory leak and copying of multi-dimensional complex arrays. |
|
<dt> <a href="oldnews.html">Old news</a>. |
|
</dl> |
|
|
|
<h2>Introduction</h2> |
|
|
|
Writing Python C/API wrappers for Fortran routines can be a very |
|
tedious task, especially if a Fortran routine takes more than 20 |
|
arguments but only few of them are relevant for the problems that they |
|
solve. So, I have developed a tool that generates the C/API modules |
|
containing wrapper functions of Fortran routines. I call this |
|
tool as <em>F2PY ­ Fortran to Python Interface Generator</em>. |
|
It is completely written in <a href="http://www.python.org">Python</a> |
|
language and can be called from the command line as <code>f2py</code>. |
|
<em>F2PY</em> (in NumPy) is released under the terms of the NumPy License. |
|
|
|
|
|
<h2><code>f2py</code>, Second Edition</h2> |
|
|
|
The development of <code>f2py</code> started in summer of 1999. |
|
For now (January, 2000) it has reached to stage of being a |
|
complete tool: it scans real Fortran code, creates signature file |
|
that the user can modify, constructs C/API module that can be |
|
complied and imported to Python, and it creates LaTeX documentation |
|
for wrapper functions. Below is a bit longer list of |
|
<code>f2py</code> features: |
|
<ol> |
|
<li> <code>f2py</code> scans real Fortran codes and produces the signature files. |
|
The syntax of the signature files is borrowed from the Fortran 90/95 |
|
language specification with some extensions. |
|
<li> <code>f2py</code> generates a GNU Makefile that can be used |
|
for building shared modules (see below for a list of supported |
|
platforms/compilers). Starting from the third release, |
|
<code>f2py</code> generates <code>setup_modulename.py</code> for |
|
building extension modules using <code>distutils</code> tools. |
|
<li> <code>f2py</code> uses the signature files to produce the wrappers for |
|
Fortran 77 routines and their <code>COMMON</code> blocks. |
|
<li> For <code>external</code> arguments <code>f2py</code> constructs a very flexible |
|
call-back mechanism so that Python functions can be called from |
|
Fortran. |
|
<li> You can pass in almost arbitrary Python objects to wrapper |
|
functions. If needed, <code>f2py</code> takes care of type-casting and |
|
non-contiguous arrays. |
|
<li> You can modify the signature files so that <code>f2py</code> will generate |
|
wrapper functions with desired signatures. <code>depend()</code> |
|
attribute is introduced to control the initialization order of the |
|
variables. <code>f2py</code> introduces <code>intent(hide)</code> |
|
attribute to remove |
|
the particular argument from the argument list of the wrapper |
|
function and <code>intent(c)</code> that is useful for wrapping C |
|
libraries. In addition, <code>optional</code> and |
|
<code>required</code> |
|
attributes are introduced and employed. |
|
<li> <code>f2py</code> supports almost all standard Fortran 77/90/95 constructs |
|
and understands all basic Fortran types, including |
|
(multi-dimensional, complex) arrays and character strings with |
|
adjustable and assumed sizes/lengths. |
|
<li> <code>f2py</code> generates a LaTeX document containing the |
|
documentations of the wrapped functions (argument types, dimensions, |
|
etc). The user can easily add some human readable text to the |
|
documentation by inserting <code>note(<LaTeX text>)</code> attribute to |
|
the definition of routine signatures. |
|
<li> With <code>f2py</code> one can access also Fortran 90/95 |
|
module subroutines from Python. |
|
</ol> |
|
|
|
For more information, see the <a href="usersguide.html">User's |
|
Guide</a> of the tool. Windows users should also take a look at |
|
<a href="win32_notes.txt">f2py HOWTO for Win32</a> (its latest version |
|
can be found <a |
|
href="http://www.numpy.org/Members/eric/f2py_win32">here</a>). |
|
|
|
<h3>Requirements</h3> |
|
<ol> |
|
<li> You'll need <a |
|
href="http://www.python.org/download/">Python</a> |
|
(1.5.2 or later, 2.2 is recommended) to run <code>f2py</code> |
|
(because it uses exchanged module <code>re</code>). |
|
To build generated extension modules with distutils setup script, |
|
you'll need Python 2.x. |
|
<li> You'll need <a |
|
href="http://sourceforge.net/project/?group_id=1369">Numerical |
|
Python</a> |
|
(version 13 or later, 20.3 is recommended) to compile |
|
C/API modules (because they use function |
|
<code>PyArray_FromDimsAndDataAndDescr</code>) |
|
</ol> |
|
|
|
<h3>Download</h3> |
|
|
|
<dl> |
|
<dt> User's Guide: |
|
<dd> <a href="usersguide.html">usersguide.html</a>, |
|
<a href="usersguide.pdf">usersguide.pdf</a>, |
|
<a href="usersguide.ps.gz">usersguide.ps.gz</a>, |
|
<a href="usersguide.dvi">usersguide.dvi</a>. |
|
<dt> Snapshots of the fifth public release: |
|
<dd> <a href="2.x">2.x</a>/<a href="2.x/F2PY-2-latest.tar.gz">F2PY-2-latest.tar.gz</a> |
|
<dt> Snapshots of earlier releases: |
|
<dd> <a href="rel-5.x">rel-5.x</a>, <a href="rel-4.x">rel-4.x</a>, |
|
<a href="rel-3.x">rel-3.x</a>, |
|
<a href="rel-2.x">rel-2.x</a>,<a href="rel-1.x">rel-1.x</a>, |
|
<a href="rel-0.x">rel-0.x</a> |
|
</dl> |
|
|
|
<h3>Installation</h3> |
|
|
|
Unpack the source file, change to directory <code>f2py-?-???</code> |
|
and run <code>python setup.py install</code>. That's it! |
|
|
|
<h3>Platform/Compiler Related Notes</h3> |
|
|
|
<code>f2py</code> has been successfully tested on |
|
<ul> |
|
<li> Intel Linux (MD7.0,RH6.1,RH4.2,Debian woody), Athlon Linux (RH6.1), Alpha Linux (RH5.2,RH6.1) with <a |
|
href="http://gcc.gnu.org/">gcc</a> (versions egcs-2.91.60,egcs-2.91.66, and 2.95.2). |
|
<li> Intel Linux (MD7.0) with <a |
|
href="http://www.psrv.com/index.html">Pacific-Sierra |
|
Research</a> <a href="http://www.psrv.com/lnxf90.html">Personal |
|
Linux VAST/f90 Fortran 90 compiler</a> (version V3.4N5). |
|
<li> Intel Linux (RH6.1) with <a href="http://www.absoft.com/">Absoft F77/F90</a> compilers for Linux. |
|
<li> IRIX64 with <a href="http://gcc.gnu.org/">gcc</a> (2.95.2) and <a |
|
href="http://www.sgi.com/developers/devtools/languages/mipspro.html">MIPSpro |
|
7 Compilers</a> (f77,f90,cc versions 7.30). |
|
<li> Alpha Linux (RH5.2,RH6.1) with <a href="http://www.digital.com/fortran/linux/">Compaq Fortran </a> compiler (version V1.0-920). |
|
<li> Linux with <a href="http://www.nag.co.uk/">NAGWare</a> Fortran |
|
95 compiler. |
|
<li> <a href="http://developer.intel.com/software/products/compilers/f50/linux/"> |
|
Intel(R) Fortran Compiler for Linux</a> |
|
<li> Windows 2000 with <a href="http://www.mingw.org">mingw32</a>. |
|
</ul> |
|
<code>f2py</code> will probably run on other UN*X systems as |
|
well. Additions to the list of platforms/compilers where |
|
<code>f2py</code> has been successfully used are most welcome. |
|
<P> |
|
<em>Note:</em> |
|
Using Compaq Fortran |
|
compiler on Alpha Linux is succesful unless when |
|
wrapping Fortran callback functions returning |
|
<code>COMPLEX</code>. This applies also for IRIX64. |
|
<P> |
|
<em>Note:</em> |
|
Fortran 90/95 module support is currently tested with Absoft F90, VAST/f90, Intel F90 compilers on Linux (MD7.0,Debian woody). |
|
|
|
|
|
<h3><a name="f2py-users">Mailing list</a></h3> |
|
|
|
There is a mailing list <a |
|
href="http://cens.ioc.ee/pipermail/f2py-users/">f2py-users</a> |
|
available for the users of the <code>f2py</code> |
|
program and it is open for discussion, questions, and answers. You can subscribe |
|
the list <a href="http://cens.ioc.ee/mailman/listinfo/f2py-users">here</a>. |
|
|
|
<h3><a href="http://cens.ioc.ee/cgi-bin/cvsweb/python/f2py2e/">CVS Repository</a></h3> |
|
|
|
<code>f2py</code> is being developed under <a href="http://www.sourcegear.com/CVS">CVS</a> and those who are |
|
interested in the really latest version of <code>f2py</code> (possibly |
|
unstable) can get it from the repository as follows: |
|
<ol> |
|
<li> First you need to login (the password is <code>guest</code>): |
|
<pre> |
|
> cvs -d :pserver:[email protected]:/home/cvs login |
|
</pre> |
|
<li> and then do the checkout: |
|
<pre> |
|
> cvs -z6 -d :pserver:[email protected]:/home/cvs checkout f2py2e |
|
</pre> |
|
<li> In the directory <code>f2py2e</code> you can get the updates by hitting |
|
<pre> |
|
> cvs -z6 update -P -d |
|
</pre> |
|
</ol> |
|
You can browse <code>f2py</code> CVS repository <a href="http://cens.ioc.ee/cgi-bin/cvsweb/python/f2py2e/">here</a>. |
|
|
|
<h2>Related sites</h2> |
|
|
|
<ol> |
|
<li> <a href="http://pfdubois.com/numpy/" target="_top">Numerical Python</a>. |
|
<li> <a href="http://pyfortran.sourceforge.net/" target="_top">Pyfort</a> -- The Python-Fortran connection tool. |
|
<li> <a href="http://starship.python.net/crew/hinsen/scientific.html" target="_top">Scientific Python</a>. |
|
<li> <a href="http://numpy.org/" target="_top">SciPy</a> -- Scientific tools for Python (includes Multipack). |
|
<li> <a href="http://www.fortran.com/fortran/" target="_top">The Fortran Company</a>. |
|
<li> <a href="http://www.j3-fortran.org/" target="_top">Fortran Standards</a>. |
|
|
|
<li> <a href="http://www.fortran.com/fortran/F77_std/rjcnf.html">American National Standard Programming Language FORTRAN ANSI(R) X3.9-1978</a> |
|
<li> <a href="http://www.mathtools.net" target="_top">Mathtools.net</a> -- A technical computing portal for all scientific and engineering needs. |
|
|
|
</ol> |
|
|
|
|
|
<HR> |
|
<ADDRESS> |
|
<A href="http://validator.w3.org/"><IMG border=0 align=right src="/icons/vh40.gif" alt="Valid HTML 4.0!" height=31 width=88></A> |
|
<A href="http://cens.ioc.ee/~pearu/" target="_top">Pearu Peterson</A> |
|
<A href="mailto:pearu(at)ioc.ee"><pearu(at)ioc.ee></A><BR> |
|
|
|
Last modified: Fri Jan 20 14:55:12 MST 2006 |
|
|
|
</ADDRESS> |
|
|
|
|
|
|
|
|
|
<p> |
|
<center> |
|
This <a href="http://www.ctv.es/USERS/irmina/pythonring.html">Python |
|
ring</a> site owned by <a href="mailto:pearu(at)ioc.ee">Pearu Peterson</a>. |
|
<br> |
|
[ |
|
<a href="http://nav.webring.org/cgi-bin/navcgi?ring=python_ring;id=12;prev5">Previous 5 Sites</a> |
|
| |
|
<a href="http://nav.webring.org/cgi-bin/navcgi?ring=python_ring;id=12;prev">Previous</a> |
|
| |
|
<a href="http://nav.webring.org/cgi-bin/navcgi?ring=python_ring;id=12;next">Next</a> |
|
| |
|
<a href="http://nav.webring.org/cgi-bin/navcgi?ring=python_ring;id=12;next5">Next 5 Sites</a> |
|
| |
|
<a href="http://nav.webring.org/cgi-bin/navcgi?ring=python_ring;random">Random Site</a> |
|
| |
|
<a href="http://nav.webring.org/cgi-bin/navcgi?ring=python_ring;list">List Sites</a> |
|
] |
|
</center> |
|
<p> |
|
|
|
|
|
|
|
</BODY> |
|
|
|
|
|
</HTML> |
|
|
|
|
|
|
|
|