accessing fortran modules from python

Robert Kern robert.kern at gmail.com
Thu Nov 16 16:36:01 EST 2006


sam wrote:
> hello all,
> 
> i am currently in the process of planning a piece of software to model
> polymerisation kinetics, and intend to use python for all the
> high-level stuff. the number-crunching is something i would prefer to
> do in fortran (which i have never used, but will learn), but i have no
> experience of accessing non-python code from python. i am also fairly
> new to programming period, and am therefore tackling a fairly serious
> issue reletive to my experience.
> 
> how easy is it to get fortran modules running from python? if c is
> easier to use in this respect, i could go in that direction instead.
> 
> i realize there is a lot of material on this subject already available,
> but i am finding it difficult to make sense of, it's like trying to
> take a drink from a fire hose.
> 
> any advice would be gratefully received. i will almost certainly be
> coding this on windows, for what it's worth.
> 
> thank you,
> 
> sam
> 
> PS if numpy is adequate for this, i would be quite happy to use it. i
> got the impression it was more for matrix algebra. i will be
> programming a monte carlo simulation, which will need to perform a lot
> (a lot!) of simple operations over and over...

numpy isn't for matrix algebra, specifically. It is primarily designed for
operations on arrays. If your simple operations can be "vectorized," then numpy
will benefit you. If you can describe your needs in more detail, we'll be happy
to give you suggestions on the numpy-discussion list.

  http://www.scipy.org/Mailing_Lists

Of course, since the major player in wrapping Fortran libraries for Python is
f2py, a component of numpy, you're probably going to end up installing numpy
anyways.

  http://numpy.scipy.org

All of the f2py documentation is currently in the source, so start here:

  http://projects.scipy.org/scipy/numpy/browser/trunk/numpy/f2py/docs/README.txt

Using f2py to wrap Fortran subroutines is actually a fair bit simpler than
wrapping C code, mostly because typical Fortran uses a limited set of simple types.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco




More information about the Python-list mailing list