#pragma rtGlobals=1 // Use modern global access method. #pragma version = 2.1 #include #include #include #include "New jdx loader" //This set of utilities for loading IR spectra was compiled from code provided by myself and //Robin Humphry-Baker (Robin provided the bulk of it). I have done this rewrite //because I needed to get some of the loaders working for myself. I have tried to make it so //that this procedure file can be loaded and will work directly on any Macintosh using IGOR. //I have tried to avoid global variables except for the final loaded data, which is created by these routines. // //***If you are on a WinTel machine you will have to change the swap byte settings in the //read commands. Simply run a replace searching for /B=1 and replace it with /B=0.**** // //****************************************************** // Update Information in reverse chronological order //****************************************************** //1/13/05- Increased memory efficiency by deleting all the separate waves when .SRS files are loaded. //5/9/03-Version number to 2.2 from 2.1 added Nicolet .SRS reader. J. Gutow //5/3/03-Version number to 2.1 from 2.0. //5/3/03-Made identical windows version with the edited code from Donald Lavery. //5/3/03-Tested and debugged the Galactic .spc file reader. Rewrote the translate function so // that it actually comes up with something close to the right date. //5/3/03-Added code to make sure that the point x-values are ordered from lowest to highest as the //point numbers increase. This is to avoid problems with some existing IGOR functions. J. Gutow. //4/29/03-Added read of section 107 data (tracename data) from Nicolet .spg files. // Thanks to Donald Lavery for the information leading to this. //Only the Mattson .abs and Nicolet .spa and .spg loaders have been tested in this bundled //routine. If you test any others and have fixes please let me know and I will update them. //Jonathan Gutow 3/28/03. e-mail: gutow@uwosh.edu //Compatible with IGOR 4.XX //********************End Update Information******************* macro Load_IR_Spectrum() Pick_IR_File() end macro Load_IR_Series() Series_Loader() end Function Series_Loader() //This function takes a series of spectra taken at equal time intervals and loads them in all at once. //The data is stored in IGOR as separate waves for each spectrum and a matrix of spectra where the //yscale is set to the time increment. //At present it will only handle .srs, .spa and .abs files for the input data. //It is assumed that the files are named sequentially in the form name0000.ext...name9999.ext // where "ext" = "spa" or ".abs", etc.... The loader will keep going until it finds no more files in the //data folder fitting into this numbering scheme. string datapath, filename variable filenumber string basename, tempfilename, extension, matrixname, executestring variable counter, howmany, startvalue variable timeincrement Open /R/T="????"/M="Pick the first data file:" filenumber datapath = FilePathOnly(S_filename) filename = RemoveFilePath(S_filename) basename = filenameonly(filename) extension = UpperStr(FileExtension(Filename)) print "File ", filename," is being loaded from directory ",datapath strswitch (extension) //check to see if all the files are in one .srs file case ".SRS": //This is a single file with all the data in it. Load_Nic_SRS_Spectra(filenumber, datapath, filename,timeincrement,howmany) startvalue=1 //this file loader starts numbering at 1 instead of 0. timeincrement=timeincrement*60 //convert to seconds from minutes break default: Close filenumber counter = str2num(basename[(strlen(basename)-4), strlen(basename)]) startvalue = counter //just in case the numbering doesn't start with 0000 basename = basename[0,(strlen(basename)-5)] //remove the numbers do if (counter < 10) tempfilename=(datapath+basename+"000"+num2str(counter)+extension) endif if ((counter<100) && (counter >= 10)) tempfilename=(datapath+basename+"00"+num2str(counter)+extension) endif if ((counter <1000) && (counter >=100)) tempfilename=(datapath+basename+"0"+num2str(counter)+extension) endif if ((counter <10000) && (counter >=1000)) tempfilename=(datapath+basename+num2str(counter)+extension) endif if (counter > 9999) print "error: cannot handle more than 10000 files" endif Open /R/Z=1 filenumber as tempfilename if (V_flag!=0) break //stop looping, we've found the last file. endif strswitch (extension) case ".ABS": //Mattson Polaris absorbance files Load_Polaris(filenumber,datapath, RemovefilePath(tempfilename)) break case ".SPA": // Nicolet FTIR.SPA files Load_Nic_SPA_Spectrum(filenumber,datapath, RemovefilePath(tempfilename)) break default: Abort "Unrecognized file extension" endswitch counter = counter +1 close filenumber while (filenumber!=0) //until test for file existing fails... howmany=counter-1 //set to be the number of the highest file Prompt timeincrement, "Enter the time increment between spectra in seconds:" DoPrompt "Get time between Spectra", timeincrement endswitch //make a matrix of the waves. First we need to read dimensions from one of the waves it will //be made from. Then we create it. Wave DataWave=$(basename+"000"+num2str(startvalue)) //making the somewhat unsafe assumption that the numbering will //start at less than 10. make /n=(DimSize(DataWave,0), (howmany-startvalue+1)) DataMatrix Wave DataMatrix=DataMatrix //Load the matrix and set the axis scaling counter = startvalue do if (counter < 10) tempfilename=(basename+"000"+num2str(counter)) //a wave name so no extension endif if ((counter<100) && (counter >= 10)) tempfilename=(basename+"00"+num2str(counter)) //a wavename so no extension endif if ((counter <1000) && (counter >=100)) tempfilename=(basename+"0"+num2str(counter)) //a wavename so no extension endif if ((counter <10000) && (counter >=1000)) tempfilename=(basename+num2str(counter)) //a wavename so no extension endif Wave DataWave=$tempfilename DataMatrix[][counter-startvalue]=DataWave[p] if (counter == startvalue) CopyScales DataWave, DataMatrix Note DataMatrix, (note(DataWave)) endif killwaves DataWave counter = counter + 1 while (counter <= howmany) SetScale/P y 0, timeincrement, "s", DataMatrix //Rename and cleanup matrixname = (basename +"_mat") executestring = "duplicate/O DataMatrix, '"+matrixname+"'" Execute executestring Print "Series Matrix", matrixname, " created." Print "***WARNING: ALL THE SEPARATE SPECTRA HAVE BEEN DELETED. USE EXTRACT TRACE TO WORK WITH A SINGLE SPECTRUM.****" killwaves DataMatrix end Function Pick_IR_File() string datapath, filename variable filenumber, minperspec, nspec //last two needed to accommodate the SRS file reader even though this doesn't use them. Open /R/T="????"/M="Pick the data file:" filenumber datapath = FilePathOnly(S_filename) filename = RemoveFilePath(S_filename) print "File ", filename," is being loaded from directory ",datapath strswitch (UpperStr(FileExtension(Filename))) case ".ABS": //Mattson Polaris absorbance files Load_Polaris(filenumber,datapath, filename) break case ".DX": //JCAMP Load_DX_Spectrum(filenumber,datapath, filename) break case ".JDX": Readjdx(filenumber, datapath, filename) break case ".SPA": // Nicolet FTIR.SPA files Load_Nic_SPA_Spectrum(filenumber,datapath, filename) break case ".SPC": //Galactic file (As of 3/31/03 this is not working...) Load_Galactic_SPC_Spectrum(filenumber,datapath, filename) break case ".SPG": //Nicolet FTIR.SPG files Load_Nic_SPG_Spectra(filenumber,datapath, filename) break case ".SRS": //Nicolet FTIR.SRS files (series data) print "Series data file loader is not yet working. Save as .SPA files and load." Load_Nic_SRS_Spectra(filenumber,datapath, filename,minperspec,nspec) print "Series data file loader is not yet working. Save as .SPA files and load." break case ".SP": //Perkin Elmer Parragon 1000 .SP files Load_PE_SP_Spectrum(filenumber,datapath, filename) break default: Abort "Unrecognized file extension" endswitch close filenumber end function Load_Polaris(filenumber,datapath, filename) string filename, datapath variable filenumber variable firstx, lastx, delta, points string nameforwave, executestring // old loader used: GBLoadWave/B/A=limit/L=64/S=6/W=1/U=2/P=datapath FileName FSetPos filenumber, 6 //skip first six bytes FBinRead /B=0/F=5 filenumber, firstx //starting value, 64 bit IEEE FBinRead /B=0/F=5 filenumber, lastx //ending value, 64 bit IEEE //old loader used: GBLoadWave/B/A=spacing/L=64/S=292/W=1/U=2/P=datapath FileName FSetPos filenumber, 292 //skip first 292 bytes FBinRead /B=0/F=5 filenumber, delta //spacing between values, 64 bit IEEE //old loader used: GBLoadWave/B/A=points/F=1/S=300/W=1/U=2/P=datapath FileName FSetPos filenumber, 300 FBinRead /B=0/F=3 filenumber, points //number of points, signed 32 bit //old loader used: GBLoadWave/B/A=DataWave/L=32/S=512/W=1/U=(points)/P=datapath FileName make /O/n=(points) DataWave wave DataWave = DataWave FSetPos filenumber, 512 FBinRead /B=0/F=4 filenumber, DataWave //load the data SetScale /I x firstx,lastx,"wavenumbers",DataWave //set the axis lables and the scaling. SetScale d 0,2, "Absorbance", DataWave //Now check to see that the x values increase with increasing point value. If they don't than swap //all the points end over end. If (firstx > lastx) //we need to flip the wave to make sure some IGOR functions won't be confused. SwapPointOrder(DataWave) endif //now lets rename the wave and cleanup nameforwave=FileNameOnly(Filename) executestring = "duplicate/O DataWave,"+"'"+nameforwave+"'" Execute executestring print "data loaded into wave: ", nameforwave killwaves DataWave end function Load_DX_Spectrum(filenumber,datapath, filename) string filename, datapath variable filenumber variable firstx, lastx, delta, points string nameforwave, executestring, title, version, user, S_date, xunits, yunits, resolution, data_type, str string key do FReadLine filenumber,str str=StrSubstitute("## ",str,"##"); str=StrSubstitute("##",str,"##:") // Clean up string str=StrSubstitute(" = ",str,"= ") key=StringByKey("##",str,":","= "); str=StringByKey(key,str,"=",":") if (!cmpstr(key,"TITLE")) title=str[1,strlen(str)-2] endif if (!cmpstr(key,"JCAMPDX")) version=str[1,strlen(str)-2] endif if (!cmpstr(key,"DATATYPE")) endif if (!cmpstr(key,"BLOCKS")) endif if (!cmpstr(key,"ORIGIN")) endif if (!cmpstr(key,"OWNER")) // user=str[1,strlen(str)-2] endif if (!cmpstr(key,"DATE")) S_date=str[1,strlen(str)-2] endif if (!cmpstr(key,"XUNITS")) xunits=str[1,strlen(str)-2] // axes labels endif if (!cmpstr(key,"YUNITS")) yunits=str[1,strlen(str)-2] // axes labels, not useful endif if (!cmpstr(key,"RESOLUTION")) resolution=str[1,strlen(str)-2] // Spectrometer Resolution endif if (!cmpstr(key,"XFACTOR")) endif if (!cmpstr(key,"YFACTOR")) endif if (!cmpstr(key,"FIRSTX")) firstx=str2num(str[1,strlen(str)-2]) endif if (!cmpstr(key,"LASTX")) lastx=str2num(str[1,strlen(str)-2]) endif if (!cmpstr(key,"MINX")) endif if (!cmpstr(key,"MAXX")) endif if (!cmpstr(key,"FIRSTY")) endif if (!cmpstr(key,"LASTY")) endif if (!cmpstr(key,"XYDATA")) data_type=str[1,strlen(str)-2] endif if (!cmpstr(key,"XYDATA")) break endif while (1) if (!cmpstr(data_type,"(XY..XY)")) LoadWave/Q/O/G/P=DataPath/N=DataWave FileName // Load JCAMP (XY..XY) format //I think we probably need some cleanup here, but I'm not sure what. I would have to see what this loads. J. G 3/31/03 else sprintf str,"JCAMPLoadWave/R/N=DataWave/O \"%s\"",FileName print str; Execute str // Load JCAMP (X++(Y..Y) format SetScale/I x firstx, lastx, xunits, DataWave0 SetScale d 0,100, yunits,DataWave0 Note DataWave0, ("Title: "+title) Note DataWave0, ("Resolution: "+resolution) Note DataWave0, ("Date: "+S_date) //Now check to see that the x values increase with increasing point value. If they don't than swap //all the points end over end. If (firstx > lastx) //we need to flip the wave to make sure some IGOR functions won't be confused. SwapPointOrder(DataWave0) endif //now lets rename the wave and cleanup nameforwave=FileNameOnly(Filename) executestring = "duplicate/O DataWave0,'"+nameforwave+"'" Execute executestring print "data loaded into wave: ", nameforwave killwaves DataWave0 endif end function Load_Nic_SPA_Spectrum(filenumber,datapath, filename) string filename, datapath variable filenumber variable firstx, lastx, delta, points, V_filetype, V_nspectra, nSec, secOffset, V_nscans, V_nBkgScans variable a, b, c, n, secType, secLength string nameforwave, executestring, str, title, S_vers, S_date, S_backDate, S_yaxislabel, UserText, S_datatype string S_resolution, s_beamsplitter, TraceName //fill some strings title="" TraceName="" S_date="" S_Backdate = "" S_datatype="" S_yaxislabel="Absorbance" //Default if not changed by data in the file. S_Resolution ="" S_Beamsplitter="" UserText="" FReadLine filenumber,str; S_vers=str[0,strlen(str)-2] // data file type FSetPos filenumber,30; FReadLine/T="" filenumber,str; title=str[0,strlen(str)-2] // title FSetPos filenumber,288; FBinRead/B=0/F=2 filenumber,V_FileType // Must be 1 FSetPos filenumber,292; FBinRead/B=0/F=2 filenumber,V_nspectra // # of index sections FBinRead/B=0/F=2 filenumber,nSec // # of sections n=0 do FSetPos filenumber,304+16*n; FBinRead/B=0/F=2 filenumber,secType FBinRead/B=0/F=3 filenumber,secOffset FBinRead/B=0/F=3 filenumber,secLength //print "SecType:",SecType," SecOffset:",SecOffset," SecLength:",SecLength switch (secType) // Select data type case 2: // Spectral Header ReadNicSection2(filenumber,secOffset, points, firstx, lastx, V_nscans, V_nBkgScans) break case 3: // Spectral Data make /O/n=(points) DataWave wave DataWave = DataWave ReadNicSection3(filenumber, SecOffset, DataWave) break case 4: // User text UserText=ReadNicSection4(filenumber, secOffset) break case 27: // History text ReadNicSection27(filenumber, secOffset, S_Backdate, S_datatype, S_yaxislabel, S_Resolution, S_beamsplitter) break case 105: // Parameters don't know ReadNicSection105(filenumber, secOffset, a,b,c) break case 106: // Parameters don't know // FSetPos file,secOffset; FBinRead/B=0/F=2 file,wave1 break case 107: //trace name info TraceName =ReadNicSection107(filenumber, secOffset) break case 130: //Parameters don't know break endswitch n+=1 while (n lastx) //we need to flip the wave to make sure some IGOR functions won't be confused. SwapPointOrder(DataWave) endif //now let's rename the wave nameforwave=FileNameOnly(Filename) executestring = "duplicate/O DataWave,'"+nameforwave+"'" Execute executestring //Cleanup print "data loaded into wave: ", nameforwave killwaves DataWave end function Load_Galactic_SPC_Spectrum(filenumber,datapath, filename) //see www.galactic.com //Sort of working 5/2/03 J. Gutow string filename, datapath variable filenumber variable firstx, lastx, delta, points string nameforwave, executestring, xunits, yunits, s_date, s_spectrometer, s_response, str, s, S_remark string S_source, S_user, S_speed, s_resolution Variable ftflgs,fversn,fexper,fexp,fnsub,fpost,flogoff, V_dataType, a, ex_wav, V_nscans, V_gain FBinRead/B=0/F=1 filenumber,ftflgs FBinRead/B=0/F=1 filenumber,fversn // File format: 75=new LSB version FBinRead/B=0/F=1 filenumber,fexper // data type if ((fexper!=4)&(fexper!=0)) // Check for FTIR data DoAlert 0,"Data File is not FTIR datatype" // break endif FBinRead/B=0/F=1/U filenumber,fexp // Calc data exponent FBinRead/B=0/F=3 filenumber,points // # of points FBinRead/B=0/F=5 filenumber,firstx; FBinRead/B=3/F=5 filenumber,lastx // Scaling: start pt., end pt. FBinRead/B=0/F=3 filenumber,fnsub // # of sub files/waves FBinRead/B=0/F=1/U filenumber,a // number for x-axis units //need a case statement translating the number if (a==1) xunits="wavenumbers" endif FBinRead/B=0/F=1/U filenumber,a // y axis units //need a case statement translating the number if (a==2) yunits = "absorbance" else yunits = "" //set to empty endif V_dataType=(a==2)+2*(a==128) FBinRead/B=0/F=1 filenumber,a // z axis units FBinRead/B=0/F=1 filenumber,fpost // Posting disposition FBinRead/B=0/F=3 filenumber,a; s_date=translate(a) // date FReadLine/T=(num2char(0)) filenumber,str //string containing resolution S_resolution = str[0,strlen(str)-2] FSetPos filenumber,44; FReadLine/T=(num2char(0)) filenumber,S_spectrometer FSetPos filenumber,88; FReadLine/T=(num2char(0)) filenumber,S_response // data file title FReadLine/T=(num2char(0)) filenumber,str // axis label FBinRead/B=0/F=1 filenumber,flogoff Variable Subflgs,subexp,subindex // SubFile Header starts, 32 bytes FSetPos filenumber,512; FBinRead/B=0/F=1 filenumber,subflgs FBinRead/B=0/F=1 filenumber,subexp // data exponent FBinRead/B=0/F=1 filenumber,subindex // sub file # Make/O/N=(points) DataWave wave DataWave =DataWave FSetPos filenumber,544 if (fexp<128) FBinRead/B=0/F=3 filenumber,DataWave DataWave=2^(fexp-32)*DataWave else FBinRead/B=0/F=4 filenumber,dataWave // load Y data wave as IEEE 32 bit float endif if (!flogoff) FSetPos filenumber,544+points*4+64 // LOGSTC takes 64 bytes FReadLine/T=(num2char(0)) filenumber,str str=TranslateChars(str,num2char(10),";"); str=TranslateChars(str,num2char(13),"") s=(StringbyKey("NAME ",str,"=")); S_remark=s[2,strlen(s)-2] ex_wav=1/str2num(StringbyKey("LWN ",str,"=")) // Laser wavelength V_nscans=str2num(StringbyKey("SCANS ",str,"=")) V_gain=str2num(StringbyKey("GAIN ",str,"=")) s=(StringbyKey("SRC ",str,"=")); S_source=s[2,strlen(s)-2] s=(StringbyKey("USER ",str,"=")); S_user=s[2,strlen(s)-2] s=(StringbyKey("SPEED ",str,"=")); S_speed=s[2,strlen(s)-2] // S_DataFolder=StringbyKey("experiment path",str,"=") endif SetScale/I x firstx,lastx,xunits,DataWave SetScale d 0,100,yunits,DataWave Note /K DataWave Note Datawave, "resolution: "+s_resolution+" "+xunits Note Datawave, "Date: "+s_date Note Datawave, "Laser Wavelength: " +num2str( ex_wav) Note Datawave, "Number of Scans: "+num2str(V_nscans) Note Datawave, "Gain: "+ num2str(V_gain) Note Datawave, "Scan velocity: " + S_speed //Now check to see that the x values increase with increasing point value. If they don't than swap //all the points end over end. If (firstx > lastx) //we need to flip the wave to make sure some IGOR functions won't be confused. SwapPointOrder(DataWave) endif //now lets rename the wave nameforwave=FileNameOnly(Filename) executestring = "duplicate/O DataWave,'"+nameforwave+"'" Execute executestring print "data loaded into wave: ", nameforwave killwaves DataWave end function Load_Nic_SPG_Spectra(filenumber,datapath, filename) string filename, datapath variable filenumber variable firstx, lastx, delta, points, FType, NumIndSec, NumSec, SecType, SecOffset, SecLength variable NumScan, NumBScan, n, V_nscans, V_nBkgScans, a, b, c, whichspec string nameforwave, executestring, NameIR, title,S_resolution, S_date, S_Backdate,s_datatype,UserText string ylabel, S_beamsplitter,strTemp, TraceName //fill some strings title = "" TraceName="" NameIR = "" S_date="" S_Backdate = "" S_datatype="" ylabel="" S_Resolution ="" S_Beamsplitter="" UserText="" FSetPos filenumber, 30 FReadLine /T=(num2char(0)) filenumber, NameIR // Get name of spectrum FSetPos filenumber, 288 FBinRead /B=0/F=2 filenumber, FType // Has to be FType=1 FSetPos filenumber, 292 FBinRead /B=0/F=2 filenumber, NumIndSec // Number of index sections FBinRead /B=0/F=2 filenumber, NumSec // Number of sections n=0 whichspec=0 do // Read all sections FSetPos filenumber, (304+16*n) // Start of section FBinRead /B=0/F=2 filenumber, SecType // Type of section FBinRead /B=0/F=3 filenumber, SecOffset // Get offset FBinRead /B=0/F=3 filenumber, SecLength // Get length //print "SecType:",SecType," SecOffset:",SecOffset," SecLength:",SecLength switch (secType) // Select data type case 2: // Spectral Header whichspec=whichspec+1 //increment the spectrum counter if (whichspec!=1) //we're not on the first time through so this is a new spectrum //store data for previous spectrum in the wave note and wave scales nameforwave = filenameonly(filename) +"_"+ num2str((whichspec-1)) SetScale/I x firstx,lastx,"Wavenumbers",DataWave SetScale d 0,100,ylabel,DataWave Note/K DataWave Note DataWave, ("Title: "+NameIR) Note DataWave, ("TraceName: "+TraceName) Note DataWave, ("Resolution: "+S_resolution) Note DataWave, ("Date: "+S_date) Note DataWave, ("Background date: "+S_Backdate) Note DataWave, ("DataType:" + s_datatype) Note DataWave, ("Number of Scans: "+num2Str(V_nscans)) Note DataWave, ("Number of Background Scans: "+num2Str(V_nBkgScans)) Note DataWave, ("UserText: "+UserText) //Now check to see that the x values increase with increasing point value. If they don't than swap //all the points end over end. If (firstx > lastx) //we need to flip the wave to make sure some IGOR functions won't be confused. SwapPointOrder(DataWave) endif //now let's rename the wave executestring = "duplicate/O DataWave,'"+nameforwave+"'" Execute executestring print "data loaded into wave: ", nameforwave endif ReadNicSection2(filenumber,secOffset, points, firstx, lastx, V_nscans, V_nBkgScans) break case 3: // Spectral Data make /o/n=(points) DataWave wave DataWave = DataWave ReadNicSection3(filenumber, SecOffset, DataWave) break case 4: // User text UserText=ReadNicSection4(Filenumber, SecOffset) break case 27: // History text ReadNicSection27(filenumber, secOffset, S_Backdate, S_datatype, ylabel, S_Resolution, S_beamsplitter) break case 105: // Parameters don't know ReadNicSection105(filenumber, secOffset, a,b,c) break case 106: // Parameters don't know // FSetPos file,secOffset; FBinRead/B=0/F=2 file,wave1 break case 107: //trace name info TraceName =ReadNicSection107(filenumber, secOffset) break case 130: //Parameters don't know break endswitch n=n+1 // Loop index while (n lastx) //we need to flip the wave to make sure some IGOR functions won't be confused. SwapPointOrder(DataWave) endif //now let's rename the wave and cleanup executestring = "duplicate/O DataWave,'"+nameforwave+"'" Execute executestring print "data loaded into wave: ", nameforwave //now let's cleanup killwaves DataWave end function Load_Nic_SRS_Spectra(filenumber,datapath, filename,minperspec,nspec) string filename, datapath variable filenumber, &minperspec, &nspec variable spec_firstx, spec_lastx, delta, spec_points, V_filetype, V_nspectra, nSec, secOffset, spec_V_nscans, spec_V_nBkgScans variable bac_firstx, bac_lastx,bac_points,bac_V_nscans, bac_V_nBkgScans, points variable a, b, c, n, secType, secLength, whichspec, sec2count string nameforwave, executestring, str, title, S_vers, S_date, S_backDate, S_yaxislabel, UserText, S_datatype string S_resolution, s_beamsplitter, TraceName //fill some strings title="" TraceName="" S_date="" S_Backdate = "" S_datatype="" S_yaxislabel="Absorbance" //I'm making an assumption here since I cannot find where this information is in the file. S_Resolution ="" S_Beamsplitter="" UserText="" FReadLine filenumber,str; S_vers=str[0,strlen(str)-2] // data file type FSetPos filenumber,30; FReadLine/T="" filenumber,str; title=str[0,strlen(str)-2] // title FSetPos filenumber,288; FBinRead/B=0/F=2 filenumber,V_FileType // Should be 11 FSetPos filenumber,292; FBinRead/B=0/F=2 filenumber,V_nspectra // # of index sections FBinRead/B=0/F=2 filenumber,nSec // # of sections //print "FileType:",V_FileType," index sections:", V_nspectra,"number of sections:", nSec n=0 whichspec=0 sec2count = 0 do FSetPos filenumber,304+16*n; FBinRead/B=0/F=2 filenumber,secType FBinRead/B=0/F=3 filenumber,secOffset FBinRead/B=0/F=3 filenumber,secLength //print "section #:",n," SecType:",SecType," SecOffset:",SecOffset," SecLength:",SecLength switch (secType) // Select data type case 2: // Spectral Header sec2count=sec2count+1 switch(sec2count) case 1: //Header for ratioed spectra ReadNicSection2(filenumber,secOffset, spec_points, spec_lastx, spec_firstx, spec_V_nscans, spec_V_nBkgScans) //for some reason //firstx and lastx are switched in .SRS files... break case 2: //Header for background spectrum ReadNicSection2(filenumber,secOffset, bac_points, bac_lastx,bac_firstx, bac_V_nscans, bac_V_nBkgScans) //for some reason //firstx and lastx are switched in .SRS files... break endswitch break case 3: // Spectral Data if (whichspec==0) //either we're loading the initial background or one of spectral series points=bac_points else points=spec_points endif make /O/n=(points) DataWave wave DataWave = DataWave ReadNicSection3(filenumber, SecOffset, DataWave) if (whichspec==0) //store data for spectrum in the wave note and wave scales nameforwave = filenameonly(filename) +"_"+ "background" s_datatype = "background" SetScaleandNote(DataWave, bac_firstx, bac_lastx, title,TraceName, s_resolution, s_date, s_backdate, s_datatype, bac_V_nscans, bac_V_nBkgscans, UserText, S_yaxislabel) else if (whichspec < 10) nameforwave=(filenameonly(filename)+"000"+num2str(whichspec)) //a wave name so no extension endif if ((whichspec<100) && (whichspec >= 10)) nameforwave=(filenameonly(filename)+"00"+num2str(whichspec)) //a wavename so no extension endif if ((whichspec <1000) && (whichspec >=100)) nameforwave=(filenameonly(filename)+"0"+num2str(whichspec)) //a wavename so no extension endif if ((whichspec <10000) && (whichspec >=1000)) nameforwave=(filenameonly(filename)+num2str(whichspec)) //a wavename so no extension endif s_datatype = "spectrum" SetScaleandNote(DataWave, spec_firstx, spec_lastx, title,TraceName, s_resolution, s_date, s_backdate, s_datatype, spec_V_nscans, spec_V_nBkgscans, UserText, S_yaxislabel) endif whichspec=whichspec+1 //increment the spectrum counter //now let's rename the wave executestring = "duplicate/O DataWave,'"+nameforwave+"'" Execute executestring //print "data loaded into wave: ", nameforwave break case 4: // User text UserText=ReadNicSection4(filenumber, secOffset) break case 27: // History text ReadNicSection27(filenumber, secOffset, S_Backdate, S_datatype, S_yaxislabel, S_Resolution, S_beamsplitter) //print "backdate:",S_Backdate," datatype:",S_datatype," ylabel:",S_yaxislabel," resolution:",S_Resolution," beamsplitter:",S_beamsplitter break case 105: // Parameters don't know ReadNicSection105(filenumber, secOffset, a,b,c) break case 106: // Parameters don't know // FSetPos file,secOffset; FBinRead/B=0/F=2 file,wave1 break case 107: //trace name info TraceName =ReadNicSection107(filenumber, secOffset) break case 113: //Parameters don't know break case 130: //Parameters don't know break case 146: //Parameters don't know break case 148: //tracename and delay info TraceName=ReadNicSection148(filenumber,secOffset) //print TraceName break case 151: //number of series spectra and minutes per spectrum ReadNicSection151(filenumber,secOffset, nspec, minperspec) break endswitch n+=1 while (n lastx) //we need to flip the wave to make sure some IGOR functions won't be confused. SwapPointOrder(DataWave) endif //now lets rename the wave nameforwave=FileNameOnly(Filename) executestring = "duplicate/O DataWave,'"+nameforwave+"'" Execute executestring print "data loaded into wave: ", nameforwave killwaves DataWave end // below are the readers for the various sections of the nicolet files .spa and .spg and possibly .srs. //It's not all here. I don't have info on all the sections. Function/S ReadNicSection4(FileVar, Pos) Variable FileVar, Pos//FileVar = filenumber, Pos=offset for the FSetPos function. String UserText string line UserText = "" FSetPos FileVar, Pos do FReadLine /T=(num2char(0)) FileVar, Line // Read one line UserText=UserText+Line[0,strlen(Line)-2]+"\r" while (strlen(Line)>1) // Until end of string list return(UserText) End function ReadNicSection2(filenumber,secOffset, V_npnts, firstx, lastx, V_nscans, V_nBkgScans) variable filenumber,secOffset, &V_npnts, &firstx, &lastx, &V_nscans, &V_nBkgScans FSetPos filenumber,secOffset+4; FBinRead/B=0/F=3 filenumber,V_npnts FSetPos filenumber,secOffset+16; FBinRead/B=0/F=4 filenumber,firstx FBinRead/B=0/F=4 filenumber,lastx FSetPos filenumber,secOffset+36; FBinRead/B=0/F=3 filenumber,V_nscans FSetPos filenumber,secOffset+52; FBinRead/B=0/F=3 filenumber,V_nBkgScans end function ReadNicSection3(filenumber, SecOffset, DataWave) variable filenumber, SecOffset wave DataWave //DoAlert 1,"Offset to Section 3 is " + num2str(SecOffset) //if(V_flag!=1) // Abort //endif FSetPos filenumber,secOffset FBinRead/B=0/F=4 filenumber,DataWave end function ReadNicSection27(filenumber, secOffset, S_Backdate, S_datatype, S_yaxislabel, S_Resolution, S_beamsplitter) variable filenumber, secOffset string &S_Backdate, &S_datatype, &S_yaxislabel, &S_Resolution, &S_beamsplitter string str //set all strings to empty to avoid problems S_Backdate = "" S_datatype="" S_yaxislabel="" S_Resolution ="" S_Beamsplitter="" FSetPos filenumber,secOffset //move to beginning of history section Do //read strings until reach end of history section FReadLine filenumber,str if (stringmatch(str,"*Collect Sample*")) s_datatype = "Sample" //Data Type from the collect command endif if (stringmatch(str,"*Collect Background*")) s_datatype="Background" endif if (stringmatch(str,"*Background collected on*")) s_Backdate=str[26,strlen(str)-2] // Date from Background Info endif if(stringmatch(str, "*Final Format*")) S_yaxislabel=str[16,strlen(str)-2]; //gets the axis label and the format of spectrum endif if (stringmatch(str, "*Resolution*")) S_resolution=str[14,20]; //gets the resolution endif //other things typically available here, but ignored are: the bench serial number and user name while (!stringmatch(Str, "\r" )) //stop when we get a blank line end function ReadNicSection105(filenumber, secOffset, a,b,c) //don't know what this is??? variable filenumber, secOffset, &a,&b,&c FSetPos filenumber,secOffset; FBinRead/B=0/F=2 filenumber,a FBinRead/B=0/F=2 filenumber,b FBinRead/B=0/F=2 filenumber,c end function /S ReadNicSection107(filenumber,secOffset) //TraceName data variable filenumber, secOffset string strTemp FSetPos filenumber,secOffset FReadLine/T="" filenumber,strTemp return (strTemp[0,strlen(strTemp)-2]) end function /S ReadNicSection148(filenumber,secOffset) //TraceName data in .SRS file variable filenumber, secOffset string strTemp FSetPos filenumber,secOffset+16 FReadLine/T="" filenumber,strTemp return (strTemp[0,strlen(strTemp)-2]) end function ReadNicSection151(filenumber,secOffset, nspec, minperspec) variable filenumber, secOffset, &nspec, &minperspec variable spec1time, lastspectime, timeunits //get the time of first spectrum (not returned, for sanity checking) FSetPos filenumber, (secOffset+2+4*16) FBinRead /B=0/F=4 filenumber, spec1time //get the time for the last spectrum (not returned, for sanity checking) FSetPos filenumber, (secOffset +2+4*17) FBinRead /B=0/F=4 filenumber, lastspectime //get delta in time FSetPos filenumber, (secOffset +2+4*18) FBinRead /B=0/F=4 filenumber, minperspec //get the number of spectra although we don't use it for anything FSetPos filenumber, (secOffset+2*45) FBinRead /B=0/F=2 filenumber, nspec //check time units. Units can be either seconds or minutes. I cannot find where this information is except in text associated //with each spectrum?. end function /S translate(date_word) //this is made up for the initial date loader since function was missing //JG 3/28/03 variable date_word string date_string date_word = date_word + 1034056800 date_string = secs2date(date_word,0) return(date_string) end Function SetScaleandNote(DataWave, firstx, lastx, title, TraceName, s_resolution, s_date, s_backdate, s_datatype, V_nscans, V_nBkgscans, UserText, ylabel) Wave Datawave variable firstx, lastx string title, TraceName, s_resolution, s_date, s_backdate, s_datatype, ylabel variable V_nscans, V_nBkgscans string UserText SetScale/I x firstx,lastx,"Wavenumbers",DataWave SetScale d 0,100,ylabel,DataWave Note/K DataWave Note DataWave, ("Title: "+title) Note DataWave, ("TraceName: "+TraceName) Note DataWave, ("Resolution: "+S_resolution) Note DataWave, ("Date: "+S_date) Note DataWave, ("Background date: "+S_Backdate) Note DataWave, ("DataType:" + s_datatype) Note DataWave, ("Number of Scans: "+num2Str(V_nscans)) Note DataWave, ("Number of Background Scans: "+num2Str(V_nBkgScans)) Note DataWave, ("UserText: "+UserText) //Now check to see that the x values increase with increasing point value. If they don't than swap //all the points end over end. If (firstx > lastx) //we need to flip the wave to make sure some IGOR functions won't be confused. SwapPointOrder(DataWave) endif end Function SwapPointOrder(DataWave) wave &DataWave variable points, newfirstx, newlastx string units Duplicate /O DataWave TempDataWave points = DimSize(DataWave,0) DataWave = TempDataWave[points-p] //now fix the wave scaling newlastx = pnt2x(DataWave,0) newfirstx = pnt2x(DataWave,(points-1)) units = WaveUnits(DataWave,0) SetScale /I x newfirstx, newlastx, units, DataWave //cleanup killwaves TempDataWave end Function PrintFunctionList() String ListofFunctions Variable i,n,Refnum open Refnum as "FunctionList" ListofFunctions=FunctionList("*",";","KIND:2") n=ItemsinList(ListofFunctions,";") Make/O/N=(n)/T FnList for(i=0;i