function mg_savefile::_overloadHelp, varname
compile_opt strictarr
result = ''
arrformat = '(%"%-15s %-9s = Array[%s]%s")'
scalarformat = '(%"%-15s %-9s = %s%s")'
typenames = ['UNDEFINED', 'BYTE', 'INT', 'LONG', 'FLOAT', 'DOUBLE', $
'STRING', 'STRUCTURE', 'DCOMPLEX', 'POINTER', 'OBJREF', $
'UINT', 'ULONG', 'LONG64', 'ULONG64']
varnames = self->names(count=nvars)
for v = 0L, nvars - 1L do begin
type = self->size(varnames[v], /type)
ndims = self->size(varnames[v], /n_dimensions)
dims = strjoin(strtrim(self->size(varnames[v], /dimensions), 2), ', ')
if (ndims gt 0) then begin
result += string(varnames[v], typenames[type], dims, mg_newline(), $
format=arrformat)
endif else begin
value = self->get(varnames[v])
help, value, output=output
pos = strsplit(output, len=len)
repr = strmid(output, pos[3])
result += string(varnames[v], typenames[type], repr, $
mg_newline(), $
format=scalarformat)
endelse
endfor
result = strmid(result, 0, strlen(result) - strlen(mg_newline()))
if (result eq '') then result = 'no regular IDL variables'
return, result
end
function mg_savefile::_overloadPrint
compile_opt strictarr
result = ''
noneformat = '(%"%s: 0%s")'
format = '(%"%s: %d (%s)%s")'
varnames = self->names(count=nvars)
if (nvars eq 0L) then begin
result += string('Variables', mg_newline(), format=noneformat)
endif else begin
result += string('Variables', nvars, strjoin(varnames, ', '), $
mg_newline(), $
format=format)
endelse
commonnames = self->names(count=ncommon, /common_block)
if (ncommon eq 0L) then begin
result += string('Common blocks', mg_newline(), format=noneformat)
endif else begin
result += string('Common blocks', ncommon, strjoin(commonnames, ', '), $
mg_newline(), $
format=format)
endelse
sysvarnames = self->names(count=nsysvar, /system_variable)
if (nsysvar eq 0L) then begin
result += string('System variables', mg_newline(), format=noneformat)
endif else begin
result += string('System variables', nsysvar, strjoin(sysvarnames, ', '), $
mg_newline(), $
format=format)
endelse
objectnames = self->names(count=nobjs, /object_heapvar)
if (nobjs eq 0L) then begin
result += string('Object heap variables', mg_newline(), format=noneformat)
endif else begin
result += string('Object heap variables', nobjs, $
strjoin(strtrim(objectnames, 2), ', '), $
mg_newline(), $
format=format)
endelse
ptrnames = self->names(count=nptrs, /pointer_heapvar)
if (nptrs eq 0L) then begin
result += string('Pointer heap variables', mg_newline(), format=noneformat)
endif else begin
result += string('Pointer heap variables', nptrs, $
strjoin(strtrim(ptrnames, 2), ', '), $
mg_newline(), $
format=format)
endelse
structnames = self->names(count=nstrdef, /structure_definition)
if (nstrdef eq 0L) then begin
result += string('Functions', mg_newline(), format=noneformat)
endif else begin
result += string('Functions', nstrdef, strjoin(structnames, ', '), $
mg_newline(), $
format=format)
endelse
functionnames = self->names(count=nfunction, /function)
if (nfunction eq 0L) then begin
result += string('Functions', mg_newline(), format=noneformat)
endif else begin
result += string('Functions', nfunction, strjoin(functionnames, ', '), $
mg_newline(), $
format=format)
endelse
procedurenames = self->names(count=nprocedures, /procedure)
if (nprocedures eq 0L) then begin
result += string('Procedures', mg_newline(), format=noneformat)
endif else begin
result += string('Procedures', nprocedures, strjoin(procedurenames, ', '), $
mg_newline(), $
format=format)
endelse
result = strmid(result, 0, strlen(result) - strlen(mg_newline()))
return, result
end
function mg_savefile::_overloadBracketsRightSide, isRange, ss1
compile_opt strictarr
on_error, 2
if (isRange[0] gt 0) then message, 'ranges not allowed'
return, self->get(ss1)
end
function mg_savefile::get, saveitem, _ref_extra=e
compile_opt strictarr
self->restore, saveitem, _extra=e
isVar = 1B
for el = 0L, n_elements(e) - 1L do begin
if (e[el] ne 'COUNT') then isVar = 0B
endfor
return, isVar ? scope_varfetch(saveitem) : !null
end
function mg_savefile::init, filename, _extra=e
compile_opt strictarr
if (~self->IDL_Object::init()) then return, 0
if (~self->IDL_Savefile::init(filename, _extra=e)) then return, 0
return, 1
end
pro mg_savefile__define
compile_opt strictarr
define = { MG_Savefile, inherits IDL_Object, inherits IDL_Savefile }
end
s = mg_savefile(file_which('cow10.sav'))
help, s
print, s
r = 0.5
p = plot3d([- r, r], [- r, r], [- r, r], axis_style=0, /nodata)
p = polygon([[s['x']], [s['y']], [s['z']]], connectivity=s['polylist'], /data)
end