|
Re: How to add a new tag to N structures [message #69989 is a reply to message #69972] |
Thu, 04 March 2010 04:00  |
R.Bauer
Messages: 1424 Registered: November 1998
|
Senior Member |
|
|
nata schrieb:
> Hi guys,
>
> I want to add a new TAG to an array of structures. I don't know how to
> do that efficiently.
> For example, this is my array:
>
> str={a: 0l, b: ''}
> str_arr=REPLICATE(str,10)
>
> And I can't do things like this:
>
> FOR i=0, 9 DO str_arr[i]=CREATE_STRUCT(str_arr[i],'C',0l)
> or
> str_arr=CREATE_STRUCT(str_arr[i],'C',0l)
>
> This is just an example, my real structs contain a lot of fields.
>
> For some reasons I can define the C tag before so I have to add to
> each struct later. There is a way to do that without creating the new
> struct array and copying each field separately ?
> Thanks,
> nata
well you can reform your array of structures to an structure with
arrays. then you can add your new tag to that structure. Afterwards
reform it back to your array of structures
e.g.
str={a: 0l, b: ''}
str_arr=REPLICATE(str,10)
ref_str = reform_struct(str_arr, /tag_array, 10)
ref_str = create_struct(ref_str, 'c' ,make_array(10))
help, ref_str, /str
** Structure <2800d48>, 3 tags, length=240, data length=240, refs=1:
A LONG Array[10]
B STRING Array[10]
C FLOAT Array[10]
str = reform_struct(str_arr, /struct_array, 10)
help, str
STR STRUCT = -> <Anonymous> Array[10]
You get reform_struct from
http://www.fz-juelich.de/icg/icg-1/idl_icglib/idl_source/idl _html/dbase/reform_struct_dbase.pro.html
cheers
Reimar
|
|
|
Re: How to add a new tag to N structures [message #70007 is a reply to message #69989] |
Wed, 03 March 2010 11:44  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
pp writes:
> I meant associative arrays. I do not know yet how IDL 8 will implement
> and call them. Python calls them dictionaries, C++'s STL, calls them
> maps, and Java calls their common interface map (it has a bunch of
> different implementations, including hashtables, trees, and arrays).
Oh, I think they are going to be called "lists" and "hashes".
I guess I see how that might make things easier for you. :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
Re: How to add a new tag to N structures [message #70008 is a reply to message #70007] |
Wed, 03 March 2010 11:37  |
penteado
Messages: 866 Registered: February 2018
|
Senior Member Administrator |
|
|
On Mar 3, 4:02 pm, David Fanning <n...@dfanning.com> wrote:
> pp writes:
>> But presumably this will not be necessary in IDL 8,
>> since it will finally have dictionaries.
>
> Now I understand why my kids have never opened one:
> we must mean different things by the word. What in
> the world is a "dictionary" in this context!?
I meant associative arrays. I do not know yet how IDL 8 will implement
and call them. Python calls them dictionaries, C++'s STL, calls them
maps, and Java calls their common interface map (it has a bunch of
different implementations, including hashtables, trees, and arrays).
|
|
|
Re: How to add a new tag to N structures [message #70012 is a reply to message #70008] |
Wed, 03 March 2010 11:02  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
pp writes:
> But presumably this will not be necessary in IDL 8,
> since it will finally have dictionaries.
Now I understand why my kids have never opened one:
we must mean different things by the word. What in
the world is a "dictionary" in this context!?
Cheers,
An Oldster
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
Re: How to add a new tag to N structures [message #70013 is a reply to message #70012] |
Wed, 03 March 2010 10:44  |
penteado
Messages: 866 Registered: February 2018
|
Senior Member Administrator |
|
|
On Mar 3, 3:07 pm, wlandsman <wlands...@gmail.com> wrote:
> Well, I don't know how to avoid creating a new structure but you can
> use STRUCT_ASSIGN to copy fields from the old structure to the new
> one.
>
> IDL> str={a: 3l, b: 'v'}
> IDL> str_arr=REPLICATE(str,10)
>
> IDL> str1={a: 3l, b: 'w',c:0l}
> IDL> str1_arr= REplicate(str,10)
>
> IDL> struct_assign,temporary(str),str1
>
> where I changed the initialization values so one can verify that the
> "relaxed structure assignment" is working.
The only other way I see is to use a pointer array instead. Then you
can replace elements by whatever you want. But it is more likely to be
a worse solution, since it will not be possible to use fields as
arrays.
This reminds me of what I currently find most needed in create_struct:
an option to give it an array of field names, and an array of pointers
to the field contents. That way it would not be necessary to loop over
the fields, calling create_struct to add one field at a time, defining
a bunch of temporary structures that will never be used again. But
presumably this will not be necessary in IDL 8, since it will finally
have dictionaries.
|
|
|
Re: How to add a new tag to N structures [message #70014 is a reply to message #70013] |
Wed, 03 March 2010 10:07  |
wlandsman
Messages: 743 Registered: June 2000
|
Senior Member |
|
|
On Mar 3, 11:46 am, nata <bernat.puigdomen...@gmail.com> wrote:
> For some reasons I can define the C tag before so I have to add to
> each struct later. There is a way to do that without creating the new
> struct array and copying each field separately ?
Well, I don't know how to avoid creating a new structure but you can
use STRUCT_ASSIGN to copy fields from the old structure to the new
one.
IDL> str={a: 3l, b: 'v'}
IDL> str_arr=REPLICATE(str,10)
IDL> str1={a: 3l, b: 'w',c:0l}
IDL> str1_arr= REplicate(str,10)
IDL> struct_assign,temporary(str),str1
where I changed the initialization values so one can verify that the
"relaxed structure assignment" is working.
--Wayne
|
|
|