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.
.savfor SAVE files. Using the
.savextension 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:
.profiles to an IDL Project and build the project, which creates a single
.savfile. See Creating IDL Projects for additional information.
.savextension 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.
.profiles 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
.savfile by entering the following:
SAVE, image, FILENAME='imagefile.sav'
This stores the SAVE file in your current working directory.
.datextension instead of a
.savextension. While any extension can be used to identify files created with SAVE, it is recommended that you use the
.savextension to easily identify files that can be restored.
imagefile.savfile. 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, YSIZE=s, TITLE="Point of Interest" TV, image ; Draw the arrow. ARROW, 40, 20, 165, 115 END
draw_arrow.proand compile it by entering:
draw_arrow.savcontaining 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_arrowprocedures are the only routines that are currently compiled, in the IDL session, create the SAVE file as follows:
SAVE, /ROUTINES, FILENAME='draw_arrow.sav'
.savextension 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.txtfile in the
examples/datasubdirectory of the IDL distribution.
plot.txtfrom the file selection dialog.
plot.txtfile using the custom template,
PLOT_ASCII = READ_ASCII(FILEPATH('plot.txt', SUBDIRECTORY = $ ['examples', 'data']), TEMPLATE = plotTemplate)
The file contents are printed in the Output Log window. Your output will resemble the following display.
SAVE, plotTemplate, FILENAME='myPlotTemplate.sav'
This file contains your custom ASCII template information stored in the structure variable,
plotTemplatefor the TEMPLATE:
PLOT_ASCII = READ_ASCII(FILEPATH('plot.txt', $ SUBDIRECTORY = ['examples', 'data']), $ TEMPLATE = plotTemplate)
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.
XROIat the command line to open the XROI utility.
examples/datasubdirectory 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
.FULL_RESET_SESSIONat the IDL command line before creating a SAVE file to avoid saving unwanted session information.
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
.savextension and has the same base name as the main level routine, and all necessary files (in this case,
myXRoi.sav) are stored in the current working directory, simply type the name of the file, minus the
.savextension, at the command line:
The following figure will appear, showing the selected regions of interest.