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

Home » Public Forums » archive » ASSOC and structures don't mix
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
ASSOC and structures don't mix [message #11105] Thu, 12 March 1998 00:00
Brian Jackel is currently offline  Brian Jackel
Messages: 34
Registered: January 1998
Member
Recently some people have remarked that ASSOC is a useful
tool for I/O. While this is true, there is a subtle problem
when reading structures from a file that was not written
using ASSOC. The following script demonstrates what I'm
talking about. Of course, the obvious workaround is to
write the files using ASSOC as well, but that is not always
an option.

;
;IDL script to demonstrate why it's dangerous
;to use ASSOC with structures.
;


;Make a test structure, write it out with some
;values in it.
;
test= {PROBLEM, a:0b, b:FLTARR(3)}
OPENW,lun,'test.dat',/GET_LUN
FOR indx=0,3 DO BEGIN
test.a= indx
test.b= [indx,indx+0.5,indx+1.5]
WRITEU,lun,test
ENDFOR
CLOSE,lun


;Reading it back in works like a charm...
;
OPENR,lun,'test.dat',/GET_LUN
READU,lun,test & PRINT,test
READU,lun,test & PRINT,test
READU,lun,test & PRINT,test


;...but the results from ASSOC aren't so good
;
dat= ASSOC(lun,{PROBLEM})
PRINT,dat(0)
PRINT,dat(1)
PRINT,dat(2)


;because IDL is zero padding the structure to
;some multiple of 8 bytes (?). There's actually
;only 13 bytes (assuming 4 byte floats).
;
HELP,/STR,{PROBLEM}

END
--
Brian Jackel
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: PS OUTPUT ON HP LASER JET
Next Topic: B-Splines in IDL

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

Current Time: Wed Oct 08 15:34:38 PDT 2025

Total time taken to generate the page: 0.00544 seconds