F2PY - Fortran to Python Interface Generator
Author: Pearu Peterson
Keywords: fortran,python,interface,f2py,f2py2e,wrapper,fpig

# F2PY Fortran to Python Interface Generator

by Pearu Peterson

## What's new?

See NEWS.txt for the latest changes in `f2py`.

July ??, 2002
  Implemented prototype calculator, complete tests for scalar F77 functions, --help-compiler option. Fixed number of bugs and removed obsolete features.
April 4, 2002
  Fixed a nasty bug of copying one-dimensional non-contiguous arrays. (Thanks to Travis O. for pointing this out).
March 26, 2002
  Bug fixes, turned off F2PY_REPORT_ATEXIT by default.
March 13, 2002
  MAC support, fixed incomplete dependency calculator, minor bug fixes.
March 3, 2002
  Fixed memory leak and copying of multi-dimensional complex arrays.
Old news.

## Introduction

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 F2PY Fortran to Python Interface Generator. It is completely written in Python language and can be called from the command line as `f2py`. F2PY (in NumPy) is released under the terms of the NumPy License.

## `f2py`, Second Edition

The development of `f2py` 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 `f2py` features:

1. `f2py` 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.
2. `f2py` 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, `f2py` generates `setup_modulename.py` for building extension modules using `distutils` tools.
3. `f2py` uses the signature files to produce the wrappers for Fortran 77 routines and their `COMMON` blocks.
4. For `external` arguments `f2py` constructs a very flexible call-back mechanism so that Python functions can be called from Fortran.
5. You can pass in almost arbitrary Python objects to wrapper functions. If needed, `f2py` takes care of type-casting and non-contiguous arrays.
6. You can modify the signature files so that `f2py` will generate wrapper functions with desired signatures. `depend()` attribute is introduced to control the initialization order of the variables. `f2py` introduces `intent(hide)` attribute to remove the particular argument from the argument list of the wrapper function and `intent(c)` that is useful for wrapping C libraries. In addition, `optional` and `required` attributes are introduced and employed.
7. `f2py` 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.
8. `f2py` 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 `note(<LaTeX text>)` attribute to the definition of routine signatures.
9. With `f2py` one can access also Fortran 90/95 module subroutines from Python.

For more information, see the User's Guide of the tool. Windows users should also take a look at f2py HOWTO for Win32 (its latest version can be found here).

### Requirements

1. You'll need Python (1.5.2 or later, 2.2 is recommended) to run `f2py` (because it uses exchanged module `re`). To build generated extension modules with distutils setup script, you'll need Python 2.x.
2. You'll need Numerical Python (version 13 or later, 20.3 is recommended) to compile C/API modules (because they use function `PyArray_FromDimsAndDataAndDescr`)

### Download

User's Guide:
  usersguide.html, usersguide.pdf, usersguide.ps.gz, usersguide.dvi.
Snapshots of the fifth public release:
  2.x/F2PY-2-latest.tar.gz
Snapshots of earlier releases:
  rel-5.x, rel-4.x, rel-3.x, rel-2.x,rel-1.x, rel-0.x

### Installation

Unpack the source file, change to directory `f2py-?-???` and run `python setup.py install`. That's it!

### Platform/Compiler Related Notes

`f2py` has been successfully tested on

- Intel Linux (MD7.0,RH6.1,RH4.2,Debian woody), Athlon Linux (RH6.1), Alpha Linux (RH5.2,RH6.1) with gcc (versions egcs-2.91.60,egcs-2.91.66, and 2.95.2).
- Intel Linux (MD7.0) with Pacific-Sierra Research Personal Linux VAST/f90 Fortran 90 compiler (version V3.4N5).
- Intel Linux (RH6.1) with Absoft F77/F90 compilers for Linux.
- IRIX64 with gcc (2.95.2) and MIPSpro 7 Compilers (f77,f90,cc versions 7.30).
- Alpha Linux (RH5.2,RH6.1) with Compaq Fortran compiler (version V1.0-920).
- Linux with NAGWare Fortran 95 compiler.
- Intel(R) Fortran Compiler for Linux
- Windows 2000 with mingw32.

`f2py` will probably run on other UN*X systems as well. Additions to the list of platforms/compilers where `f2py` has been successfully used are most welcome.

Note: Using Compaq Fortran compiler on Alpha Linux is succesful unless when wrapping Fortran callback functions returning `COMPLEX`. This applies also for IRIX64.

Note: Fortran 90/95 module support is currently tested with Absoft F90, VAST/f90, Intel F90 compilers on Linux (MD7.0,Debian woody).

### Mailing list

There is a mailing list f2py-users available for the users of the `f2py` program and it is open for discussion, questions, and answers. You can subscribe the list here.

### CVS Repository

`f2py` is being developed under CVS and those who are interested in the really latest version of `f2py` (possibly unstable) can get it from the repository as follows:

1. First you need to login (the password is `guest`):

       > cvs -d :pserver:anonymous@cens.ioc.ee:/home/cvs login

2. and then do the checkout:

       > cvs -z6 -d :pserver:anonymous@cens.ioc.ee:/home/cvs checkout f2py2e

3. In the directory `f2py2e` you can get the updates by hitting

       > cvs -z6 update -P -d

You can browse `f2py` CVS repository here.

## Related sites

1. Numerical Python.
2. Pyfort -- The Python-Fortran connection tool.
3. Scientific Python.
4. SciPy -- Scientific tools for Python (includes Multipack).
5. The Fortran Company.
6. Fortran Standards.
7. American National Standard Programming Language FORTRAN ANSI(R) X3.9-1978
8. Mathtools.net -- A technical computing portal for all scientific and engineering needs.

This Python ring site owned by Pearu Peterson.
[ Previous 5 Sites | Previous | Next | Next 5 Sites | Random Site | List Sites ]