* binary data files
@ 1999-11-23 2:06 David Covey
1999-11-23 18:46 ` furio ercolessi
1999-11-23 21:25 ` Greg Johnson
0 siblings, 2 replies; 3+ messages in thread
From: David Covey @ 1999-11-23 2:06 UTC (permalink / raw)
To: axp-list
Hi all,
I've been using Linux/Alpha for a while now and slowly working on
a problem I have with binary data files. I *think* I've figured it out
and have a kludge but I'd like to know if someone has come up with a
better explanation and/or solution.
Specifically I've been having problems reading binary data files
with 'variable-length record' format. The records in these files are
prefixed and suffixed with a 4-byte integer with a count of the data
bytes in the record (excluding the prefix and suffix). I often have
data files using this format that have been written on other machines,
and so the data may be byte-swapped. That much can be fixed with a
compiler option, or a 'dd conv=swab...' command. The prefix/suffix
byte-count has an additional twist though, in that it appears to be
word-swapped. Hence a record of 13 bytes would have a 4-byte count
that, on the Linux/Alpha box, looks like the byte sequence :
13 0 0 0
The same data generated on another type of (big-endian) workstation would
have a count :
0 0 0 13
In the case I'm working on now, the actual binary data is byte-swapped
but not word-swapped, only the leading and trailing record size count.
I've written a small C utility that reads a data file and word-swaps
the count, and optionally byte-swaps the data. I'd be happy to make it
available if it would help anyone else.
Please let me know if this is a previously solved problem, if I've
managed to re-invent the wheel, whatever...
- Dave
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: binary data files
1999-11-23 2:06 binary data files David Covey
@ 1999-11-23 18:46 ` furio ercolessi
1999-11-23 21:25 ` Greg Johnson
1 sibling, 0 replies; 3+ messages in thread
From: furio ercolessi @ 1999-11-23 18:46 UTC (permalink / raw)
To: axp-list
On Mon, Nov 22, 1999 at 05:06:51PM -0900, David Covey wrote:
> Hi all,
> I've been using Linux/Alpha for a while now and slowly working on
> a problem I have with binary data files. I *think* I've figured it out
> and have a kludge but I'd like to know if someone has come up with a
> better explanation and/or solution.
[...]
> I've written a small C utility that reads a data file and word-swaps
> the count, and optionally byte-swaps the data. I'd be happy to make it
> available if it would help anyone else.
> Please let me know if this is a previously solved problem, if I've
> managed to re-invent the wheel, whatever...
The Digital/Compaq Fortran compiler (are you talking about Fortran
unformatted files, aren't you..?) has a switch to read/write
big endian files rather than little endian. It works very well
when exchanging files with AIX, HP-UX, Irix and Solaris.
I suppose that you can enable the same switch on a file basis by
putting some parameter in OPEN , and therefore writing a conversion
program should be trivial under Tru64 Unix.
I am not sure that a Compaq Fortran unformatted file is entirely
compatible with a g77 unformatted file; but I would guess it is.
furio ercolessi
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: binary data files
1999-11-23 2:06 binary data files David Covey
1999-11-23 18:46 ` furio ercolessi
@ 1999-11-23 21:25 ` Greg Johnson
1 sibling, 0 replies; 3+ messages in thread
From: Greg Johnson @ 1999-11-23 21:25 UTC (permalink / raw)
To: axp-list
On Mon, Nov 22, 1999 at 05:06:51PM -0900, David Covey wrote:
> Hi all,
> I've been using Linux/Alpha for a while now and slowly working on
> a problem I have with binary data files. I *think* I've figured it out
> and have a kludge but I'd like to know if someone has come up with a
> better explanation and/or solution.
> Specifically I've been having problems reading binary data files
> with 'variable-length record' format. The records in these files are
> prefixed and suffixed with a 4-byte integer with a count of the data
> bytes in the record (excluding the prefix and suffix). I often have
> data files using this format that have been written on other machines,
> and so the data may be byte-swapped. That much can be fixed with a
> compiler option, or a 'dd conv=swab...' command. The prefix/suffix
> byte-count has an additional twist though, in that it appears to be
> word-swapped. Hence a record of 13 bytes would have a 4-byte count
> that, on the Linux/Alpha box, looks like the byte sequence :
> 13 0 0 0
> The same data generated on another type of (big-endian) workstation would
> have a count :
> 0 0 0 13
> In the case I'm working on now, the actual binary data is byte-swapped
> but not word-swapped, only the leading and trailing record size count.
> I've written a small C utility that reads a data file and word-swaps
> the count, and optionally byte-swaps the data. I'd be happy to make it
> available if it would help anyone else.
> Please let me know if this is a previously solved problem, if I've
> managed to re-invent the wheel, whatever...
> - Dave
I write binary data files with XDR to address these issues. I haven't
found a better method than a small C program as you describe to fix old
files, though.
Greg
--
Greg Johnson gjohnson@physics.clarku.edu
http://physics.clarku.edu/~gjohnson finger for PGP key
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~1999-11-23 21:25 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1999-11-23 2:06 binary data files David Covey
1999-11-23 18:46 ` furio ercolessi
1999-11-23 21:25 ` Greg Johnson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox