Reading unformatted big-endian files

A

Andrea Gavana

Hello John,
Silently ignoring errors when reading a file doesn't sound like a good
idea to me at all, especially if different records have different
formats.

Yeah, you're right, but the file itself is quite big and I am
interested only in a small part of it. Moreover, the sequence
keyword-number-keytype is unlikely to fail to be read unless the
simulator that outputs the file does something very strange.
(a) read the docs on the struct module

Yes, I have done it, and I have written something similar to what you
propose (well, actually your solution is more elegant than mine :-D )
if keyword == 'DIMENS':
# 'dimens' is neither declared nor initialised in the FORTRAN
# so I'm just guessing here ...

Sorry, I forgot to include it, 'dimens' is an integer(4)

Thank you very much for your explanation, now it is very clear what I
should do. I hope performances will not change so much: fortran is
very fast in reading files (but I use it only in this case, I love to
use Python)... well, let's see :-D

Andrea.
 
J

John Machin

I hope performances will not change so much: fortran is
very fast in reading files (but I use it only in this case, I love to
use Python)... well, let's see :-D

<ot> Well FORTRAN would have to have *something* going for it :)
I vaguely recall in a previous incarnation tarting up a vanilla ratfor
"compiler" with switch statements and macros and all sorts of goodies so
that life was less unbearable :) [this was *before* f77]
</ot>

Suggestions:
(1) Upgrade to 2.5 as soon as it goes final -- struct's performance has
been improved.
(2) Consider the possibility of not unpacking all three variables if you
don't need to -- for example if you are ignoring everything until you
hit a record that starts with 'DIMENS ', you don't need to unpack
anything, just do:

if buff[:8] == 'DIMENS ':

How big are your files, anyway?

Cheers,
John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top