[f2py] Fortran project

Dede ded.espaze at laposte.net
Wed Jun 13 10:18:32 EEST 2007


Hi Ana,

I am doing something similar with XFOIL:
http://raphael.mit.edu/xfoil/, I try to bring some of the 
 functionalities to Python.
For the steps, first all the fortran files need to be compiled to
objects. Then you have a f2py file that describes the interface
available to Python. At the end you link everything into one module,
including the third part libraries, like lapack and f77blas.

For doing all that steps, you can use the numpy.distutils package
inside a setup.py, you can write a Makefile or a SCons file.

Another approach is to turn your Fortran set of files into a shared
library and link with the third part libraries at that step. This
is easier to achieve because I guess that you already know how to build
your project. Then you just write one interface file,
"interface.f", that use the f2py syntax and call subroutines from
your shared library. You get the module like that:

f2py -c -m your_module -lyour_library interface.f

As a mechanical student, it took me time to understand that approach
because the bindings documentation (like SWIG or f2py) describes of
course the bindings syntax, everybody is supposed to know about 
shared libraries.
I gave a presentation last week about how to write bindings to MBDyn
here:
http://mbdynsimsuite.sourceforge.net/presentation1.pdf
This is with C++ and SWIG but the philosophy is the same and I hope
some of the drawing will help you to understand. Do not hesitate to ask
questions, I had the same feeling as you some months ago.

Best regards,

Dede


On Tue, 12 Jun 2007 14:06:23 -0400
Ana Viana <ana.gomes.viana at gmail.com> wrote:

> Hi,
> 
> I have a Fortran set of files that I would like to wrap into Python,
> but I am not managing to do that with f2py.
> I have been searching for info but with no success. So, I wonder if 
> someone can help me...
> 
> In Fortran things work as follows: I have several fortran files. Once 
> compiled, at execution time, there is an input parameter - the name
> of a file with input data.
> 
> I have looked at your list and found some info there, that I tried to 
> use with no success. These are the steps I have followed:
> 
> f2py -m teste -h teste.pyf  *.f
> 
> f2py -llapack -lf77blas  -c teste.pyf  *.o
> 
> 
> But I think I am not doing things correctly.
> Needless to say, I am new in this subject...
> 
> Ana
> 
> 
> 
> _______________________________________________
> f2py-users mailing list
> f2py-users at cens.ioc.ee
> http://cens.ioc.ee/mailman/listinfo/f2py-users



More information about the f2py-users mailing list