Improving the /Z flag of Wave, NVAR, SVAR
thomas_braun
1.) Currently the /Z of the above operations doesn't recognize dfrefs which are null and are supplied by /SDFR.
For example the following is my current way in referencing global vars in some of my procedures.
if(!DataFolderExists(settingsFolder))
print "BUG: settings folder does not exist"
return 0
endif
NVAR/Z/SDFR=$settingsFolder scrapFormatOne, scrapFormatTwo, hddFormatOne, hddFormatTwo, exportLowRes, exportHighRes
if(!NVAR_Exists(scrapFormatOne) || !NVAR_Exists(scrapFormatTwo) || !NVAR_Exists(hddFormatOne) || !NVAR_Exists(hddFormatTwo) || !NVAR_Exists(exportLowRes) || !NVAR_Exists(exportHighRes))
print "BUG: some nvars are missing"
return 0
endif
print "BUG: settings folder does not exist"
return 0
endif
NVAR/Z/SDFR=$settingsFolder scrapFormatOne, scrapFormatTwo, hddFormatOne, hddFormatTwo, exportLowRes, exportHighRes
if(!NVAR_Exists(scrapFormatOne) || !NVAR_Exists(scrapFormatTwo) || !NVAR_Exists(hddFormatOne) || !NVAR_Exists(hddFormatTwo) || !NVAR_Exists(exportLowRes) || !NVAR_Exists(exportHighRes))
print "BUG: some nvars are missing"
return 0
endif
I always have to check that the datafolder exists before I pass it to the /SDFR flag. In my eyes the /Z flag should also prevent run time errors due to invalid /null dfrefs in the /SDFR flag.
The following example shows hopefully what I mean:
#pragma rtGlobals=3 // Use modern global access method.
Function doTest()
string folder="root:testing"
string folderNonExistent="root:testingNonExistent"
NewDataFolder/O $folder
dfref folderDFR = $folder
dfref folderNonExistentDFR = $folderNonExistent
variable/G folderDFR:nvarOne
variable/G folderDFR:nvarTwo
variable/G folderDFR:nvarThree
variable/G folderDFR:nvarFour
variable/G folderDFR:nVarFive
NVAR/Z nvarOne = $(folder) +":nvarOne"
if(NVar_Exists(nvarOne))
print "nvarOne exists"
endif
NVAR/Z nvarTwo = $(folderNonExistent) +":nvarTwo"
if(NVar_Exists(nvarTwo))
print "nvarTwo exists"
endif
NVAR/Z/SDFR=folderDFR nVarThree
if(NVar_Exists(nVarThree))
print "nVarThree exists"
endif
NVAR/Z/SDFR=folderNonExistentDFR nVarFour // <- runtime error
if(NVar_Exists(nVarFour))
print "nVarFour exists"
endif
KilLDataFolder/Z $folder
// now the dfref is still valid but the folder is non existent
NVAR/Z/SDFR=folderDFR nVarFive // no run time error, /Z works as expected
if(NVar_Exists(nVarFive))
print "nVarFive exists"
endif
End
Function doTest()
string folder="root:testing"
string folderNonExistent="root:testingNonExistent"
NewDataFolder/O $folder
dfref folderDFR = $folder
dfref folderNonExistentDFR = $folderNonExistent
variable/G folderDFR:nvarOne
variable/G folderDFR:nvarTwo
variable/G folderDFR:nvarThree
variable/G folderDFR:nvarFour
variable/G folderDFR:nVarFive
NVAR/Z nvarOne = $(folder) +":nvarOne"
if(NVar_Exists(nvarOne))
print "nvarOne exists"
endif
NVAR/Z nvarTwo = $(folderNonExistent) +":nvarTwo"
if(NVar_Exists(nvarTwo))
print "nvarTwo exists"
endif
NVAR/Z/SDFR=folderDFR nVarThree
if(NVar_Exists(nVarThree))
print "nVarThree exists"
endif
NVAR/Z/SDFR=folderNonExistentDFR nVarFour // <- runtime error
if(NVar_Exists(nVarFour))
print "nVarFour exists"
endif
KilLDataFolder/Z $folder
// now the dfref is still valid but the folder is non existent
NVAR/Z/SDFR=folderDFR nVarFive // no run time error, /Z works as expected
if(NVar_Exists(nVarFive))
print "nVarFive exists"
endif
End
2.) It would be also terrific if there would be an easier way to get to know if the last NVAR/SVAR/Wave call with the /Z flag was completely successfull or not.
The idea would be along the lines of
NVAR/Z/SDFR=$settingsFolder scrapFormatOne, scrapFormatTwo, hddFormatOne, hddFormatTwo, exportLowRes, exportHighRes
if(!lastRefSuccess()) // or a V_flag
print "BUG: some nvars are missing"
return 0
endif
if(!lastRefSuccess()) // or a V_flag
print "BUG: some nvars are missing"
return 0
endif
Thanks for reading,
Thomas