How do I create a python module from a fortran program with f2py?

Posted by Lars Hellemo on Stack Overflow See other posts from Stack Overflow or by Lars Hellemo
Published on 2010-03-17T13:04:12Z Indexed on 2010/03/17 13:51 UTC
Read the original article Hit count: 271

Filed under:
|
|

I am trying to read some smps files with python, and found a fortran implementation, so I thought I would give f2py a shot. The problem is that I have no experience with fortran.

I have successfully installed gfortran and f2py on my Linux box and ran the example on thew f2py page, but I have some trouble compiling and running the large program. There are two files, one with a file reader wrapper and one with all the logic. They seem to call each other, but when I compile and link or try f2py, I get errors that they somehow can't find each other:

f95 -c FILEWR~1.F
f95 -c SMPSREAD.F90 
f95 -o smpsread SMPSREAD.o FILEWR~1.o 

FILEWR~1.o In function `file_wrapper_'
FILEWR~1.F(.text+0x3d) undefined reference to `chopen_'
usrlibgcci486-linux-gnu4.4.1libgfortranbegin.a(fmain.o) In function `main'
(.text+0x27) undefined reference to `MAIN__'
collect2 ld returned 1 exit status  

I also tried changing the name to FILE_WRAPPER.F but that did not help.

With f2py I found out I had to include a comment to get it to accept free format, and saved this as a new file and tried:

f2py -c -m smpsread smpsread.f90

I get a lot of output and warnings, but the error seems to be this one:

getctype: No C-type found in "{'typespec': 'type', 'attrspec': ['allocatable'],  'typename': 'node', 'dimension': [':']}", assuming void.

The fortran 90 spms reader can be found here.

Any help or suggestions appreciated.

© Stack Overflow or respective owner

Related posts about fortran

Related posts about python