Python and Fortran code

Berthold Höllmann bhoel at server.python.net
Thu Jul 8 17:03:10 EDT 1999


Scott Wolford wrote:
> 
> Look at a combination of the SWIG tool (I can't remember where it's at but it
> stands for Simplified Wrapper Interface Generator so you can search for it) and
> a C wrapper for you fortran function. Basically, make it so you can call the
> fortran from C. Then swig the C function and link the cstuff.o and fstuff.o with
> cstuff_wrap.o (from SWIG) into a shared library then you can follow choice 2
> from the other response to this post.
> 
> Scott
> 
> Jose L Gomez Dans wrote:
> 
> > Hi!
> >         I have a quetion on using python to do some simple processing on
> > some data I pre-process with some Fortran code. I wanted to be able to call
> > this subroutine from within python, as it is already "tried and tested" and
> > optimized. Basically, my subroutine looks like this:
> >
> >         subroutine ex1(exdata)
> >         dimension exdata(256,200)
> >         print*,'Doing some processing in FORTRAN'
> >  C      We said we were doing some processing, so we might as well do it :)
> >  C      Processing of exdata
> >         return
> >         end
> >
> >         This subroutine would need to get input from the user and would also
> > need to print stuff out for the user to see several parameters as the
> > software runs. I'd like to pass exdata as a Python object (NumPy array
> > object), and then recover it with the results. I wonder if I could somehow
> > do that compiling this subroutine as an object file and then calling it from
> > python (not that i know how to do it, but with scilab, it works :D).
> >
> >         If it's of any use, I am using Debian GNU/Linux and g77. And using
> > loads of complex numbers :))))
> >
> >         Thanks in advance!
> >         Jose
> >

For the Fortran wrapping you might take a look at cfortran.h avaible
from http://www-zeus.desy.de/~burow/ which is helpfull if you want
making the wrapping platform independent.

Greetings

Berthold
-- 
bhoel at starship.python.net / http://starship.python.net/crew/bhoel/
        It is unlawful to use this email address for unsolicited ads
        (USC Title 47 Sec.227). I will assess a US$500 charge for
        reviewing and deleting each unsolicited ad.




More information about the Python-list mailing list