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

Home » Public Forums » archive » Convert a byte array to a structure?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Convert a byte array to a structure? [message #28889] Thu, 17 January 2002 12:10
mikef is currently offline  mikef
Messages: 9
Registered: May 1998
Junior Member
Does IDL have a simple and/or elegant way to convert a byte array
into a structure?

I could write a brute force approach like:

proc arr_to_struct_1, arr, struct, idx
ntag = N_Tags(struct)
If (ntag Eq 0) Then return ; Not a structure
If (N_Params() LT 3) Then idx = 0

For i=0, ntag-1 Do Begin
sz = Size(struct.(i), /STRUCTURE)
Case sz.TYPE_NAME Of
'STRUCT': Begin ; Recurse to convert
tmp = struct.(i)
arr_to_struct, arr, tmp, idx
struct.(i) = tmp
End
'Byte': Begin
If (main.N_DIMENSIONS Eq 0) Then Begin
struct.(i) = arr[idx]
EndIf Else Begin
struct.(i) = Byte(arr,idx,DIMENSIONS[0], $
DIMENSIONS[1],DIMENSIONS[2],DIMENSIONS[3],
DIMENSIONS[4],DIMENSIONS[5],DIMENSIONS[6],
DIMENSIONS[7])
End
idx = idx + sz.N_ELEMENTS
End
'Int': Begin
.
.
.
Else: Begin
;Some error message
End
EndCase
EndFor
end


Or I could thrash the filesystem.

proc arr_to_struct_2, arr, struct
Openw, lu, 'trash.tmp', /GET_LUN
Writeu, lu, arr
Free_Lun, lu
Openr, lu, 'trash.tmp', /GET_LUN
Readu, lu, struct
Free_Lun, lu
end

But is there a better, platform independent, way?
(Windows NT/2K, Linux, and Solaris)
--
--
Mike Fitzgibbon MRFitz@ns.arizona.edu
UofAz, LPL phone:(520)626-4791
Systems Programmer, Pr. fax: (520)621-6783
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Responsible retail of "Herbal Highs" [Ultra-Off-Topic]
Next Topic: Large TIFF file question

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

Current Time: Wed Oct 08 13:40:49 PDT 2025

Total time taken to generate the page: 0.00446 seconds