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

Home » Public Forums » archive » Re: indexing over structure tags
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: indexing over structure tags [message #24809 is a reply to message #24807] Thu, 19 April 2001 10:36 Go to previous messageGo to previous message
Vapuser is currently offline  Vapuser
Messages: 63
Registered: November 1998
Member
Randall Skelton <rhskelto@atm.ox.ac.uk> writes:

> Hello,
>
> Imagine someone has a structure of structures...
>
> ; define the basic structure for each
> sm_struc = {basic_struct, comment: ' ', values: fltarr(nlev)}
>
> ; define the large structure
> data = {big_struct, so4: sm_struc, co2: sm_struc, hcl: sm_struc}
>
> The IDL manual describes how to make an array of the tags in a structure
> using:
>
> ; get the names of the tags
> names = tag_names(data)
>
> so that names = [so4, co2, hcl].
>
> That is all fine. But is it possible to index over the tag names with a
> for-loop?
>
> i.e. for i=0, n_elements(names)-1 do data.names[i].values = i
> ^^^^^^^^^^^^^^^^^^^^

>
> where IDL determines what the appropriate label 'data.name[i].values' is.
>
> Thanks,
> Randall
>

data.(i) to iterate over that tags of data, and
data.(i).(j) to iterate over the tags of data.(i)

If each tag is an array, rather than a scalar structure instance, you
might (probably?) have to pull it out, like this

IDL> junk={foo, a:0, b:0l, c:0.0}
IDL> bar={bar, a:replicate({foo},3),b:replicate({foo},4)}
IDL> help,bar,/struct
** Structure BAR, 2 tags, length=84:
A STRUCT -> FOO Array[3]
B STRUCT -> FOO Array[4]


IDL> .run
- FOR i=0,1 DO BEGIN
- FOR j=0,2 DO BEGIN
- tmp=bar.(i).(j) ;<--- I couldn't find a way to do this inline,
; ; but there might be one that I'm missing
- FOR k=0,n_elements(tmp)-1 DO tmp[k]=(2^(i+1))*(3^(j+1))+k
- bar.(i).(j)=tmp
- endfor
- endfor
- end
% Compiled module: $MAIN$.
IDL> print,bar
{
a = { 6 18 54.0000}
{ 7 19 55.0000}
{ 8 20 56.0000}

b = { 12 36 108.000}
{ 13 37 109.000}
{ 14 38 110.000}
{ 15 39 111.000}

}


whd

--
William Daffer: 818-354-0161: William.Daffer@jpl.nasa.gov
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: fastest operations/fctns.
Next Topic: MBAR

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

Current Time: Wed Oct 08 18:41:16 PDT 2025

Total time taken to generate the page: 0.00450 seconds