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 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: converting a string to an IDL command [message #62372] Mon, 08 September 2008 13:46
astroboy2k is currently offline  astroboy2k
Messages: 34
Registered: July 2007
Member
On Sep 8, 3:57 pm, David Fanning <n...@dfanning.com> wrote:
> Mark writes:
>> Everything I know about IDL I learned from you!
>
> Oh, oh. Guess I'll retire again. I've done enough damage. ;-)
>
> Cheers,
>
> David



Seriously, David, I'm not a bad programmer, thanks in *large* part to
you. This stuff is just to help me in telling where the numbers went
bad in code that other people wrote, as Mike puts it, a glorified help
command.

The very very best of luck in the future. The group here won't be the
same without your unselfish help and humor.

Mark
Re: converting a string to an IDL command [message #62374 is a reply to message #62372] Mon, 08 September 2008 12:57 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Mark writes:

> Everything I know about IDL I learned from you!

Oh, oh. Guess I'll retire again. I've done enough damage. ;-)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: converting a string to an IDL command [message #62375 is a reply to message #62374] Mon, 08 September 2008 12:54 Go to previous message
Michael Galloy is currently offline  Michael Galloy
Messages: 1114
Registered: April 2006
Senior Member
On Sep 8, 1:43 pm, Mark <astrobo...@gmail.com> wrote:
> I do believe scope_var is just what I'm looking for. I already have a
> routine which returns line numbers within various layers of code, so I
> suppose I could come up with a function that would tell me the line
> number within each layer of code, the variable name at that level, and
> then the min and max (or whatever). Perverse as that is, that would be
> a big help in alot of the work I'm doing these days....

I echo David sentiment that you shouldn't go too far down this road.
The routines I sent were meant as sort of a specialized HELP
replacement for interactive use. I would advise against using them in
code that you keep around.

Mike
--
www.michaelgalloy.com
Tech-X Corporation
Software Developer II
Re: converting a string to an IDL command [message #62376 is a reply to message #62375] Mon, 08 September 2008 12:53 Go to previous message
astroboy2k is currently offline  astroboy2k
Messages: 34
Registered: July 2007
Member
On Sep 8, 3:46 pm, David Fanning <n...@dfanning.com> wrote:
> Mark writes:
>> I do believe scope_var is just what I'm looking for. I already have a
>> routine which returns line numbers within various layers of code, so I
>> suppose I could come up with a function that would tell me the line
>> number within each layer of code, the variable name at that level, and
>> then the min and max (or whatever). Perverse as that is, that would be
>> a big help in alot of the work I'm doing these days....
>
> Remind me not to get involved in any projects using IDL
> code you have written. I have enough of my own problems. :-)
>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")

But David,

Everything I know about IDL I learned from you!

Seriously.

Mark ;)
Re: converting a string to an IDL command [message #62377 is a reply to message #62376] Mon, 08 September 2008 12:26 Go to previous message
Jean H. is currently offline  Jean H.
Messages: 472
Registered: July 2006
Senior Member
> 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....
>
> Thanks in advance,
>
> Mark

yes, see "SCOPE_VARNAME" in the help

Jean
Re: converting a string to an IDL command [message #62378 is a reply to message #62377] Mon, 08 September 2008 12:46 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Mark writes:

> I do believe scope_var is just what I'm looking for. I already have a
> routine which returns line numbers within various layers of code, so I
> suppose I could come up with a function that would tell me the line
> number within each layer of code, the variable name at that level, and
> then the min and max (or whatever). Perverse as that is, that would be
> a big help in alot of the work I'm doing these days....

Remind me not to get involved in any projects using IDL
code you have written. I have enough of my own problems. :-)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: converting a string to an IDL command [message #62379 is a reply to message #62377] Mon, 08 September 2008 12:43 Go to previous message
astroboy2k is currently offline  astroboy2k
Messages: 34
Registered: July 2007
Member
Thanks, Mike and David.

I do believe scope_var is just what I'm looking for. I already have a
routine which returns line numbers within various layers of code, so I
suppose I could come up with a function that would tell me the line
number within each layer of code, the variable name at that level, and
then the min and max (or whatever). Perverse as that is, that would be
a big help in alot of the work I'm doing these days....

Mark
Re: converting a string to an IDL command [message #62380 is a reply to message #62377] Mon, 08 September 2008 12:29 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Mark writes:

> 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"
>
>
> 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....

Now you are going down a really slippery slope. Better be
careful!

Think about it. You are inside of SOME_FUNCTION and you need
to know something about a variable array named "happydays".
Where is this array? Not inside the function where you are
thinking about it, that's for sure. Could you find it anyway?

Maybe, if you knew where to look. But where would that be?
One level up? Unlikely. Because if it were there, the person
who called you could have just as easily called the MINMAX command on
the array itself. Why didn't he? Maybe he didn't know where it was
either. Are you going to look for the data array everywhere? Where
*is* everywhere, anyway?

Anyway, if you think this is worth pursuing (I don't), then have
a look at the SCOPE_VAR** routines. They are what you want to use to
nose around in places you have no business being.

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
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 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
Re: converting a string to an IDL command [message #62383 is a reply to message #62381] Mon, 08 September 2008 12:13 Go to previous message
astroboy2k is currently offline  astroboy2k
Messages: 34
Registered: July 2007
Member
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"


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....

Thanks in advance,

Mark
Re: converting a string to an IDL command [message #62384 is a reply to message #62383] Mon, 08 September 2008 11:57 Go to previous message
astroboy2k is currently offline  astroboy2k
Messages: 34
Registered: July 2007
Member
On Sep 8, 1:30 pm, Bob Crawford <Snowma...@gmail.com> wrote:
> On Sep 8, 12:46 pm, Mark <astrobo...@gmail.com> wrote:
>
>
>
>> Hello!
>
>> I find myself constantly doing things like:
>
>> print,'   min(x), max(x)     ',min(x),max(x)
>
>> Is is possible to do something along the lines of:
>
>> char=' min(x),max(x) '
>> some_function,char
>
>> where some_function would change char into one line of IDL code? That
>> is, if x=findgen(10)
>> sub_function would print something like:
>
>>  min(x),max(x) ,0.000 ,9.000
>
>> Seems like this wouldn't be so hard. I'm interested in something that
>> would work with Unix.
>> Thanks,
>
>> Mark
>
> result=execute('print,"'+char+'",'+char)

Thanks Bob,

This is just what I need. Unfortunately, I have never worked anywhere
where anyone knows more IDL than I do, and despite all the unselfish
help from this group and David's excellent book and website, alot of
times there are pretty basic things which simply flew under the radar
along the way... :(
Re: converting a string to an IDL command [message #62390 is a reply to message #62384] Mon, 08 September 2008 10:30 Go to previous message
Bob[3] is currently offline  Bob[3]
Messages: 60
Registered: December 2006
Member
On Sep 8, 12:46 pm, Mark <astrobo...@gmail.com> wrote:
> Hello!
>
> I find myself constantly doing things like:
>
> print,'   min(x), max(x)     ',min(x),max(x)
>
> Is is possible to do something along the lines of:
>
> char=' min(x),max(x) '
> some_function,char
>
> where some_function would change char into one line of IDL code? That
> is, if x=findgen(10)
> sub_function would print something like:
>
>  min(x),max(x) ,0.000 ,9.000
>
> Seems like this wouldn't be so hard. I'm interested in something that
> would work with Unix.
> Thanks,
>
> Mark

result=execute('print,"'+char+'",'+char)
Re: converting a string to an IDL command [message #62391 is a reply to message #62390] Mon, 08 September 2008 09:56 Go to previous message
Jean H. is currently offline  Jean H.
Messages: 472
Registered: July 2006
Senior Member
Mark wrote:
> Hello!
>
> I find myself constantly doing things like:
>
> print,' min(x), max(x) ',min(x),max(x)
>
> Is is possible to do something along the lines of:
>
> char=' min(x),max(x) '
> some_function,char
>
> where some_function would change char into one line of IDL code? That
> is, if x=findgen(10)
> sub_function would print something like:
>
> min(x),max(x) ,0.000 ,9.000
>
> Seems like this wouldn't be so hard. I'm interested in something that
> would work with Unix.
> Thanks,
>
> Mark

Execute comes to mind... but you would have to pass both the command
string and the x array.
Otherwise, do a printMinMax,x procedure that prints and do exactly what
you want!

Jean
Re: converting a string to an IDL command [message #62392 is a reply to message #62391] Mon, 08 September 2008 10:16 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
pgrigis@gmail.com writes:

> lots of posts today, did you give up your new job already?
> Not that anybody here would complain about that ... ;-)

No, no. Car troubles. Stuck at home where old habits
die hard. :-)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: converting a string to an IDL command [message #62393 is a reply to message #62391] Mon, 08 September 2008 10:14 Go to previous message
pgrigis is currently offline  pgrigis
Messages: 436
Registered: September 2007
Senior Member
Hi David,

lots of posts today, did you give up your new job already?
Not that anybody here would complain about that ... ;-)

Ciao,
Paolo

David Fanning wrote:
> Mark writes:
>
>> I find myself constantly doing things like:
>>
>> print,' min(x), max(x) ',min(x),max(x)
>>
>> Is is possible to do something along the lines of:
>>
>> char=' min(x),max(x) '
>> some_function,char
>>
>> where some_function would change char into one line of IDL code? That
>> is, if x=findgen(10)
>> sub_function would print something like:
>>
>> min(x),max(x) ,0.000 ,9.000
>>
>> Seems like this wouldn't be so hard. I'm interested in something that
>> would work with Unix.
>
> I think it might take all of 10 seconds to write your
> own MINMAX routine in IDL that did exactly what you have
> in mind. Then, you could do it all in *one* line! :-)
>
> Cheers,
>
> David
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming: http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: converting a string to an IDL command [message #62396 is a reply to message #62391] Mon, 08 September 2008 09:51 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Mark writes:

> I find myself constantly doing things like:
>
> print,' min(x), max(x) ',min(x),max(x)
>
> Is is possible to do something along the lines of:
>
> char=' min(x),max(x) '
> some_function,char
>
> where some_function would change char into one line of IDL code? That
> is, if x=findgen(10)
> sub_function would print something like:
>
> min(x),max(x) ,0.000 ,9.000
>
> Seems like this wouldn't be so hard. I'm interested in something that
> would work with Unix.

I think it might take all of 10 seconds to write your
own MINMAX routine in IDL that did exactly what you have
in mind. Then, you could do it all in *one* line! :-)

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: map plotting
Next Topic: Re: inverse the axis

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

Current Time: Wed Oct 08 13:43:22 PDT 2025

Total time taken to generate the page: 0.00902 seconds