15

I know of, and have used f2py2e to wrap some old Fortran 77 code, but my understanding is that it does not work with newer Fortran 95 code. I've researched what I should use, and have come across fwrap and G3 f2py, neither of which seem to give any explanation of their current state, or how to use them. I have seen that the version of f2py has the option to use the third generation f2py, but it is commented as being non-functional. Given this, I don't know which project I should use. Which one should I use?

This question has now been cross-posted to (and answered at) Computational Science stack exchange site as Which package should I use to wrap Modern Fortran Code with Python?

7
  • 2
    maybe calling fortran libraries through ctypes would be an option? Commented May 19, 2012 at 14:29
  • 1
    f2py (as included in scipy) seems to claim to support Fortan95. Have you tried it? Commented May 19, 2012 at 17:02
  • 2
    You might also try asking on scicomp.stackexchange since there are a lot of people over there that work with Python and Fortran. Commented May 19, 2012 at 17:05
  • 1
    You might make progress by using modern Fortran's 'interoperability with C' features and making your compiled Fortran present a C-like interface to the outside world. Commented May 22, 2012 at 11:45
  • 1
    @JamesTocknell, it has been 8 years now, and I am curious of how this turned out. What path did you pick, and how did that turn out? Commented Mar 11, 2020 at 21:48

1 Answer 1

9

I have used SWIG to wrap some C/C++ code before but they don't support Fortran. They link to the following, though

At least FortWrap states that they support Fortran95, but you might have to use FortWrap to get C/C++ wrappers and SWIG for the Python wrappers. f90wrap will automatically generate the Python wrappers based on the f90 sources (and supports derived types).

Sign up to request clarification or add additional context in comments.

2 Comments

I mentioned F2PY, and I'd much rather avoid SWIG. Also pyfortran is old code which probably won't work with numpy (it's designed for Numeric), and FortWrap is designed for C++, again lacking integration with numpy.
I just discovered f90wrap thanks to this answer. You saved my day!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.