Interfacing Fortran code from Python

I have been working on a project that seems to parallel this well, I would like to interface between python and existing fortran code directly, instead of the existing I/O which uses text files. I am using the approach of writing a wrapper function with c_iso_binding, and then wrapping this with cython. This seems to work pretty well, but I have two questions I hope the group could help with.

  1. Is there any work on automatic wrapper code generation? This part is time consuming and fragile, and not a lot of fun for functions with 20+ arguments. I also ran into some errors in this process, and the debugging was a nightmare.

  2. Is it possible to work with allocatable fortran arrays with this workflow? I think the holdup is cython, but I can’t find a working example.

Any help is appreciated! I am just starting to learn fortran and I find it very interesting. I think for me, it will remain in the near future much more practical with a convenient interface to python.

2 Likes