Save Experiment SnapShot with Date+Time Stamp Suffix
jjweimer
I often need to save snap shots of experiments with brief notes in case I need to return. This saves a snap shot of the current experiment with a date+time stamp suffix. It puts a global string SnapShotNote with comments before saving. Saves to home directory (same as current experiment) or to user's choice if first time. Recognizes if the current experiment is itself a snap shot. Relies on a function to create the date + time stamp.
21-04-16: corrected a mistake in ParseFilePath
// Save Experiment SnapShot
Function SaveExpSnapShot()
string pstr = "", nstr, lssn, ossn
variable vs = 0, vh = 0, vk = 1
// get current experiment info
string CurrExperiment = IgorInfo(1)
string dstamp = DateTimeStamp()
string SExpName
// note string
Prompt nstr, "What note for this snapshot?"
DoPrompt "Note for snapshot?" nstr
if (v_flag == 1)
return 0
endif
sprintf lssn, "%s\r%s", DateTimeStamp(dsep="-",tsep=":",sep="/"), nstr
// save it?
PathInfo home
if (v_flag == 0)
NewPath/Q/C/M="Where should this experiment be saved?" tsave
if (v_flag == 0)
vs = 1
endif
else
vh = 1
vs = 1
endif
if (vs == 1)
SVAR/Z SSN = root:SnapShotNote
if (SVAR_exists(SSN))
SExpName = ParseFilePath(1,CurrExperiment,"_",1,0) + dstamp
ossn = SSN
SSN = lssn + "\r" + ossn
vk = 0
else
SExpName = CurrExperiment + "_" + dstamp
string/G root:SnapShotNote
SVAR SSN = root:SnapShotNote
SSN = lssn
endif
switch(vh)
case 0: // not to home
SaveExperiment/P=tsave/C as SExpName
PathInfo tsave
pstr = S_path
KillPath tsave
break
case 1: // to home
SaveExperiment/C as SExpName
PathInfo home
pstr = S_path
break
endswitch
switch(vk)
case 0: // replace existing with old
SSN = ossn
break
case 1: // kill temporary
killstrings/Z root:SnapShotNote
break
endswitch
sprintf nstr, "%s --> Experiment snapshot saved: %s %s\r%s", DateTimeStamp(dsep="-",tsep=":",sep="/"), pstr, SExpName, nstr
print nstr
endif
return 0
end
// date/time stamp in various ways
// dsep - date separator string (default "")
// tsep - time separator string (default "")
// sep - date + time separator string (default "")
// dtonly - 0: all, 1: date only, 2: time only (default 0)
Function/S DateTimeStamp([dsep,tsep,sep,dtonly])
string dsep, tsep, sep
variable dtonly
string a, b, c, dstr, tstr, rtstr, gExp
if (ParamIsDefault(sep))
sep = ""
endif
if (ParamIsDefault(dsep))
dsep = ""
endif
if (ParamIsDefault(tsep))
tsep = ""
endif
if (ParamIsDefault(dtonly))
dtonly = 0
endif
gExp = "([0-9]+)/([0-9]+)/([0-9]+)"
SplitString/E=(gExp) secs2date(datetime,-1), a, b, c
dstr = c[2,3] + dsep + b + dsep + a
gExp = "([0-9]+):([0-9]+)"
SplitString/E=(gExp) secs2time(datetime,2), a, b
tstr = a + tsep + b
switch(dtonly)
case 0: // all
rtstr = dstr + sep + tstr
break
case 1: // date only
rtstr = dstr
break
case 2: // time only
rtstr = tstr
break
endswitch
return rtstr
end
Function SaveExpSnapShot()
string pstr = "", nstr, lssn, ossn
variable vs = 0, vh = 0, vk = 1
// get current experiment info
string CurrExperiment = IgorInfo(1)
string dstamp = DateTimeStamp()
string SExpName
// note string
Prompt nstr, "What note for this snapshot?"
DoPrompt "Note for snapshot?" nstr
if (v_flag == 1)
return 0
endif
sprintf lssn, "%s\r%s", DateTimeStamp(dsep="-",tsep=":",sep="/"), nstr
// save it?
PathInfo home
if (v_flag == 0)
NewPath/Q/C/M="Where should this experiment be saved?" tsave
if (v_flag == 0)
vs = 1
endif
else
vh = 1
vs = 1
endif
if (vs == 1)
SVAR/Z SSN = root:SnapShotNote
if (SVAR_exists(SSN))
SExpName = ParseFilePath(1,CurrExperiment,"_",1,0) + dstamp
ossn = SSN
SSN = lssn + "\r" + ossn
vk = 0
else
SExpName = CurrExperiment + "_" + dstamp
string/G root:SnapShotNote
SVAR SSN = root:SnapShotNote
SSN = lssn
endif
switch(vh)
case 0: // not to home
SaveExperiment/P=tsave/C as SExpName
PathInfo tsave
pstr = S_path
KillPath tsave
break
case 1: // to home
SaveExperiment/C as SExpName
PathInfo home
pstr = S_path
break
endswitch
switch(vk)
case 0: // replace existing with old
SSN = ossn
break
case 1: // kill temporary
killstrings/Z root:SnapShotNote
break
endswitch
sprintf nstr, "%s --> Experiment snapshot saved: %s %s\r%s", DateTimeStamp(dsep="-",tsep=":",sep="/"), pstr, SExpName, nstr
print nstr
endif
return 0
end
// date/time stamp in various ways
// dsep - date separator string (default "")
// tsep - time separator string (default "")
// sep - date + time separator string (default "")
// dtonly - 0: all, 1: date only, 2: time only (default 0)
Function/S DateTimeStamp([dsep,tsep,sep,dtonly])
string dsep, tsep, sep
variable dtonly
string a, b, c, dstr, tstr, rtstr, gExp
if (ParamIsDefault(sep))
sep = ""
endif
if (ParamIsDefault(dsep))
dsep = ""
endif
if (ParamIsDefault(tsep))
tsep = ""
endif
if (ParamIsDefault(dtonly))
dtonly = 0
endif
gExp = "([0-9]+)/([0-9]+)/([0-9]+)"
SplitString/E=(gExp) secs2date(datetime,-1), a, b, c
dstr = c[2,3] + dsep + b + dsep + a
gExp = "([0-9]+):([0-9]+)"
SplitString/E=(gExp) secs2time(datetime,2), a, b
tstr = a + tsep + b
switch(dtonly)
case 0: // all
rtstr = dstr + sep + tstr
break
case 1: // date only
rtstr = dstr
break
case 2: // time only
rtstr = tstr
break
endswitch
return rtstr
end
Forum
Support
Gallery
Igor Pro 9
Learn More
Igor XOP Toolkit
Learn More
Igor NIDAQ Tools MX
Learn More