In addition to distributing IDL code in binary format, you can also create SAVE files that contain variable data. 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.

Saving Data Variables in a SAVE File


Data can be conveniently stored in SAVE files, relieving you 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 Red, Green, and Blue hold the color table vectors, and the variable Image holds the image variable, the IDL statement,

SAVE, FILENAME = 'image.sav', Red, Green, Blue, Image

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. See Save Image Variable Data for an additional example.

Saving Heap Variables in a SAVE File


The SAVE procedure works for heap variables just as it works for all other supported types. By default, when IDL saves a pointer or object reference in a SAVE file, it recursively saves the heap variables that are referenced by that pointer or object reference.

In some cases, you may want to save the pointer or object reference, but not the heap variable that are referenced by that pointer or object reference. You can specify that the heap variable associated with a pointer or object reference not be saved using the HEAP_NOSAVE procedure or the HEAP_SAVE function. See the documentation for HEAP_SAVE for additional details.

Saving System Variables in a SAVE 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 system variables and local variables from the current 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.