Re: Convert a byte array to a structure? [message #28880 is a reply to message #28877] |
Thu, 17 January 2002 14:57   |
Bhautik Joshi
Messages: 21 Registered: November 2001
|
Junior Member |
|
|
> Does IDL have a simple and/or elegant way to convert a byte array
> into a structure?
> ..
> But is there a better, platform independent, way?
> (Windows NT/2K, Linux, and Solaris)
I wouldn't mind finding this out myself (its a nifty trick). However,
from what I can see, a simple method is not possible? Please, correct me
if I'm wrong.
There is a newsgroup post from a while back here (from JD Smith):
http://groups.google.com/groups?q=converting+type+struct+gro up:comp.lang.idl-pvwave++group:comp.lang.idl-pvwave&hl=e n&selm=3BAF6CAD.CFB19104%40astro.cornell.edu&rnum=3
The structure of a structure in memory is something like:
typedef struct { /* Reference to a structure */
IDL_ARRAY *arr; /* ^ to array block containing data */
struct _idl_structure *sdef; /* ^ to structure definition */
} IDL_SREF;
So what you have is data, stored as bytes in an array, that is the data
that fills out the structure fields, all concatenated together. Then
there is the 'context', which defines the data types of the fields and
how many bytes each field takes up. So, if you could extract the data
and context blocks (I haven't tried this before, but using pointers and
stuff, just like good old C) and then play with it from there...
Another option would be to use the READS command and use explicitly
formatted I/O to format the data into fields. I'm having a look at that
now, and I'll get back to you on that one :)
cheers,
Bhautik
--
/--------------------------------------------------(__)----- ----\
| nbj@imag.wsahs.nsw.gov.au | phone: 0404032617 |..|--\ -moo |
| ICQ #: 2464537 | http://cow.mooh.org | |--| |
|---------------------------+----------------------\OO/|| ------/
| international |
| roast. my sanity has gone |
| its lost forever |
\---------------------------/
|
|
|