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

Home » Public Forums » archive » Re: converting strings to structure tags
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: converting strings to structure tags [message #49156] Fri, 30 June 2006 06:41
Benjamin Hornberger is currently offline  Benjamin Hornberger
Messages: 258
Registered: March 2004
Senior Member
maye wrote:
> Benjamin Hornberger schrieb:
>
>
>> kl_tah@hotmail.com wrote:
>>
>>> Hi All,
>>>
>>> does anyone know how to convert a string to a structure tag? for e. g.
>>> I'd like to take a string as a function argument and use it to access a
>>> structure tag like so (hypothetically):
>>>
>>> function example,tag,i,j
>>>
>>> restore,'struct.dat
>>>
>>> tmp=mk_struct_tag(struct(i),tag) ; i.e. tmp=struct(i).tag
>>>
>>> a=tmp(j) ; i.e. a=struct(i).tag(j)
>>>
>>> return a
>>>
>>> end
>>>
>>> thanks,
>>> KL
>>>
>>
>> ;; get the tag names of the structure
>> names = tag_names(struct)
>>
>> ;; find the index of the tag you are looking for
>> i = where(strcmp(names, tag, /fold), count)
>>
>> ;; access the i-th tag in the structure
>> if count gt 0 then tag_value = struct.(i)
>>
>
> exactly what i needed today, thanks! This forum rocks! :)
> Why is this kind of access not documented? Well, at least it's not
> written in "Structure references", right? (IDL 6.3)
> Regards,
> Michael
>

Well, you can find it by going to "structures -> advanced" in the help
index. But I agree that often things are not so easy to find in the help
system. But that's what the newsgroup is for :-).

Cheers,
Benjamin
Re: converting strings to structure tags [message #49157 is a reply to message #49156] Fri, 30 June 2006 06:31 Go to previous message
maye is currently offline  maye
Messages: 29
Registered: June 2006
Junior Member
Benjamin Hornberger schrieb:

> kl_tah@hotmail.com wrote:
>> Hi All,
>>
>> does anyone know how to convert a string to a structure tag? for e. g.
>> I'd like to take a string as a function argument and use it to access a
>> structure tag like so (hypothetically):
>>
>> function example,tag,i,j
>>
>> restore,'struct.dat
>>
>> tmp=mk_struct_tag(struct(i),tag) ; i.e. tmp=struct(i).tag
>>
>> a=tmp(j) ; i.e. a=struct(i).tag(j)
>>
>> return a
>>
>> end
>>
>> thanks,
>> KL
>>
>
> ;; get the tag names of the structure
> names = tag_names(struct)
>
> ;; find the index of the tag you are looking for
> i = where(strcmp(names, tag, /fold), count)
>
> ;; access the i-th tag in the structure
> if count gt 0 then tag_value = struct.(i)
>
exactly what i needed today, thanks! This forum rocks! :)
Why is this kind of access not documented? Well, at least it's not
written in "Structure references", right? (IDL 6.3)
Regards,
Michael
Re: converting strings to structure tags [message #49172 is a reply to message #49157] Wed, 28 June 2006 12:35 Go to previous message
Benjamin Hornberger is currently offline  Benjamin Hornberger
Messages: 258
Registered: March 2004
Senior Member
kl_tah@hotmail.com wrote:
> Hi All,
>
> does anyone know how to convert a string to a structure tag? for e. g.
> I'd like to take a string as a function argument and use it to access a
> structure tag like so (hypothetically):
>
> function example,tag,i,j
>
> restore,'struct.dat
>
> tmp=mk_struct_tag(struct(i),tag) ; i.e. tmp=struct(i).tag
>
> a=tmp(j) ; i.e. a=struct(i).tag(j)
>
> return a
>
> end
>
> thanks,
> KL
>

;; get the tag names of the structure
names = tag_names(struct)

;; find the index of the tag you are looking for
i = where(strcmp(names, tag, /fold), count)

;; access the i-th tag in the structure
if count gt 0 then tag_value = struct.(i)

Good luck,
Benjamin
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: sorting column arrays
Next Topic: IDL's THIN function, with /PRUNE option

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

Current Time: Wed Oct 08 18:00:36 PDT 2025

Total time taken to generate the page: 0.00688 seconds