#pragma rtGlobals=3 // Use modern global access method and strict wave access. // DisplayHelpTopic "Loading Waves Using Igor Procedures" //////////////////////////////////////////////////// // Add an item to Igor's Load Waves submenu (Data menu) Menu "Macros" Submenu "Load IR files" "Load IR Text File...", Load_IR("", "") "Load IR Text Files In Folder...", Load_all_txt_Files("") "Plot IR" end end ///////////////////////////////////////////////////// // load one infrared .txt file with two columns ( wavenumber, absorbance), giving 2 waves. // Give name of the files to the both waves and add sufix for absorbance, // Set scaling of second column, // duplicate absorbance twice (_N and _F) // kill first column Function Load_IR(fileName, pathName) String fileName// File name to load, not including the path, or "" to get dialog String pathName // Name of path or "" to get dialog // Strip the extension from the file name to get the generic name. String genericname = fileName[0, strsearch(fileName, ".txt", inf, 1) - 1] Wave Wavenumber, Absorbance String Abstr="_A" String AbstrN="_N" String AbstrF="_F" String Wavenumberwave=genericname String Absorbancewave=genericname+Abstr String AbsorbancewaveN=genericname+AbstrN String AbsorbancewaveF=genericname+AbstrF // Load the waves and set the globals LoadWave/A/G/D/O/P=$pathName/B="C=1, N=Wavenumber; C=1, N=Absorbance;" fileName SetScale/P x, 5000, 700, "", $Absorbancewave duplicate/o Wavenumber $Wavenumberwave duplicate/o Absorbance $Absorbancewave duplicate/o Absorbance $AbsorbancewaveN duplicate/o Absorbance $AbsorbancewaveF KillWaves/Z Wavenumber return 0 // Signifies success. End ///////////////////////////////////////////////////// // load several .txt files at once, with each of them having two columns, giving 2 waves. Function Load_all_txt_Files(pathName) String pathName // Name of an Igor symbolic folder created by Misc->NewPath String fileName Variable index=0 if (strlen(pathName) == 0) String message = "Select a directory containing only Sylvie data files" NewPath/O/M=message SylvieDataPath // This displays a dialog in which you can select a folder if (V_flag != 0) return V_flag // -1 means user canceled endif pathName = "SylvieDataPath" endif Variable result= 0 do // Loop through each file in folder fileName = IndexedFile($pathName, index, ".txt") // catch .txt files in folder if (strlen(fileName) == 0) // No more files ? break // Break out of loop endif result = Load_IR(pathName, fileName) if( result == -1 ) break // user cancelled or no waves in this file (which we take to be an error) endif index += 1 while (1) if (Exists("SylvieDataPath")) // Kill temp path if it exists KillPath temporaryPath endif return result // 0 Signifies success. End