comp.lang.ada
 help / color / mirror / Atom feed
* Re: Extracting contents of binary data files
       [not found] <342eedac.49311445@newsbeta.alt.net>
@ 1997-09-28  0:00 ` Steve Doiel
  1997-09-29  0:00 ` Regarding: " Anonymous
  1 sibling, 0 replies; 2+ messages in thread
From: Steve Doiel @ 1997-09-28  0:00 UTC (permalink / raw)



>2) If so, how do I do the bit-shifting in Ada?

Look to the standard package "Interfaces" for bit shifting functions.

>3) Are there existing Ada library routines available to do this?
>

I don't know if routines are already available, but I would look at
the Public Ada Library (PAL) to try to find them.  I don't know the
URL right off hand, but you can get there from http://www.adahome.com/

I hope this helps,
Steve Doiel





^ permalink raw reply	[flat|nested] 2+ messages in thread

* Regarding: Extracting contents of binary data files
       [not found] <342eedac.49311445@newsbeta.alt.net>
  1997-09-28  0:00 ` Extracting contents of binary data files Steve Doiel
@ 1997-09-29  0:00 ` Anonymous
  1 sibling, 0 replies; 2+ messages in thread
From: Anonymous @ 1997-09-29  0:00 UTC (permalink / raw)



On Sun, 28 Sep 1997 05:45:30 GMT, andy.cornell.nospam@ibm.net wrote:

> Hi:
> 
> I need to extract the contents of some packed binary files (WMO GRIB
> files, to be exact). The data items are contained in a (big-endian)
> continuous stream of bits (no unused bits between data items). The
> number of bits per item doesn't vary within a file, but varies from
> file to file, depending on precision required. The data items are
> unsigned integers, which get converted back to the original real
> values using reference values contained in the header portion of the
> file. The start of the data stream is byte-aligned (I think that's the
> correct terminology), but obviously the following data item's
> alignment with byte boundaries varies.
> 
> I have a Fortran routine which unpacks these files; it reads the
> entire file into an integer array, then performs bit-shift operations
> (IAND, IOR, ISHFT) on bytes to extract and byte-align the data.
> 
> My questions are:
> 1) Is this the best approach using Ada?
> 2) If so, how do I do the bit-shifting in Ada?
> 3) Are there existing Ada library routines available to do this?
> 
> I am using GNAT 3.09 OS/2 (I'll upgrade soon). I am a novice
> programmer (one year of university CS 4 years ago) who is new to Ada;
> I discovered it while reading McConnell's "Code Complete" from
> Microsoft Press. I like what I've seen of Ada so far.
> 
> Thanks in advance.
> 
> Andy Cornell
> andy dot cornell at ibm dot net
> 
> P.S. I'd like to stick with portable solutions as I eventually plan to
> get a big-endian UN*X box.
> 
> 

You have some options. If you're happy with the FORTRAN routine, why not
keep it and call it from Ada? GNAT provides package Interfaces.Fortran
for this purpose.

If you want to write it in Ada, modular types provide for bitwise
logical operations. The modular types defined in package Interfaces also
have shift operations defined for them. So you could read the stream a
byte at a time and use these operations to extract the bit-packed data.

Finally, you might be able to use representation clauses to let you read
all the data with a single operation, and have the compiler figure out
how to extract the individual items. GNAT is pretty good about letting
you have components in records that are not aligned on byte boundaries.

Jeff Carter  PGP:1024/440FBE21
My real e-mail address: ( carter @ innocon . com )
"Illegitimate-faced bugger-folk!"
Monty Python & the Holy Grail
-- 
Jeff Carter  PGP:1024/440FBE21
"Illegitimate-faced bugger-folk!"
Monty Python & the Holy Grail















^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1997-09-29  0:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <342eedac.49311445@newsbeta.alt.net>
1997-09-28  0:00 ` Extracting contents of binary data files Steve Doiel
1997-09-29  0:00 ` Regarding: " Anonymous

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox