7185
How to explore and use the contents of a .sav file in IDL?
Before restoring a .sav file which is only including variables you may want to explore its content first. This is possible using the IDL_Savefile object class: https://www.nv5geospatialsoftware.com/docs/IDL_Savefile.html
; choose your .sav file
savefile = "C:\Path\to\your\Sav\File\sav_file.sav"
// or by selecting the file with: savefile=dialog_pickfile()
; create the IDL_Savefile object from this .sav file and query its content
sObj = OBJ_NEW('IDL_Savefile', savefile)
sObj.contents()
; output of the content:
{
"FILENAME": "C:\Path\to\your\Sav\File\sav_file.sav",
"DESCRIPTION": "",
"FILETYPE": "Portable (XDR)",
"USER": "username",
"HOST": "hostname",
"DATE": "Tue Aug 12 10:42:43 2025",
"ARCH": "x86_64",
"OS": "Win32",
"RELEASE": "9.1.0",
"N_COMMON": 0,
"N_VAR": 0,
"N_SYSVAR": 0,
"N_PROCEDURE": 2877,
"N_FUNCTION": 2025,
"N_OBJECT_HEAPVAR": 0,
"N_POINTER_HEAPVAR": 0,
"N_STRUCTDEF": 0
}
; it is also possible to access the number of variables included in this .sav file ; as well as the variable names ; e.g.
print,content.N_VAR
foreach Name, sObj.Names() do print,Name,sObj.size(Name)
; you can then decide to restore only specific variables based on their names
data=sObj.Names()
sObj.restore,(data[0])
; another useful option is to convert specific variable names into a variable identifier using SCOPE_VARFETCH, so you can then manipulate this variable in your IDL code afterwards
b=SCOPE_VARFETCH(data[0])
help,b
------------------------------------------------
Created by BC on 1/19/21; modified by MT on 08/12/25
Reviewed by BC(US) on 1/21/2021