procedure with arbitrary parameter [message #76259] |
Mon, 30 May 2011 09:53  |
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  |
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  |
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  |
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  |
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
|
|
|