Re: Array of Structures [message #38991 is a reply to message #19984] |
Thu, 15 April 2004 10:39   |
R.Bauer
Messages: 1424 Registered: November 1998
|
Senior Member |
|
|
Craig Markwardt wrote:
>
> Kenneth Bowman <k-bowman@null.tamu.edu> writes:
>
>> In article <a6ebc8fb.0404150705.7a9f883b@posting.google.com>,
>> dsteinberg@whrc.org (Dan Steinberg) wrote:
>>
>>> I am wondering if it is possible to create an array of structures. I
>>> want to read multiple different anonymous structures into a single
>>> variable so I can reference each structure using the variable name and
>>> the array index. Is this possible?
>>>
>>> -Dan
>>
>> See "Arrays of Structures" in Chapter 7 of "Building IDL Applications.
>> You can use REPLICATE to create the array of structures.
>
> That was my first reaction too, but if you read the OP carefully, he
> discusses "multiple *different* anonymous structures," (emph added).
>
> It is impossible to make an array of dissimilar structures in IDL. The
> poster really must use an array of pointers, and then each pointer can
> point to a different structure.
>
> Craig
>
I can show a trick with two of our routines to get arrayed pointers on the
tags and then we can do a reformation of the structure if this is
necessary.
In difference to your answer Craig the pointers are on the tags not several
structures are as pointer arrayed. One tag could be changed without
redefinition of the whole structure. But I am not sure if this is wanted at
the moment. So this is only an addition to your answer.
IDL> names=['file','img']
IDL>
ptr=[ptr_new([ptr_new('file1'),ptr_new('file2')]),ptr_new([p tr_new(bytarr(10,5)),ptr_new(bytarr(10,10))])]
IDL> s=names_and_ptrs2struct(names,ptr)
IDL> help,s,/str
** Structure <81de694>, 2 tags, length=16, data length=16, refs=1:
FILE POINTER Array[2]
IMG POINTER Array[2]
IDL> help,*s.img[0]
<PtrHeapVar21> BYTE = Array[10, 5]
IDL> help,*s.img[1]
<PtrHeapVar22> BYTE = Array[10, 10]
IDL> x=reform_struct(s,2,/struct_arr)
% Compiled module: REFORM_STRUCT.
IDL> help,x,/str
** Structure <81de814>, 2 tags, length=8, data length=8, refs=1:
FILE POINTER <PtrHeapVar18>
IMG POINTER <PtrHeapVar21>
IDL> help,x
X STRUCT = -> <Anonymous> Array[2]
The routines are in the library at
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_lib_intro. html
regards
Reimar
--
Forschungszentrum Juelich
email: R.Bauer@fz-juelich.de
http://www.fz-juelich.de/icg/icg-i/
============================================================ ======
a IDL library at ForschungsZentrum Juelich
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_lib_intro. html
|
|
|