Python Fortran integration

“Glue” modules are required – python cannot call C, and presumably fortran, functions directly.

adding fortran to python explains how to wrap fortran code so that it is callable from a python script.

I really think this is the way to go, at least for development. There’s no reason for a big batch job to have a python interface, but when you’re tweaking an algorithm, the speed with which you can tweak things and visualise the results is everything.

Beazly paper on scientific computing with python

It appears that calling fortran from python is a two-step process. First you need to write a C interface to the fortran, and then call the C from python. This seems like a lot of work if the fortran code is under development – every time you add an argument, you need to change the interface declaration, in two more places.

I’ve taken the following from Summer 2002 Report about Hybrid Systems Modelling by Simon Lacoste-Julien


(file cCallsF.c):
extern void hello_();
int main() {
hello_();
return 1;
}
(file fhello.f):
SUBROUTINE HELLO()
PRINT *, 'Hello world! I''m in Fortran!'
END SUBROUTINE HELLO
building commands:
gcc -c cCallsF.c
g77 cCallsF.o fhello.f -o cCallsF.exe

The manual on the main python website covers in detail the extension of python with C.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: