fortran unformatted output from python
![](https://secure.gravatar.com/avatar/c046597eca36463300cb6c9630e5f7f3.jpg?s=120&d=mm&r=g)
Hi, I am trying to write a binary unformatted sequential output from python using fortranfile.py module. I have managed to figure out most of the code, but I am stuck when I need to use the boolean operation. In fortran file, i need to add some metadata, where I need to provide .false. in the output. When i try o use the struct module to write struct.pack('?',False), it doesnt seem to be recognized by fortran. I was wondering if someone has some suggestions in this regard. Thanks, nikhil
![](https://secure.gravatar.com/avatar/2a9d09b311f11f92cdc6a91b3c6519b1.jpg?s=120&d=mm&r=g)
Nikhil <nikhilgarg.gju@gmail.com> wrote:
In fortran file, i need to add some metadata, where I need to provide .false. in the output. When i try o use the struct module to write struct.pack('?',False), it doesnt seem to be recognized by fortran.
I was wondering if someone has some suggestions in this regard.
The Fortran standard does not specify anything about the ABI of unformatted I/O. SciPy's fortranfile.py usually work, but this is strictly speaking by accident. If you want to be sure, do your I/O in a Fortran subroutine and call it from Python using e.g. f2py. (Or if you are paranoid about portability, use Cython and Fortran 2003 ISO C bindings.) Note that unformatted output is not even portable between Fortran compilers, or even between different versions of the same compiler. For this reason, I always recommend that Fortran's I/O facilities are never used, particuarly unfornatted files, and that all I/O is taken care of in Python or C. Sturla
participants (2)
-
Nikhil
-
Sturla Molden