[SciPy-User] writing data to binary for fortran

Gideon gideon.simpson at gmail.com
Wed May 12 15:58:28 EDT 2010


Tried both, but I got the same error in both cases.

On May 12, 2:00 pm, Neil Martinsen-Burrell <n... at wartburg.edu> wrote:
> On 2010-05-12 12:56, Gideon wrote:
>
>
>
>
>
> > I've tried the following.
>
> > In Python:
> > import numpy as np
> > from FortranFile import FortranFile
>
> > x = np.random.rand(10)
> > f = FortranFile('test.bin',mode='w')
> > f.writeReals(x)
> > f.close()
>
> > In Fortran:
> >        program bintest
>
> >        double precision x(10)
> >        integer j
>
> >        open(unit=80, file='test.bin', status='old', form='unformatted')
>
> >        read(80) x
> >        close(80)
>
> >        do j=1,10
> >           write(*,*) x(j)
>
> >        enddo
>
> >        end
>
> > then at the command line,
>
> > gfortran bintest.f -o bintest
> > ./bintest
> > At line 9 of file bintest.f (unit = 80, file = 'test.bin')
> > Fortran runtime error: I/O past end of record on unformatted file
>
> > Note, I have no difficulty reading the test.bin file back in, while in
> > python, using the FortranFile.py routines.
>
> It is likely that the problem is with the endian-ness of the file being
> created by FortranFile not matching what is expected by the fortran
> compiler.  (There is a reason that the format of unformatted I/O is not
> specified in the Fortran standard.)  Try the above with different
> settings of FortranFile(..., endian='<') or '>' or '='.
>
> -Neil
> _______________________________________________
> SciPy-User mailing list
> SciPy-U... at scipy.orghttp://mail.scipy.org/mailman/listinfo/scipy-user
>
> --
> You received this message because you are subscribed to the Google Groups "SciPy-user" group.
> To post to this group, send email to scipy-user at googlegroups.com.
> To unsubscribe from this group, send email to scipy-user+unsubscribe at googlegroups.com.
> For more options, visit this group athttp://groups.google.com/group/scipy-user?hl=en.



More information about the SciPy-User mailing list