The SAVE procedure can be used to quickly save IDL routines and data variables in a binary format that can be shared with other IDL users, or with others who have installed the IDL Virtual Machine.
| Warning |
| Note |
.sav for SAVE files. Using the .sav extension has two benefits: it makes it clear to another IDL user that the file contains IDL routines or data, and it allows IDL automatically locate and compile the routines in the file as described in Automatic Compilation.
If your program or utility consists of multiple routines, each procedure or function used by your program must be resolved and contained in a SAVE file. You have the following options:
.pro files to an IDL Project and build the project, which creates a single .sav file. See Creating IDL Projects for additional information..sav extension and has the same name as the procedure or function it contains, this allows you to simply place the files in a directory included in If your program also contains variable data, you must create a separate SAVE file to contain the data. Variable data must be explicitly restored before any routine attempts to use the variables contained in the file. See Restoring Compiled IDL Programs and Data for more information.
| Note |
.pro files and re-create the SAVE file using the current version of IDL.
The following example creates two SAVE files. One SAVE file will contain variable data, loaded from an image file. This SAVE file is then restored by the program in the main SAVE file, which uses a simple call to the ARROW procedure to point out an area of interest within the image. To create these files, do the following:
READ_JPEG, (FILEPATH('pdthorax124.jpg', SUBDIRECTORY= $
['examples', 'data'])), image
.sav file by entering the following:SAVE, image, FILENAME='imagefile.sav'
This stores the SAVE file in your current working directory.
| Note |
.dat extension instead of a .sav extension. While any extension can be used to identify files created with SAVE, it is recommended that you use the .sav extension to easily identify files that can be restored.
imagefile.sav file. This variable is used in the following program statements defining the size of the window and in the TV routine which displays the image. The ARROW routine then draws an arrow within the window. Enter the following lines in a text editor.PRO draw_arrow ; Restore image data. RESTORE, 'imagefile.sav' ; Get the dimensions of the image file. s = SIZE(image, /DIMENSIONS) ; Prepare display device and display image. DEVICE, DECOMPOSED = 0 WINDOW, 0, XSIZE=s[0], YSIZE=s[1], TITLE="Point of Interest" TV, image ; Draw the arrow. ARROW, 40, 20, 165, 115 END
draw_arrow.pro. draw_arrow.pro and compile it by entering:.COMPILE draw_arrow
RESOLVE_ALL
| Note |
draw_arrow.sav containing the user-defined draw_arrow procedure. When the SAVE procedure is called with the ROUTINES keyword and no arguments, it create a SAVE file containing all currently compiled routines. Because the procedures within the draw_arrow procedures are the only routines that are currently compiled, in the IDL session, create the SAVE file as follows:SAVE, /ROUTINES, FILENAME='draw_arrow.sav'
| Note |
.sav extension and has the same base name as the main level program, it can be automatically compiled by IDL. This means that it can be called from another routine or restored from the IDL command line using only the name of the saved routine. See Automatic Compilation for details.
When importing an ASCII data file into IDL, you must first describe the format of the data using the interactive ASCII_TEMPLATE function. If you have a number of ASCII files that have the same format, you can create and save a customized ASCII template using the SAVE procedure. After creating a SAVE file of your custom template, you can avoid having to repeatedly define the same fields and records when reading in ASCII files that have the same structure.
plot.txt file in the examples/data subdirectory of the IDL distribution.
| Note |
plot.txt from the file selection dialog.
plot.txt file using the custom template, plotTemplate:
PLOT_ASCII = READ_ASCII(FILEPATH('plot.txt', SUBDIRECTORY = $
['examples', 'data']), TEMPLATE = plotTemplate)
plot.txt file data:PRINT, PLOT_ASCII
The file contents are printed in the Output Log window. Your output will resemble the following display.
SAVE, plotTemplate, FILENAME='myPlotTemplate.sav'
RESTORE, 'myPlotTemplate.sav'
This file contains your custom ASCII template information stored in the structure variable, plotTemplate.
| Note |
plotTemplate for the TEMPLATE:
PLOT_ASCII = READ_ASCII(FILEPATH('plot.txt', $
SUBDIRECTORY = ['examples', 'data']), $
TEMPLATE = plotTemplate)
PRINT, PLOT_ASCII
You can easily share your own IDL routines or utilities with other IDL users by using the SAVE routine to create a binary file of your compiled code. The following example creates a SAVE file of the XROI utility (a .pro file) and from within this file, restores a secondary SAVE file containing selected regions of interest.
XROI at the command line to open the XROI utility.mineral.png from the examples/data subdirectory of the IDL distribution. mineralROI.sav. This creates a SAVE file containing the regions of interest selected within the image.
PRO myXRoi
; Restore ROI object data by specifying a value for the
; RESTORED_OBJECTS keyword.
RESTORE, 'mineralROI.sav', RESTORED_OBJECTS = myROI
; Open XROI, specifying the previously defined value for the
; restored object data as the value for "REGIONS_IN".
XROI, READ_PNG(FILEPATH('mineral.png', $
SUBDIRECTORY = ['examples', 'data'])), $
REGIONS_IN = myROI, /BLOCK
END
Save the routine as myXRoi.pro
.FULL_RESET_SESSION at the IDL command line before creating a SAVE file to avoid saving unwanted session information..COMPILE myXRoi.pro
RESOLVE_ALL
| Note |
myXRoi.sav, containing all of the XROI utility routines. When the SAVE procedure is called with the ROUTINES keyword and no arguments, it creates a SAVE file containing all currently compiled routines. Because the routines associated with the XROI utility are the only ones that are currently compiled in our IDL session, we can create a SAVE file as follows:SAVE, /ROUTINES, FILENAME='myXRoi.sav'
myXRoi.sav. If the SAVE file uses the .sav extension and has the same base name as the main level routine, and all necessary files (in this case, mineralROI.sav and myXRoi.sav) are stored in the current working directory, simply type the name of the file, minus the .sav extension, at the command line:
myXRoi
The following figure will appear, showing the selected regions of interest.