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

Home » Public Forums » archive » Re: Pointers and Structures and Loops - oh my!
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
Re: Pointers and Structures and Loops - oh my! [message #78638] Sat, 03 December 2011 11:04
Avian is currently offline  Avian
Messages: 24
Registered: October 2011
Junior Member
and thanks! that solved the problem!
Re: Pointers and Structures and Loops - oh my! [message #78639 is a reply to message #78638] Sat, 03 December 2011 10:48 Go to previous message
Avian is currently offline  Avian
Messages: 24
Registered: October 2011
Junior Member
Ah, maybe I misinterpreted something in your last post.

I've been defining a structure ahead of time, then creating it that way. But if I use create_struct directly, I'm betting that should get around the whole problem of different structures!
Re: Pointers and Structures and Loops - oh my! [message #78640 is a reply to message #78639] Sat, 03 December 2011 10:42 Go to previous message
Avian is currently offline  Avian
Messages: 24
Registered: October 2011
Junior Member
Hi David,

Thanks for your response! That's what I tried at first. However, in the for loop, the struct will be redefined in every iteration, leading to instant unhappiness within IDL.
Re: Pointers and Structures and Loops - oh my! [message #78641 is a reply to message #78640] Sat, 03 December 2011 10:38 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Avian writes:

> I'm looking for an elegant way to read in data with different formats into one array. In other words, every record will have a (slightly) different structure, which is easily calculated within the loop for each record.
>
> Is there a way to tell IDL to redefine a structure within a loop, but still somehow keep it so I can point to it? or... What is the best way to store the structure in a way where I can use pointers to it to access it in a single array? I can't seem to get the magic combination of pointers and structures to do this.

You need a pointer array.

ptrs = PtrArr(n)
FOR j=0,n-1 DO BEGIN
...
struct = Create_Struct(...)
ptrs[j] = Ptr_New(struct)
...
ENDFOR

Then, later, you can access a field in your structure
like this:

data = (*ptrs[j]).fieldwhatever

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Pointers and Structures and Loops - oh my!
Next Topic: How to create a 2D mask that automatically half’s an irregularly shaped 2D array from top to bottom?

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

Current Time: Wed Oct 08 19:22:38 PDT 2025

Total time taken to generate the page: 0.00503 seconds