views:

146

answers:

1

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.

A: 

I would suggest skipping the fortran business altogether.

http://myweb.dal.ca/gassmann/smps2.htm

The MPS record layout is described here, and looks relatively simple to pick apart in Python.

http://myweb.dal.ca/gassmann/smps2.htm#CoreMPSline

You'll have to define appropriate Python classes (or namedtuples) for all of the data anyway.

I don't think the Fortran is helping.

S.Lott
Good point. The MPS format isn't too bad, I got that more or less nailed already, the trouble starts with the stochastic extensions, where you among other things have the possibility of many embedded MPS specifications.I got the impression I would get the data structures from fortran immediately readable in python, but that could be a misunderstanding on my part.
Lars Hellemo
@Lars Hellemo: Fortran is quite different (I was a Fortran programmer at one point.) An automated translation won't be very clever as a Python structure. At best a tool could create lists of named tuples from the Fortran code.
S.Lott