Re: Dynamically naming structures in IDL [message #91575 is a reply to message #91554] |
Thu, 30 July 2015 08:37  |
Scheherazade
Messages: 4 Registered: July 2015
|
Junior Member |
|
|
On Thursday, July 30, 2015 at 10:50:02 AM UTC-4, wlandsman wrote:
> What appears inside EXECUTE should be exactly what one would print on the command line. It is useful to display the string prior to executing it to see any syntax errors.
>
> IDL> c = !p ;Define a structure
> IDL> newname = 'c'
> IDL> str = 'save,' + newname + ',file="test.sav"'
> IDL> print,str
> save,c,file="test.sav"
> IDL> status = execute(str)
> IDL> print,status
> 1
> IDL> restore,"test.sav",/ver
> % RESTORE: Portable (XDR) SAVE/RESTORE file.
> % RESTORE: Save file written by wlandsma@gs66-mpb, Thu Jul 30 10:39:18 2015.
> % RESTORE: IDL version 8.4 (darwin, x86_64).
> % RESTORE: Restored variable: C.
>
> Be sure to include the comma after 'Save'
>
> On Thursday, July 30, 2015 at 10:05:00 AM UTC-4, Scheherazade wrote:
> (since it saves newname, not the new structure).
>>
>> IDL responded with a "syntax error" on the save. I've been removing/adding quotation marks within that line to fix it, but it gives the same error message each time. I also tried saving the two commands as strings, then executing them (which is how execute is used in the Exelis Vis help page http://www.exelisvis.com/docs/EXECUTE.html ):
>>
>> status = execute( newname + '= TEMPORARY(new_variables)' )
>> status1=('save' + "newname + file='/Users/keleuterio/Documents/omni_general_' + year + '.sav'")
>> status2=execute("status1")
>>
>> But IDL responds with "% Attempt to call undefined procedure/function: 'STATUS1'". I think that it's mostly a matter of putting the quotation marks in the right place, but I don't fully understand how the Execute command recognizes the difference between a procedure (such as save) and a string (such as the filepath).
Thank you both for your explanations, as I successfully saved the structure. It helped to test the functionality of the commands at the command line, especially now that I have a better understanding of Execute.
Additionally, do you know why there is a ', before the filepath, such as below?
IDL> str = 'save,' + newname + ',file="test.sav"'
I also realized that I could also use the variables keyword, which would save the new structure along with all other variables:
newname='new_structure_'+year
status = execute(newname + '= TEMPORARY(new_variables)')
status1= execute("save, /variables, filename='/Users/keleuterio/Documents/omni_general_' + year + '.sav'")
However, this would save more variables than needed, and I prefer the alternative.
|
|
|