Re: work with structures [message #73606] |
Wed, 17 November 2010 08:13 |
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  |
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  |
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
|
|
|