Calling FORTAN dll functions from Python

  • Thread starter Alex van der Spek
  • Start date
A

Alex van der Spek

Does anyone know how to call functions from FORTRAN dlls in Python? Is it
even possible? I browsed the documentation for Python 2.6.1 and the Python/C
API comes close to what I would like to do but it is strictly limited to C.

Unfortunately the passing of arguments in C and FORTRAN is very different,
not to mention the differences with strings where FORTRAN expects a hidden
length argument. It could call the FORTRAN dll from C and call the C
functions from Python but is that my only option?

For reference: I am using Python 2.6.1 FORTRAN powerstation 4.0. It is not
an option to translate the FORTRAN code to C (using f2c) as the source code
is the official ASME version of calculating steam tables.

I am interested in a solution that will work on Windows (XP and Vista) as
well as Linux (Ubuntu 10.4) although the latter would not use dlls but code
resources.

I am a beginner in Python. The fact that I still use and can use FORTRAN
gives away my age. Mixed language programming is not an issue for me (C/VB,
VB/FORTRAN, C/FORTRAN) but Python is new. Just pointing me to relevant
documentation would be helpful in its own right.

Thank you in advance,
Alex van der Spek
 
S

Stefan Behnel

Alex van der Spek, 07.12.2010 12:11:
Does anyone know how to call functions from FORTRAN dlls in Python? Is
it even possible?

Sure, have a look at fwrap and Cython.

Stefan
 
C

Carl Banks

Does anyone know how to call functions from FORTRAN dlls in Python? Is it
even possible? I browsed the documentation for Python 2.6.1 and the Python/C
API comes close to what I would like to do but it is strictly limited to C.

Unfortunately the passing of arguments in C and FORTRAN is very different,
not to mention the differences with strings where FORTRAN expects a hidden
length argument. It could call the FORTRAN dll from C and call the C
functions from Python but is that my only option?

I'd recommend f2py, which is part of the numpy package.


Carl Banks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top