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

Home » Public Forums » archive » nested structures in dlm
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: nested structures [message #84454 is a reply to message #52210] Mon, 27 May 2013 08:03 Go to previous message
Phillip Bitzer is currently offline  Phillip Bitzer
Messages: 223
Registered: June 2006
Senior Member
You can certainly do what you're after. In fact, I do this sort of thing when building arrays of radar data, which may have different lengths, sizes, etc.

First, some basic pointer stuff:

Consider:
IDL> s1 = {tag1:0L, tag2:PTR_NEW(/ALLOCATE)}

Then,
IDL> help, s1
** Structure <314b91d8>, 2 tags, length=8, data length=8, refs=1:
TAG1 LONG 0
TAG2 POINTER <PtrHeapVar14>

So, we see tag2 is a pointer. Fine, let's assign the pointer to a (new) structure:
IDL> *s1.tag2 = {ntag1:0L, nTag2:0L}

Okey doke. So, s1.tag2 is the pointer, and when we dereference this:
IDL> help, *s1.tag2
** Structure <1dc84338>, 2 tags, length=8, data length=8, refs=1:
NTAG1 LONG 0
NTAG2 LONG 0

we see our (new) structure.

What about getting to one of these tags? Notice this doesn't work:
IDL> help, *s1.tag2.ntag2
% Expression must be a structure in this context: <No name>.
% Execution halted at: $MAIN$

But this does:
IDL> help, (*s1.tag2).ntag2
<Expression> LONG = 0

Remember, *s1.tag2 is the pointer, and that's what what we want to dereference. That's why the parentheses are where they are.

Arrays of structures with pointers can be a little more tricky, because you'll be throwing brackets in there too. Just keep in mind where the pointer is.

Further, you'll want to take a look a this for the initialization:

http://www.idlcoyote.com/code_tips/structptrinit.html
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Re: contour discontinuity
Next Topic: contour discontinuity

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

Current Time: Fri Oct 10 08:56:44 PDT 2025

Total time taken to generate the page: 0.00629 seconds