|
Re: Pointers and Structures and Loops - oh my! [message #78639 is a reply to message #78638] |
Sat, 03 December 2011 10:48  |
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 #78641 is a reply to message #78640] |
Sat, 03 December 2011 10:38  |
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.")
|
|
|