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

Home » Public Forums » archive » procedure with arbitrary parameter
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
procedure with arbitrary parameter [message #76259] Mon, 30 May 2011 09:53 Go to next message
Evianis Cruz is currently offline  Evianis Cruz
Messages: 4
Registered: May 2011
Junior Member
So in my procedure call I have something like this

pro test, filename, var

restore, filename
plot, var

end

var will be the name of the variable I want to plot from restoring the
file. I'm thinking of giving var as a string in the procedure call. My
question is how would I do this and is it possible?
Re: procedure with arbitrary parameter [message #76404 is a reply to message #76259] Mon, 30 May 2011 13:03 Go to previous message
Michael Galloy is currently offline  Michael Galloy
Messages: 1114
Registered: April 2006
Senior Member
On 5/30/11 12:29 PM, Evianis Cruz wrote:
> On May 30, 1:13 pm, Michael Galloy<mgal...@gmail.com> wrote:
>> On 5/30/11 10:53 AM, Evianis Cruz wrote:
>>
>>> So in my procedure call I have something like this
>>
>>> pro test, filename, var
>>
>>> restore, filename
>>> plot, var
>>
>>> end
>>
>>> var will be the name of the variable I want to plot from restoring the
>>> file. I'm thinking of giving var as a string in the procedure call. My
>>> question is how would I do this and is it possible?
>>
>> Like this?
>>
>> function mg_getsavvar, filename, varname
>> compile_opt strictarr
>>
>> restore, filename=filename
>> result = execute('plot, ' + varname)
>> end
>>
>> Mike
>> --
>> Michael Galloywww.michaelgalloy.com
>> Modern IDL, A Guide to Learning IDL:http://modernidl.idldev.com
>> Research Mathematician
>> Tech-X Corporation
>
> Thank you!! :)

No problem, but use the solution from Lajos; using EXECUTE is bad
practice unless you have to (and I forgot about SCOPE_VARFECTCH).

Mike
--
Michael Galloy
www.michaelgalloy.com
Modern IDL, A Guide to Learning IDL: http://modernidl.idldev.com
Research Mathematician
Tech-X Corporation
Re: procedure with arbitrary parameter [message #76405 is a reply to message #76259] Mon, 30 May 2011 11:29 Go to previous message
Evianis Cruz is currently offline  Evianis Cruz
Messages: 4
Registered: May 2011
Junior Member
On May 30, 1:13 pm, Michael Galloy <mgal...@gmail.com> wrote:
> On 5/30/11 10:53 AM, Evianis Cruz wrote:
>
>> So in my procedure call I have something like this
>
>> pro test, filename, var
>
>> restore, filename
>> plot, var
>
>> end
>
>> var will be the name of the variable I want to plot from restoring the
>> file. I'm thinking of giving var as a string in the procedure call. My
>> question is how would I do this and is it possible?
>
> Like this?
>
> function mg_getsavvar, filename, varname
>    compile_opt strictarr
>
>    restore, filename=filename
>    result = execute('plot, ' + varname)
> end
>
> Mike
> --
> Michael Galloywww.michaelgalloy.com
> Modern IDL, A Guide to Learning IDL:http://modernidl.idldev.com
> Research Mathematician
> Tech-X Corporation

Thank you!! :)
Re: procedure with arbitrary parameter [message #76407 is a reply to message #76259] Mon, 30 May 2011 10:13 Go to previous message
Michael Galloy is currently offline  Michael Galloy
Messages: 1114
Registered: April 2006
Senior Member
On 5/30/11 10:53 AM, Evianis Cruz wrote:
> So in my procedure call I have something like this
>
> pro test, filename, var
>
> restore, filename
> plot, var
>
> end
>
> var will be the name of the variable I want to plot from restoring the
> file. I'm thinking of giving var as a string in the procedure call. My
> question is how would I do this and is it possible?

Like this?

function mg_getsavvar, filename, varname
compile_opt strictarr

restore, filename=filename
result = execute('plot, ' + varname)
end

Mike
--
Michael Galloy
www.michaelgalloy.com
Modern IDL, A Guide to Learning IDL: http://modernidl.idldev.com
Research Mathematician
Tech-X Corporation
Re: procedure with arbitrary parameter [message #76408 is a reply to message #76259] Mon, 30 May 2011 10:12 Go to previous message
Foldy Lajos is currently offline  Foldy Lajos
Messages: 268
Registered: October 2001
Senior Member
On Mon, 30 May 2011, Evianis Cruz wrote:

> So in my procedure call I have something like this
>
> pro test, filename, var
>
> restore, filename
> plot, var
>
> end
>
> var will be the name of the variable I want to plot from restoring the
> file. I'm thinking of giving var as a string in the procedure call. My
> question is how would I do this and is it possible?
>

Look up SCOPE_VARFETCH in IDL help:

plot, scope_varfetch('my_var_name')

regards,
Lajos
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Automatic Binsize Calculations
Next Topic: How to plot multiple cgContour plots using the same colour levels (but containing differing data)

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

Current Time: Wed Oct 08 11:41:22 PDT 2025

Total time taken to generate the page: 0.00757 seconds