[SciPy-User] reading in files with fixed with format

Athanasios Anastasiou athanastasiou at gmail.com
Thu Jul 7 06:57:16 EDT 2011


Hello Wolfgang

My understanding is that you have binary data packed in a file as a
series of numbers (like a vector of floats or doubles) or as a series
of structures (like a set of records) as opposed to fixed width text
data.

To read and convert binary data you can use the struct module
(http://docs.python.org/library/struct.html). The documentation
contains some representative examples. You just have to make sure that
unpack's fmt "structure definition" matches exactly the fortran
definition in terms of data types. Also, please note that fortran
stores arrays in column major format (rather than row major format
which is the default for C). You might have to take this into account
depending on the way the data was written to your files originally.

All the best
Athanasios



On Thu, Jul 7, 2011 at 8:51 AM, Wolfgang Kerzendorf
<wkerzendorf at googlemail.com> wrote:
> Dear all,
>
> I have a couple of data files that were written with fortran at a fixed
> with. That means its tabular data which might not have spaces (it is
> just specified how many characters each field has and what type it is).
> Is there anything to read that with scipy and or numpy?
>
> Cheers
>     Wolfgang
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>



More information about the SciPy-User mailing list