accessing fortran modules from python

S

sam

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...
 
B

Beliavsky

sam said:
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 strongly recommend learning Fortran 95, rather than Fortran 77
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?

G95 is a good, free Fortran 95 compiler -- I use it heavily, on
Windows. A discussion of "How to interface with Python programs" using
numpy is at http://www.g95.org/howto.html#python .

There is a numpy group http://groups.google.com/group/Numpy-discussion
with a recent thread "accessing FORTRAN from Python". There is also a
g95 group http://groups.google.com/group/gg95 .
if c is easier to use in this respect, i could go in that direction instead.

easier to interface with Python, but not easier for writing numerical
code IMO, especially if you need multidimensional arrays.

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...

Fortran 95 has some of the advantages of numpy -- you perform
operations on whole arrays and array sections. It would probably be
considerably faster for code with loops.
 
R

Robert Kern

sam said:
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
 
S

sam

thanks guys,

i'll follow this up more in a couple of weeks when i know what i need
to do better.

sam
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top