[SciPy-User] fortran unformatted output from python

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[SciPy-User] fortran unformatted output from python

Nikhil
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

_______________________________________________
SciPy-User mailing list
[hidden email]
https://mail.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|

Re: fortran unformatted output from python

Sturla Molden-3
Nikhil <[hidden email]> 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

_______________________________________________
SciPy-User mailing list
[hidden email]
https://mail.scipy.org/mailman/listinfo/scipy-user