[SciPy-User] python + fortran (english)
Thu Apr 19 07:11:02 CDT 2012
Fortran derived types is a tricky issue. The problem is that Python can
only interface with external C libraries. So to call Fortran it must use
C code as proxy, which is what f2py does. Unfortunately a Fortran type
does not map to a C struct on the binary level. The binary interface
(ABI) is compiler dependent.
The solution is to use "Fortran 2003 ISO C bindings" and let a Fortran
subroutine map a C struct to a Fortran type. Use the Fortran C bindings
to export the subroutine as a C callable void function.
Now you can call the Fortran library from Python with ctypes, Cython,
f2py, Swig, CXX, Boost.Python, Python C API, or whatever you prefer.
In theory f2py or fwrap could do this mapping to Fortran derived types.
But I am not sure if they do. I would not waste time on it, just write
the wrapper by hand. It is not tedious if you only have to expose a few
Fortran subroutines to Python.
On 19.04.2012 03:25, Leonardo Mello wrote:
> I'm having a problem getting calls from FORTRAN in Python.
> If I put a structure (TYPE) in the code does not create the f2py
> And if I use of modules with the USE f2py file.so but creates the
> when I enter the python and try to import does not work.
> Does anyone know how to use this library f2py you can help me.
> Thank you
> PS: excuse my english
> SciPy-User mailing list
More information about the SciPy-User