structure access using strings for tag-names [message #43427] |
Mon, 11 April 2005 05:08  |
Thomas Pfaff
Messages: 15 Registered: April 2005
|
Junior Member |
|
|
Hello everyone,
I would like to ask your opinion about the following.
Using the function CREATE_STRUCT it is possible to create a struct with
tag names defined by strings. This way it is possible to create structs
without knowing their names at compile time.
However even if I don't have to know the tag names when creating a
struct, it seems that I still have to know them, when I want to acccess
the data within that struct, because I couldn't find any procedure or
function for this purpose and struct.'tag_name' quite naturally gives a
syntax error.
Any ideas why this isn't implemented, or why it isn't necessary to have
it (would be nice to set up simple associative containers, wouldn't it)?
Best regards,
Thomas
|
|
|
Re: structure access using strings for tag-names [message #43428 is a reply to message #43427] |
Mon, 11 April 2005 05:31   |
Paolo Grigis
Messages: 171 Registered: December 2003
|
Senior Member |
|
|
Try this out:
;get list of tag names
tagnamelist=tag_names(!P)
;find which tag has the name "MULTI"
tagindex=where(tagnamelist EQ 'MULTI')
;access the structure
print,!p.(tagindex)
You can use struct.(0), struct.(1) etc. to access the values
in the first, second,... tag.
--Paolo
Thomas Pfaff wrote:
> Hello everyone,
>
> I would like to ask your opinion about the following.
>
> Using the function CREATE_STRUCT it is possible to create a struct with
> tag names defined by strings. This way it is possible to create structs
> without knowing their names at compile time.
>
> However even if I don't have to know the tag names when creating a
> struct, it seems that I still have to know them, when I want to acccess
> the data within that struct, because I couldn't find any procedure or
> function for this purpose and struct.'tag_name' quite naturally gives a
> syntax error.
>
> Any ideas why this isn't implemented, or why it isn't necessary to have
> it (would be nice to set up simple associative containers, wouldn't it)?
>
> Best regards,
>
>
> Thomas
|
|
|
|
Re: structure access using strings for tag-names [message #43478 is a reply to message #43427] |
Wed, 13 April 2005 02:29  |
R.Bauer
Messages: 1424 Registered: November 1998
|
Senior Member |
|
|
Thomas Pfaff wrote:
> Hello everyone,
>
> I would like to ask your opinion about the following.
>
> Using the function CREATE_STRUCT it is possible to create a struct with
> tag names defined by strings. This way it is possible to create structs
> without knowing their names at compile time.
>
> However even if I don't have to know the tag names when creating a
> struct, it seems that I still have to know them, when I want to acccess
> the data within that struct, because I couldn't find any procedure or
> function for this purpose and struct.'tag_name' quite naturally gives a
> syntax error.
>
> Any ideas why this isn't implemented, or why it isn't necessary to have
> it (would be nice to set up simple associative containers, wouldn't it)?
>
> Best regards,
>
>
> Thomas
You could use the routine tag_position from our library.
test=create_struct('A',1,'B',2)
print, test.(tag_position(test,'A'))
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_source/idl _html/dbase/tag_position_dbase.pro.html
cheers
Reimar
--
Reimar Bauer
Institut fuer Stratosphaerische Chemie (ICG-I)
Forschungszentrum Juelich
email: R.Bauer@fz-juelich.de
------------------------------------------------------------ -------
a IDL library at ForschungsZentrum Juelich
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_lib_intro. html
============================================================ =======
|
|
|