[SciPy-user] Is it possible to pass Fortran derived data types to Python via C and SWIG?
Sun Nov 30 06:21:20 CST 2008
2008/11/30 David Cournapeau <email@example.com>:
> John Salvatier wrote:
>> I have a Fortran 90 algorithm which uses a derived data type to return
>> data, and I would like to make a python wrapper for this algorithm. I
>> understand that f2py cannot wrap derived data types; is it possible to
>> do so with a C interface for the Fortran algorithm and SWIG? I would
>> have to pass the derived data type into a C struct and then to Python.
> It is possible as long as you can pass the structure from fortran to C.
> I don't know anything about Fortran derived data types, but if it is a
> non trivial object (more than a set of fundamental types), I am afraid
> it will be difficult. Does F90 supports POD data ? Otherwise, you will
> need a scheme for marshalling your data from Fortran to C (to match
> exactly how the structure would look like in C at the binary level).
I've read an article (I don't remember where though, possibly CiSE)
that stated that it's really not an easy task, as each Fortran
compiler can do as it pleases it. So depending on the compiler and the
Fortran standard, it can be possible, or not. So as there are no
guaranties, you should write a function that transforms the Fortran
structure in several pieces that are then passed to the C function.
Information System Engineer, Ph.D.
Blogs: http://matt.eifelle.com and http://blog.developpez.com/?blog=92
More information about the SciPy-user