|
Re: Renaming a variable in IDL? [message #55504 is a reply to message #55503] |
Fri, 24 August 2007 01:38  |
Foldy Lajos
Messages: 268 Registered: October 2001
|
Senior Member |
|
|
On Fri, 24 Aug 2007, peterberg79@gmail.com wrote:
> Hi,
> I am writing a procedure for autmatically saving some variables from
> more advanced programs for easy access later on. Something along the
> lines of:
>
> PRO, SAVPRO, XVAR, Fname
> save, XVAR, filename=Fname
> end
>
> So if I want to save the file 'YVAR' to filename 'YVAR.sav' I would
> call:
> SAVPRO, YVAR, 'YVAR.sav'
> The problem is that in the save file the variable would be called XVAR
> instead of YVAR, which is a problem for me.
> I realized that I can retrieve the original varaible name as a string
> and include it to the SAVPRO call. But then I got lost on how to
> rename a variable to a string name. I was thinking there might be
> soemthing along the lines of using echo in unix (echo
> $STRYVAR'=XVAR'), but I have found no such function.
>
> My question is: Is it possible to rename a variable in IDL
> automatically? Or is there a better way to do all this?
>
>
1. execute
2. (scope_varfetch('xvar', /enter))=temporary(yvar) moves the content of
yvar to xvar (yvar will be undefined).
regards,
lajos
|
|
|
Re: Renaming a variable in IDL? [message #55505 is a reply to message #55504] |
Fri, 24 August 2007 01:36  |
Maarten[1]
Messages: 176 Registered: November 2005
|
Senior Member |
|
|
On Aug 24, 7:28 am, peterber...@gmail.com wrote:
> Hi,
> I am writing a procedure for autmatically saving some variables from
> more advanced programs for easy access later on. Something along the
> lines of:
>
> PRO, SAVPRO, XVAR, Fname
> save, XVAR, filename=Fname
> end
>
> So if I want to save the file 'YVAR' to filename 'YVAR.sav' I would
> call:
> SAVPRO, YVAR, 'YVAR.sav'
> The problem is that in the save file the variable would be called XVAR
> instead of YVAR, which is a problem for me.
> I realized that I can retrieve the original varaible name as a string
> and include it to the SAVPRO call. But then I got lost on how to
> rename a variable to a string name. I was thinking there might be
> soemthing along the lines of using echo in unix (echo
> $STRYVAR'=XVAR'), but I have found no such function.
>
> My question is: Is it possible to rename a variable in IDL
> automatically? Or is there a better way to do all this?
; restore into XVAR, varname is the string that contains the name to
be used
dum = EXECUTE(varname + " = XVAR")
undefine, XVAR
But there probably is a much better way (probably by not using save
files at all).
Maarten
|
|
|