An open API service indexing awesome lists of open source software.

https://github.com/hugomvale/fortran-in-python

Examples of how to build/call Fortran modules in Python
https://github.com/hugomvale/fortran-in-python

ctypes f2py fortran interoperability python

Last synced: 2 months ago
JSON representation

Examples of how to build/call Fortran modules in Python

Awesome Lists containing this project

README

          

# Description

A few examples to illustrate the main steps required to build and call Fortran code from Python with the following tools:

| Tool | Pros | Cons |
| --- |:---: |:---: |
| [ctypes](https://docs.python.org/3/library/ctypes.html) |

  • Allows for tailor-made wrappers.
  • C-API as byproduct.
  • |
  • C-bindings and Python-bindings must be written for all data types and procedures (besides the manual effort, some aspects are not intuitive at all).
  • |
    | [f2py](https://numpy.org/doc/stable/f2py/index.html) |
  • Little/no manual work.
  • Fortran procedures are automatically given a Pythonic signature.
  • Array dimensions become optional arguments.
  • |
  • No support for derived data types, abstract interfaces, etc.
  • No possibility for wrapper customization.
  • |
    | [f90wrap](https://github.com/jameskermode/f90wrap) |
  • Support for derived data types, abstract interfaces, etc.
  • Can parse Doxygen (but not FORD) docstrings.
  • |
  • Procedure signatures remain unchanged (Fortranic, not Pythonic).
  • Procedures with callbacks are excluded (bug?).
  • Support seems limited (just an impression).
  • |
    | [gfort2py](https://github.com/rjfarmer/gfort2py)|
  • to do!
  • |
  • to do!
  • |

    A rather comprehensive list of tools to invoke Fortran code from Python can be found [here](https://github.com/Beliavsky/Fortran-Tools#interoperability).