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

Home » Public Forums » archive » Re: calling a structure tag as a variable?
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: calling a structure tag as a variable? [message #79438] Mon, 27 February 2012 11:28
desertdryad is currently offline  desertdryad
Messages: 39
Registered: August 2011
Member
Ah, yes. Thanks so much, guys! I went via Paul's method.




On Feb 27, 10:06 am, Paul van Delst <paul.vande...@noaa.gov> wrote:
> David Fanning wrote:
>> Paul van Delst writes:
>
>>> How about something like:
>
>>> PRO process_mystructure, $
>>>       mystructure, $  ; The structure
>>>       tag             ; The tag name on which to operate
>
>>>   tag_idx = WHERE(TAG_NAMES(mystructure) EQ tag, count)
>>>   IF ( count NE 1 ) THEN MESSAGE, 'Invalid input tag'
>
>>>   ; Pull out data to operate on
>>>   data = mystructure.(tag_idx[0])
>
>>>   ....operate on data...calling separate, generic procedure?
>
>>>   ; Stick it back in the structure
>>>   mystructure.(tag_idx[0]) = data
>
>>> END
>
>> I'd remember to make that tag UPPERCASE or you
>> are *never* going to find it! ;-)
>
> Good point.
>
>   tag_idx = WHERE(TAG_NAMES(mystructure) EQ STRUPCASE(tag), count)
Re: calling a structure tag as a variable? [message #79440 is a reply to message #79438] Mon, 27 February 2012 09:06 Go to previous message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
David Fanning wrote:
> Paul van Delst writes:
>
>> How about something like:
>>
>>
>> PRO process_mystructure, $
>> mystructure, $ ; The structure
>> tag ; The tag name on which to operate
>>
>> tag_idx = WHERE(TAG_NAMES(mystructure) EQ tag, count)
>> IF ( count NE 1 ) THEN MESSAGE, 'Invalid input tag'
>>
>> ; Pull out data to operate on
>> data = mystructure.(tag_idx[0])
>>
>> ....operate on data...calling separate, generic procedure?
>>
>> ; Stick it back in the structure
>> mystructure.(tag_idx[0]) = data
>>
>> END
>
> I'd remember to make that tag UPPERCASE or you
> are *never* going to find it! ;-)

Good point.

tag_idx = WHERE(TAG_NAMES(mystructure) EQ STRUPCASE(tag), count)
Re: calling a structure tag as a variable? [message #79441 is a reply to message #79440] Mon, 27 February 2012 08:55 Go to previous message
Lajos Foldy is currently offline  Lajos Foldy
Messages: 176
Registered: December 2011
Senior Member
On Feb 27, 5:36 pm, desertdryad <dry...@gmail.com> wrote:
> Hi folks -
>
> I have a set of structure variables I use in a suite of programs.  I
> need to run the same procedure on several different fields within that
> structure; where the only difference in how th eprocedure is used is
> the particualr field it operates on.  But I don't want to do them 'all
> at once' either.  I would like to be able to call the procedure in
> question by somehow making the tag name to operate on in the procedure
> a variable.  But I don't think there is a way to do that in IDL?
>
> (did I explain my question understandably?)

You can access structure fields by tag numbers, too:

IDL> s={s, i:0, l:0l, f:0.0}
IDL> tagnum=1
IDL> help, s.(tagnum)
<Expression> LONG = 0

regards,
Lajos
Re: calling a structure tag as a variable? [message #79442 is a reply to message #79441] Mon, 27 February 2012 08:58 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Paul van Delst writes:

> How about something like:
>
>
> PRO process_mystructure, $
> mystructure, $ ; The structure
> tag ; The tag name on which to operate
>
> tag_idx = WHERE(TAG_NAMES(mystructure) EQ tag, count)
> IF ( count NE 1 ) THEN MESSAGE, 'Invalid input tag'
>
> ; Pull out data to operate on
> data = mystructure.(tag_idx[0])
>
> ....operate on data...calling separate, generic procedure?
>
> ; Stick it back in the structure
> mystructure.(tag_idx[0]) = data
>
> END

I'd remember to make that tag UPPERCASE or you
are *never* going to find it! ;-)

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: calling a structure tag as a variable? [message #79443 is a reply to message #79441] Mon, 27 February 2012 08:52 Go to previous message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
desertdryad wrote:
> Hi folks -
>
> I have a set of structure variables I use in a suite of programs. I
> need to run the same procedure on several different fields within that
> structure; where the only difference in how th eprocedure is used is
> the particualr field it operates on. But I don't want to do them 'all
> at once' either. I would like to be able to call the procedure in
> question by somehow making the tag name to operate on in the procedure
> a variable. But I don't think there is a way to do that in IDL?
>
> (did I explain my question understandably?)

How about something like:


PRO process_mystructure, $
mystructure, $ ; The structure
tag ; The tag name on which to operate

tag_idx = WHERE(TAG_NAMES(mystructure) EQ tag, count)
IF ( count NE 1 ) THEN MESSAGE, 'Invalid input tag'

; Pull out data to operate on
data = mystructure.(tag_idx[0])

....operate on data...calling separate, generic procedure?

; Stick it back in the structure
mystructure.(tag_idx[0]) = data

END



??
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: calling a structure tag as a variable?
Next Topic: SHIFT Function

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

Current Time: Wed Oct 08 18:58:43 PDT 2025

Total time taken to generate the page: 0.00634 seconds