// PHI SPE File Loader // version 2.0 // 2017.12.23 // jjw #pragma rtGlobals=3 // Use modern global access method and strict wave access // constants to parse the header Static StrConstant sVersion = "SoftwareVersion:*" Static StrConstant sREX = "SoftwareVersion: [[:alpha:]]+[ ]?[[:alpha:]]?([[:digit:]]+)\.*" Static StrConstant sNSpectra = "NoSpectralReg" Static StrConstant sSpecRegDef = "SpectralRegDef" // main routine // load PHI SPE files // returns name of file loaded Function/S LoadPHISPEFile() DFREF cdf = GetDataFolderDFR() // variables and strings variable vFileRef string sFilePath, sDataFolder, sFileName = "" // set the file path // abort if cancelled if (SetPHISPEFilesPath() < 0) return sFileName endif // select a file to load Open/P=PHISPEFiles/D/R/F="PHI SPE Files (*.spe):.spe;"/M="Select the SPE file to load" vFileRef if( StrLen(S_fileName) == 0 ) return sFileName //user cancelled file selection endif sFilePath = S_fileName // create and move to a datafolder by the file name sFileName = ParseFilePath(3,SFilePath,":",0,0) sDataFolder = CleanUpName(sFileName,0) NewDataFolder/O/S $sDataFolder // create the required globals variable/G nSpectra=0, nVersion=0 make/D/O/N=4 PHISPEBinaryHeader=0 make/D/O/T/N=0 PHISPETextHeader, wSpectrumNames make/D/O/N=(0,5) PHISPESpectraHeader, wSpectrumScales // label the spectrum scale dimensions SetDimLabel 1, 0, npnts, wSpectrumScales SetDimLabel 1, 1, start, wSpectrumScales SetDimLabel 1, 2, step, wSpectrumScales SetDimLabel 1, 3, dwelltime, wSpectrumScales SetDimLabel 1, 4, Ep, wSpectrumScales // open the file to load Open/R vFileRef as sFilePath // get and parse the text header GetPHISPETextHeader(vFileRef) ParsePHISPETextHeader() // get the binary headers GetPHISPEBinaryHeaders(vFileRef) // ParsePHISPESpectraHeader() // load the spectra LoadPHISPESpectra(vFileRef) // close file, return to current data folder, and exit close vFileRef SetDataFolder cdf return sFileName end // load each spectrum Static Function LoadPHISPESpectra(vFileRef) variable vFileRef // globals DFREF pdf = GetDataFolderDFR() NVAR/SDFR=pdf nSpectra, nVersion wave/T/SDFR=pdf wSpectrumNames wave/SDFR=pdf wSpectrumScales // variables and strings variable ic, npoints, vReadVal string sName // load spectra for(ic=0; ic