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

Home » Public Forums » archive » Re: converting a string to an IDL command
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: converting a string to an IDL command [message #62381 is a reply to message #62377] Mon, 08 September 2008 12:25 Go to previous messageGo to previous message
Michael Galloy is currently offline  Michael Galloy
Messages: 1114
Registered: April 2006
Senior Member
On Sep 8, 1:13 pm, Mark <astrobo...@gmail.com> wrote:
> Actually, I have a related question, for which if it's obvious I
> apologize in advance.
>
> Not sure how to put this precisely, but....
>
> Let's say I have an array called "happydays".
>
> I'd like to make a function that would take the string 'happydays',
> and say, return the min and max of the array with that name:
>
> out=some_function('happydays')
> where out is the string:
>
> 'The max and min of HAPPYDAYS is 0 and 15"

How about:

pro mg_printvar, name
compile_opt strictarr

var = scope_varfetch(name, level=-1L)
varMin = min(var, max=varMax)
print, 'The range of ' + strupcase(name) + ' is ' + strtrim(varMin,
2) + ' to ' + strtrim(varMax, 2)
end

This works like:

IDL> a = randomu(seed, 10)
IDL> mg_printvar, 'a'
The range of A is 0.0932334 to 0.960451

> Just as well, would be something like:
>
> out=some_function(happydays)
> and out is the same string as above.
>
> In other words, I guess what I'm asking is, is  there a way to find
> the original name of a variable that was passed to a sub-program or a
> function....

This one uses SCOPE_VARNAME to do the dirty work:

pro mg_printvar2, var
compile_opt strictarr

name = scope_varname(var, level=-1L)
varMin = min(var, max=varMax)
print, 'The range of ' + strupcase(name) + ' is ' + strtrim(varMin,
2) + ' to ' + strtrim(varMax, 2)
end

For example:

IDL> mg_printvar2, a
The range of A is 0.0932334 to 0.960451

Mike
--
www.michaelgalloy.com
Tech-X Corporation
Software Developer II
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: map plotting
Next Topic: Re: inverse the axis

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

Current Time: Fri Oct 10 09:19:54 PDT 2025

Total time taken to generate the page: 0.32093 seconds