By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,611 Members | 1,642 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,611 IT Pros & Developers. It's quick & easy.

accessing fortran modules from python

P: n/a
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...

Nov 16 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a

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

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

Nov 16 '06 #2

P: n/a
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/nump...ocs/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

Nov 16 '06 #3

P: n/a
sam
thanks guys,

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

sam

Nov 16 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.