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

Home » Public Forums » archive » Re: work with structures
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: work with structures [message #73606] Wed, 17 November 2010 08:13
Jean[2] is currently offline  Jean[2]
Messages: 41
Registered: October 2010
Member
On Nov 17, 11:11 am, Michael Galloy <mgal...@gmail.com> wrote:
> On 11/17/10 9:00 AM, Jean wrote:
>
>
>
>> I have a program that takes a structure as one of its argument. I want
>> this program to parse and display its contains.
>
>> The structue may looks like this:
>
>> structure = { var1: {label:'label of var1', value:'value of var1'},$
>>                      var2: {label:'label of var2', value:'value of
>> var2'},$
>>                      ... }
>
>> I'm not supposed to know in advance the name of var1. Using tag_names,
>> I was able to retrieve those names, but know I need to get the label
>> and value of each of them and this is where I'm stuck.
>
>> of course doing something like
>
>> list_var = tag_names(structure)
>> for i=0,n_tags(structure)-1 do begin
>>     print, structure.list_var[i].label          !!! not working
>> endfor
>
>> did not work !
>
>> Any idea how I can do that ?
>
>> Jean
>
> Try:
>
> list_var = tag_names(structure)
> for i = 0L, n_tags(structure) - 1L do begin
>    print, list_var[i], structure.(i).label, structure.(i).value
> endfor
>
> Mike
> --www.michaelgalloy.com
> Research Mathematician
> Tech-X Corporation

That's exactly what I was looking for. Thanks guys.

Jean
Re: work with structures [message #73607 is a reply to message #73606] Wed, 17 November 2010 08:11 Go to previous message
Michael Galloy is currently offline  Michael Galloy
Messages: 1114
Registered: April 2006
Senior Member
On 11/17/10 9:00 AM, Jean wrote:
> I have a program that takes a structure as one of its argument. I want
> this program to parse and display its contains.
>
> The structue may looks like this:
>
> structure = { var1: {label:'label of var1', value:'value of var1'},$
> var2: {label:'label of var2', value:'value of
> var2'},$
> ... }
>
> I'm not supposed to know in advance the name of var1. Using tag_names,
> I was able to retrieve those names, but know I need to get the label
> and value of each of them and this is where I'm stuck.
>
> of course doing something like
>
> list_var = tag_names(structure)
> for i=0,n_tags(structure)-1 do begin
> print, structure.list_var[i].label !!! not working
> endfor
>
> did not work !
>
> Any idea how I can do that ?
>
> Jean

Try:

list_var = tag_names(structure)
for i = 0L, n_tags(structure) - 1L do begin
print, list_var[i], structure.(i).label, structure.(i).value
endfor

Mike
--
www.michaelgalloy.com
Research Mathematician
Tech-X Corporation
Re: work with structures [message #73608 is a reply to message #73607] Wed, 17 November 2010 08:09 Go to previous message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
Jean wrote:
> I have a program that takes a structure as one of its argument. I want
> this program to parse and display its contains.
>
> The structue may looks like this:
>
> structure = { var1: {label:'label of var1', value:'value of var1'},$
> var2: {label:'label of var2', value:'value of
> var2'},$
> ... }
>
> I'm not supposed to know in advance the name of var1. Using tag_names,
> I was able to retrieve those names, but know I need to get the label
> and value of each of them and this is where I'm stuck.
>
> of course doing something like
>
> list_var = tag_names(structure)
> for i=0,n_tags(structure)-1 do begin
> print, structure.list_var[i].label !!! not working

what about:
print, (structure.(i)).label

?

I may have overused the parentheses.

> endfor
>
> did not work !
>
> Any idea how I can do that ?
>
> Jean
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: PostScript Background Color Preference
Next Topic: NG Colorbar in IDL 8.0.1

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

Current Time: Wed Oct 08 11:33:14 PDT 2025

Total time taken to generate the page: 0.00527 seconds