Home | Categories | Alphabetical | Classes | All Contents | [ < ] | [ > ]

Saving Variables from an IDL Session


The SAVE and RESTORE procedures and the IDL_Savefile object combine to provide the ability to save the state of variables and system variables to restore them at a later time. Variables that are used from session to session can be saved as and recovered from a SAVE file. A startup file can be set up to execute the RESTORE command every time IDL is started. (See Startup Files for information on specifying a startup files.) For an overview of how to restore and run SAVE files, see Executing Programs Stored in a SAVE File.

Tip
You can also distribute IDL code in binary format, sharing programs and applications with other IDL users. For an example of creating SAVE files of compiled programs, see Saving Compiled IDL Programs and Data for more information.

The state of variables in an IDL session can be saved quickly and easily, and can be restored to the same point. This feature allows you to stop work, and later resume at a convenient time. Variables that you may wish to create a SAVE file of include frequently used data files or system variable definitions.

Data can be conveniently stored in SAVE files, relieving the user of the need to remember the dimensions of arrays and other details. It is very convenient to store images this way. For instance, if the three variables R, G, and B hold the color table vectors, and the variable I holds the image variable, the IDL statement,

SAVE, FILENAME = 'image.sav', R, G, B, I 

will save everything required to display the image properly in a file named image.sav. At a later date, the simple command,

RESTORE, 'image.sav'  

will recover the four variables from the file.

System variables can also be saved and later applied to another session of IDL. For instance, you may choose to customize !PATH, the system variable defining the directories IDL will search for libraries, batch/include files, and executive commands or !P, the system variable that controls the definition of graphic elements associated with plot procedures. You can save these definitions in a SAVE file and later automatically restore or selectively restore the variables to apply the settings to other IDL sessions.

To save and restore the state of all current and system variables within an IDL session, you could use the following statement:

SAVE, /ALL, FILENAME = 'myIDLsession.sav' 

The ALL keyword saves all common blocks, system variables and local variables from the current IDL session. See Constants and Variables for information on these elements of an IDL session.

Note
Routines and variables cannot be saved in the same file. Setting the ALL keyword does not save routines.

To restore the session information, enter:

RESTORE, 'myIDLsession.sav' 

Note
If the file is not located in your current working directory, you will need to define the path to the file.

Long iterative jobs can save their partial results in a SAVE format to guard against losing data if some unexpected event such as a machine crash should occur.

Note
A SAVE file containing data will always be restorable. However, SAVE files created prior to IDL version 5.5 that contain IDL procedures, functions, and programs are not always portable between different versions of IDL. If you created your SAVE file with a version of IDL earlier than 5.5, you will need to recompile your original .pro files and re-create the SAVE file using the current version of IDL.


Home | Categories | Alphabetical | Classes | All Contents | [ < ] | [ > ]