[SciPy-User] writing data to binary for fortran
Neil Martinsen-Burrell
nmb at wartburg.edu
Wed May 12 16:21:17 EDT 2010
On 2010-05-12 14:58, Gideon wrote:
> Tried both, but I got the same error in both cases.
If you want doubles in your file, you have to request them:
F.writeReals(x, prec='d')
makes everything work for me (Ubuntu 10.04, python 2.6.5, gfortran
4.4.3). Note that looking at the size of the file that you would expect
to have for the data you are expecting to read would have demonstrated
this: 10 doubles at eight bytes per double plus two 4-byte integers
would have given you 88 bytes for the file, rather than the 48 that were
being produced.
I use fortranfile most heavily for reading files, rather than writing
them, so I may have missed this opportunity, but do you think that the
precision used in writeReals should be auto-detected from the data type
that it is passed. That is, would
def writeReals(self, reals, prec=None):
if prec is None:
prec = reals.dtype.char
...
be better for your use? That would have made your original code work as
written.
-Neil
More information about the SciPy-User
mailing list