#pragma rtGlobals=1 // Use modern global access method. #pragma version = 1.1 Menu "jtgSpectroscopy" Submenu "Other Data Load Procs" "File Load",MultiFileLoad() End End //name of datafolder path used for file load functions Static StrConstant ksDFPath = "root:Packages:JTG:MultiFileLoader:" Static StrConstant ksDefaultDataPath = "C:My Stuff:pg:Fluorescence:Data:SPEX_Data:SPEX FL3-22 Data:Data Files:2007:" //structure used to identify type of file to load Structure DataFileType String popupText String FileExtension String FileSubType EndStructure //*************************************************************************************************************// //***** End of Menu *****// //*************************************************************************************************************// //*************************************************************************************************************// //***** MultiFileLoad *****// //*************************************************************************************************************// // Start Multiple file load routine. Display control panel; create waves used to handle waves // // and wave selections. // // 10/31/06 modified code so that data folders are used to hold waves (list of files) and string // // unique to a MultiFileLoad panel. Now multiple panels can be open and each will retain // // its own unique information set; each of which can open files from different directories. // // A hook function is set for each open panel and when the panel is killed the associated // // data folder and waves are also killed. // // 4/12/07 Modified to select file loader based on file name extension selected with "_Auto_" // // entry in FileType listbox. Added function bpMFLGetSelectedFileList to go from File Type // // selection in popFileType popup menu to a file extenstion. This was necessary so that // // auto selection and manual type selection could use the same string switch. Changed // // version to 1.1. // // 8/10/07 Added HySPEC as a file type that can be opened. Also created a structure to // // file type information, so that different flavors of the same type (for now TIFF files) can be // // opened by the appropriate file reader. This does not work with _AUTO_ load selection. // //************************************************************************************************************// Function MultiFileLoad() String PanelName String DFName String DataLocation PanelName = UniqueName("MultiFileLoadPanel", 9, 0 ) DataLocation = ksDFPath + PanelName //Create data folders to hold panel info; ksDFPath is string constant //see top of procedure file for its value. Folder has same name as panel name. CreateDFPath(ksDFPath, PanelName) String/G $(DataLocation + ":PathToFiles") = ksDefaultDataPath make /O /T /N=10 $(DataLocation + ":w") make /O /B /U /N=10 $(DataLocation + ":sw") = 0 Wave/T w = $(DataLocation + ":w") Wave sw = $(DataLocation + ":sw") PauseUpdate; Silent 1 // building window... NewPanel /K=1 /W=(338.0,67.0,776,288) DoWindow /C $PanelName //change graph window name DoWindow /T $PanelName PanelName //change graph window title SetVariable svPath,pos={66,24},size={284,16},proc=GetFileList,title="Path" SetVariable svPath,value= $(DataLocation + ":PathToFiles") //PathToFiles Button btnSetPath,pos={8,22},size={50,20},proc=bpMFLSetPath,title="Set Path" Button btnUpdateList,pos={359,22},size={65,20},proc=bpMFLUpdateList,title="Update List" Button btnUpdateList,help={"Update list of files from current path."} GroupBox gbPath frame=1, title="Path", pos={2,5}, size={431, 43} ListBox lbFiles disable=0, editStyle= 0, listWave= w, mode=10, pos={2,55} ListBox lbFiles selWave=sw, size={200,150}, widths={200} Button btnGetSelectedFileList,pos={262,55},size={50,20},proc=bpMFLGetSelectedFileList,title="Get Files" PopupMenu popFileType,pos={206,90},size={158,21},title="File Type",proc=poprocFileType PopupMenu popFileType,mode=1,value= #"\"_Auto_;Spex (.SPT);PE L-9 (.SP);Foss (.TXT);HP UVVis (.WAV);HySPEC (.TIF); TIFF (.TIF);MM log (.LOG);GRAMS (.SPC);Text (.???)\"" SetWindow kwTopWin, hook(MultiFileLoadCleanUp )=MultiFileLoadHook End Function //*************************************************************************************************************// //***** End of MultiFileLoad *****// //*************************************************************************************************************// //************************************************************************************************************// //***** MultiFileLoadHook *****// //************************************************************************************************************// // Added 10/31/06 // // Event processing function for panel created by MultiFileLoad function. // // First intended purpuose is to clean up when the MultiFileLoad panel is killed. It is used // // to delete waves ("w" & "sw") created by when the panel is opened. // //************************************************************************************************************// Function MultiFileLoadHook(s) STRUCT WMWinHookStruct &s Variable statusCode = 0 String PanelName String DFName PanelName = s.winName DFName = ksDFPath + PanelName // print PanelName // print s.eventCode, s.eventName switch (s.eventCode) case 0: //activate window; bring helper windows to front // DoWindow /F $yzWinName // DoWindow /F $zWinName // DoWindow /F $StackWinName // statusCode = 1 break case 2: //kill window: clean up KillDataFolder $DFName statusCode = 1 break endswitch return statusCode // 0 if nothing done, else 1 End //************************************************************************************************************// //***** End of MultiFileLoadHook *****// //************************************************************************************************************// //*************************************************************************************************************// //***** bpMFLSetPath *****// //*************************************************************************************************************// // Called by Set Path button on panel. Opens dialog to select new symbolic path to // // directory containing files to load. Then calls routine to get all files from that directory and // // load into wave w for display in the list box. // // 10/31/06 Modified for data folder use. // // 6/22/07 Modified to put current multfileload path in NewPath command // //*************************************************************************************************************// Function bpMFLSetPath(ctrlName) String ctrlName String Msg String PanelName String DataLocation if(stringmatch(ctrlName, "btnSetPath") != 1) return 0 endif //string and waves associated with this panel instance are located in a data folder named //after the panel name PanelName = WinName(0, 64) //name of top panel DataLocation = ksDFPath + PanelName SVAR PathToFiles = $(DataLocation + ":PathToFiles") Msg = "Browse To The File Location..." // NewPath /M=Msg /O jtgSpecFileLoadera, PathToFiles NewPath /M=Msg /O jtgSpecFileLoader if(V_flag != 0) //user hit cancel return 0 endif PathInfo jtgSpecFileLoader if(V_flag == 0)//path doesn't exist return 0 endif //update path variable PathToFiles = S_path //fill listbox with files from new path GetFileList("",0,"","") End Function //*************************************************************************************************************// //***** End of bpMFLSetPath *****// //*************************************************************************************************************// //*************************************************************************************************************// //***** poprocFileType *****// //*************************************************************************************************************// // Called by Get Files buttons on controll panel. Check wave sw to determine which files // // were selected and assign to output string. // // Currently, this is not really used although it is called when the popup menu is accessed. // //*************************************************************************************************************// Function poprocFileType(ctrlName,popNum,popStr) : PopupMenuControl String ctrlName Variable popNum String popStr if(stringmatch(ctrlName, "popFileType") != 1) return 0 endif // print popStr End Function //*************************************************************************************************************// //***** End of poprocFileType *****// //*************************************************************************************************************// //*************************************************************************************************************// //***** bpMFLGetSelectedFileList *****// //*************************************************************************************************************// // Called by Get Files buttons on controll panel. Check wave sw to determine which files // // were selected and assign to output string. // // Query popFileType control to determine which routine to call for loading the files. // // 10/31/06 Modified for data folder use. // // 4/12/07 Modified to select file loader based on file name extension selected with "_Auto_" // // entry in FileType listbox. Added function bpMFLGetSelectedFileList to go from File Type // // selection in popFileType popup menu to a file extenstion. This was necessary so that // // auto selection and manual type selection could use the same string switch. // // Structure DataFileType // // String popupText // // String FileExtension // // String FileSubType // // EndStructure // //*************************************************************************************************************// Function bpMFLGetSelectedFileList(ctrlName) String ctrlName String Msg Variable index Variable NumFiles String FileNameList String FileNumberList String FPath_Name String FName String FType String FBaseName String FExtension String PanelName String DataLocation String FLoaderToUse Struct DataFileType stFileType //info on file type to load selected by user if(stringmatch(ctrlName, "btnGetSelectedFileList") != 1) return 0 endif ////string and waves associated with this panel instance are located in a data folder named ////after the panel name PanelName = WinName(0, 64) //name of top panel DataLocation = ksDFPath + PanelName Wave/T w = $(DataLocation + ":w") Wave sw = $(DataLocation + ":sw") SVAR PathToFiles = $(DataLocation + ":PathToFiles") // Wave sw // Wave/T w // SVAR PathToFiles //Check popFileType control (labelled "File Type") to determine //which file loading routine to call. FType = MFLGetSelectedFileType(stFileType) if(strlen(FType) == 0) DoAlert 0, "Unrecognized selection in File Type (popFileType)." return 0 endif // ControlInfo popFileType // if(abs(V_flag) == 3) // FType = S_Value //type of file to open, Spex, Lambda9... // else // DoAlert 0, "Problem with file type." // return 0 // endif FileNameList = "" FileNumberList = "" NumFiles = numpnts(sw) index = 0 Do if(((sw[index] & 0x01) || (sw[index] & 0x08)) == 1) //bit one or bit 3 is set if listbox row(index) was selected (listbox mode 10) // if((sw[index] & 0x01) == 1) //bit one is set if listbox row(index) was selected (listbox mode 4) FName = w[index] FileNameList += FName + ";" FileNumberList += num2str(index) + ";" FPath_Name = PathToFiles + FName FBaseName = ParseFilePath(3, FName, ":", 0, 0) FExtension = ParseFilePath(4, FName, ":", 0, 0) //if FileType listbox (popFileType) selection is "_Auto_", then use file extension to select appropriate file loader. if(stringmatch(FType, "_Auto_") == 1) FLoaderToUse = FExtension else FLoaderToUse = FType endif strswitch(FLoaderToUse) case "SPT": OpenSpexFile(FPath_Name) break case "SP": OpenLambda9File(FPath_Name) break case "TIF": if(stringmatch(stFileType.FileSubType, "TIFF" ) == 1) ImageLoad /N=$FBaseName /O /Q /T=TIFF/Z FPath_Name elseif(stringmatch(stFileType.FileSubType, "HySPEC" ) == 1) OpenHySPECFile(FPath_Name) endif break case "LOG": OpenMMlogFile(FPath_Name) break case "SPC": OpenGRAMSFile(FPath_Name) break case "WAV": //HP UVVis data file OpenHPUVVISFile(FPath_Name) break case "???": OpenGeneralTextFile(FPath_Name) break // case "TXT": // if(stringmatch(stFileType.FileSubType, "FOSS" ) == 1) // ImageLoad /N=$FBaseName /O /Q /T=TIFF/Z FPath_Name // endif // break default: print FBasename + " has an unrecognized file type of " + FLoaderToUse return 0 endswitch // strswitch(FLoaderToUse) // case "Spex (.SPT)": // OpenSpexFile(FPath_Name) // break // case "PE L-9 (.SP)": // OpenLambda9File(FPath_Name) // break // case "TIFF (.TIF)": // ImageLoad /N=$FBaseName /O /Q /T=TIFF/Z FPath_Name //// ImageLoad /O /Q /T=TIFF/Z FPath_Name // break // case "MM log (.LOG)": // OpenMMlogFile(FPath_Name) // break // case "GRAMS (.SPC)": // OpenGRAMSFile(FPath_Name) // break // case "Text (.???)": // OpenGeneralTextFile(FPath_Name) // break // default: // DoAlert 0, "Unrecognized File Type." // return 0 // endswitch endif index += 1 While (index < NumFiles) //For debugging print a list of files selected for loading and a list of their position in the //wave of all files in directory. // print FileNameList // print FileNumberList End Function //*************************************************************************************************************// //***** End of bpMFLGetSelectedFileList *****// //*************************************************************************************************************// //*************************************************************************************************************// //***** bpMFLGetSelectedFileList *****// //*************************************************************************************************************// // Called once by Function bpMFLGetSelectedFileList to determine the File Type selected by// // the user. // // Added 4/12/07 to accomodate automatic selection of file type ("_Auto_") based on file // // extension. // //*************************************************************************************************************// Function/S MFLGetSelectedFileType(stFileType) Struct DataFileType &stFileType String FType String FLoaderToUse //Check popFileType control (labelled "File Type") to determine //which file loading routine to call. ControlInfo popFileType if(abs(V_flag) == 3) FType = S_Value //type of file to open, Spex, Lambda9... else //Problem with file type, return empty string." return "" endif stFileType.popupText = "FType" strswitch(FType) case "_Auto_": FLoaderToUse = "_Auto_" stFileType.FileExtension = "" stFileType.FileSubType = "" break case "Spex (.SPT)": FLoaderToUse = "SPT" stFileType.FileExtension = FLoaderToUse stFileType.FileSubType = "SPEX" break case "PE L-9 (.SP)": FLoaderToUse = "SP" stFileType.FileExtension = FLoaderToUse stFileType.FileSubType = "PE" break case "HySPEC (.TIF)": FLoaderToUse = "TIF" stFileType.FileExtension = "TIF" stFileType.FileSubType = "HySPEC" break case "TIFF (.TIF)": FLoaderToUse = "TIF" stFileType.FileExtension = FLoaderToUse stFileType.FileSubType = "TIFF" break case "MM log (.LOG)": FLoaderToUse = "LOG" stFileType.FileExtension = FLoaderToUse stFileType.FileSubType = "MMlog" break case "GRAMS (.SPC)": FLoaderToUse = "SPC" stFileType.FileExtension = FLoaderToUse stFileType.FileSubType = "GRAMS" break case "HP UVVis (.WAV)": FLoaderToUse = "WAV" stFileType.FileExtension = FLoaderToUse stFileType.FileSubType = "HPUVVIS" break case "Text (.???)": FLoaderToUse = "???" stFileType.FileExtension = FLoaderToUse stFileType.FileSubType = "TEXT" break case "Foss (.TXT)": FLoaderToUse = "TXT" stFileType.FileExtension = FLoaderToUse stFileType.FileSubType = "FOSS" break default: FLoaderToUse = "" stFileType.FileExtension = FLoaderToUse stFileType.FileSubType = "" endswitch return FLoaderToUse End Function //*************************************************************************************************************// //***** End of MFLGetSelectedFileType *****// //*************************************************************************************************************// //*************************************************************************************************************// //***** GetFileList *****// //*************************************************************************************************************// // Get list of files from current path jtgSpecFileLoader, redimension waves used to hold // // file names and list box attributes. // // This will automatically put new list into listbox. // // 10/31/06 Modified for data folder use. // // 6/20/07: // 1) added line "sw = 0" to clear all selections when the listbox is updated // // 2) changed from JTGSort to builtin SortList function for a decrease in sort time of // // about 200x // // 3) changed from using a loop to fill w with wave list to using a simple assignment // // statement; little if any change in time to complete the operation. // //*************************************************************************************************************// Function GetFileList(ctrlName,varNum,varStr,varName) String ctrlName Variable varNum // value of variable as number String varStr // value of variable as string String varName // name of variable String PanelName String DataLocation //string and waves associated with this panel instance are located in a data folder named //after the panel name PanelName = WinName(0, 64) //name of top panel DataLocation = ksDFPath + PanelName Wave/T w = $(DataLocation + ":w") Wave sw = $(DataLocation + ":sw") Variable NumFiles Variable i = 0 String FileList = IndexedFile(jtgSpecFileLoader, -1, "????") // FileList = SimpleSort(FileList, ";") //jtg_Utilities Strings: sorts alphabetically FileList = SortList(FileList, ";", 16) //16: case-insensitive alphanumeric sort that sorts wave0 and wave9 before wave10. NumFiles = itemsinlist(FileList, ";") Redimension /N=(NumFiles) w Redimension /N=(NumFiles) sw sw = 0 // for(i=0; i