Dave
Dave

Reputation: 21

f2py and the WRITE statement

I've tried searching for this answer as it doesn't seem too complicated, but I've had no success. I'm trying to work with some old FORTRAN code and bring it into Python so I can use it. In the process I've come across some issues with file I/O, and I'm trying to understand how this would be handled by f2py. I'm working on Ubuntu 11.10 with gfortran. For example, I was trying to use the following subroutine:

C     FILE INOUT.F

      SUBROUTINE INOUT
     i     (NAME, STUFF)

Cf2py Intent(in,out) NAME, STUFF

      CHARACTER*6 NAME, STUFF

      OPEN(unit=1,file=NAME)
      WRITE(1,100) STUFF
 100  FORMAT(A8) 

      RETURN
      END

I then compile using gfortran and f2py:

f2py -c -m inout inout.f

Which creates the inout.so shared library. Then in Python, I try a simple test:

python
>>> import inout
>>> inout.inout('test','hello')
('test', 'hello ')

Then exit out of Python and open the newly created "test" file, and it's empty. I can print to the screen no problem, but printing to a file doesn't seem to work. Any guidance would be appreciated. The f2py documentation doesn't mention WRITE statements.

Upvotes: 2

Views: 949

Answers (1)

Raniere Silva
Raniere Silva

Reputation: 2697

You can see here,

Python I/O will not catch I/O from Fortran.

Upvotes: 2

Related Questions