comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: read a C written binary file with IDL
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: read a C written binary file with IDL [message #79235 is a reply to message #79234] Thu, 09 February 2012 20:56 Go to previous messageGo to previous message
manodeep@gmail.com is currently offline  manodeep@gmail.com
Messages: 33
Registered: June 2006
Member
Hi,

This is because C pads the structure to produce alignments. Under
'normal' operations, you would expect MyStruct to be 20 bytes,
however, if you do a sizeof(struct MyStruct), you will probably see
that the size is 24. (And you can enable the warning for gcc by using
the compile time option -Wpadded).

In general, the padding is compiler specific -- so there is no
standard way of reading in those binary files into IDL/other codes.
The best bet would be to write out the individual fields of the
structure and then read them back into IDL.

HTH,
Manodeep

On Feb 9, 9:44 pm, bing999 <thibaultga...@gmail.com> wrote:
> Hi,
>
> I am having a problem with reading a C written binary file with IDL.
> It may come from differences of type definitions between C and IDL but
> I could not really figure out from Google...
>
> In C, it writes a structure containing the following variable types:
>
> struct MyStruct
> {
> int a;
> long long b;
> int c;
> float d;
>
> };
>
> Then, in IDL, I read this with:
>
>   MyStruct = {$
>             a             : 0L, $
>             b             : 0LL, $
>             c             : 0L, $
>             d             : 0.0  $
>             }
>
>      openr, 1, filename, /SWAP_IF_BIG_ENDIAN
>      readu, 1, MyStruct
>      close, 1
>
> but this gives me wrong values.
>
> Did I miss something about the type conversion??
>
> If someone could please clarify this, it would really help!
> Thanks !
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: tracking clusters through multiple timesteps
Next Topic: Making a html image map?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 06:34:16 PDT 2025

Total time taken to generate the page: 0.95580 seconds