[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: One for the experts...



One for the experts?   This is entrapment!   But it's interesting;  I'll bite
regardless...

  gadagkar@norland.com wrote:
> I have been using IDL (on a Linux OS) for R&D work but our normal application
> software is a DOS application written in C. The database and image header
> structures have been written such that there are no bytes appended to fields
> of structures that do not align themselves on 8 byte boundaries. The spaces
> (if any) between fields of a structure are removed by using the "packed"
> attribute (GNU CC). So what I have to do is read binary files that have
> headers that are "packed" from an IDL application running on a Linux box.

I haven't looked into this thoroughly, just a bit, but as far as I can tell,
IDL's READU and WRITEU (with structures) keep files lean.  READU expects to
find no padding bytes in the file (it pads up after reading), and WRITEU
writes no padding bytes (it strips them off before writing).  By padding
bytes I mean both alignment bytes before multibyte structure members and
alignment bytes between structure array elements (if you have an array of
structures).

So if you define an IDL structure that exactly matches your C structure, READU
and WRITEU *will* work.

Well, I guess I forgot about strings for the moment.   If your C structure
includes string members, they will be defined as fixed-length char arrays, of
course.   You should do the "same" in your IDL structure - use BYTARRs of the
same size as in the C structure for these members.

IDL's other method for accessing binary files - ASSOC - is a bit different.
The past and current-default behaviour for ASSOC is that it DOES read and
write padding bytes.  In IDL 5.2, though, there's a new keyword PACKED that
will make ASSOC work lean.

I don't know IDL/Linux but with IDL/Windows there is another little nasty
lurking about.   If you want to be 100% sure of doing strict BINARY I/O on
IDL/Windows, you have to open your files with /BINARY,/NOAUTOMODE, otherwise
things can occasionally go bizarrely wrong.


Peter Mason

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own