FPIG ­ Fortran to Python Interface Generator

by Pearu Peterson

What's new?

September 12, 2000
The second public release of f2py is out. See Release notes.
September 11, 2000
Now f2py supports wrapping Fortran 90/95 module routines (support for F90/95 module data coming soon)
June 12, 2000
Now f2py has a mailing list f2py-users open for discussion.

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 FPIG ­ Fortran to Python Interface Generator. It is completely written in Python language and can be called from the command line as f2py. FPIG is released under the terms of GNU LGPL.

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).
  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. 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 routines from Python.
For more information, see the User's Guide of the tool.

Requirements

  1. You'll need Python (1.5.2 or later) to run f2py (because it uses exchanged module re)
  2. You'll need Numerical Python (version 13 or later) 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 second public release:
rel-2.x/f2py-2.latest.tgz
Snapshots of the first public release:
rel-1.x/f2py-1.latest.tgz
Snapshots of the pre-release:
rel-0.x/f2py-0.latest.tgz

Installation

Unpack the source file, change to directory f2py-?-??? and run gmake install (you need GNU make). That's it! To test f2py, run gmake test.

Platform/Compiler Related Notes

f2py has been successfully tested on 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 only with Absoft F90 compiler on Linux (MD7.0).

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:/usr/local/cvsroot login
    
  2. and then do the checkout:
    > cvs -z6 -d :pserver:anonymous@cens.ioc.ee:/usr/local/cvsroot checkout f2py2e
    
  3. In the directory f2py2e you can get the updates by hitting
    > cvs -z6 update -P -d
    

Valid HTML 4.0! Pearu Peterson <pearu@ioc.ee>
Last modified: Tue Sep 12 14:02:34 GMT-2 2000

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