[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: indexing over structure tags



Hmmm.... Well assuming that you want to iterate (for whatever reason)
over a set of names rather than a set of indices how about.

names = tagnames(data)
for i=0,n_tags(data)-1 do begin  ; Or any other kind of loop
    name = ... entered somehow by the user perhaps ...
    w=where(name eq names[i]);
    if (w(0) ne -1) then begin
        ind = w[0]
        data.(ind).values = ... 
....

It's easy enough to translate from the variable name to the variable
index -- and the index may itself be a variable.

	Tom

Randall Skelton wrote:
> 
> Thanks Tom... I did think of that.  However, in this particular case there
> is some merit in having the name of the structure be a useful and human
> readable tag.  Nobody would be happy trying to remember yet another
> arbitrary numbering scheme for molecules when they'd rather just type the
> name ;)  My suspicion is that there isn't an easy way to do what I want...
> 
> Randall
> 
> On Thu, 19 Apr 2001, tam wrote:
> 
> > Just use the numeric tag syntax for structures.
> >
> >    for i=0,n_tags(data)-1 do begin
> >         data.(i).values = .. some expresion ...
> >    endfor
> >
> > where the (i) indicates use the i'th element of the structure.
> > So you don't need to use the names at all.
> >
> >       Regards,
> >       Tom McGlynn
> >