#pragma rtGlobals=3 // Use modern global access method and strict wave access. #pragma rtGlobals=1 // Use modern global access method. Function Browse4Folder(PathToFldr,CtrlName,PromptStr,CurrentFldr) // based on mg code from htdma toolkit String PathToFldr // path to data folder String PromptStr // Prompt text in data browser String CurrentFldr // current data folder String CtrlName variable exit=0 // stops trying when exit reaches 6 do string/g BrowserList string /g TempFldr=CurrentFldr variable/g Flag execute "CreateBrowser prompt=\""+PromptStr+"\", select=tempfldr" // prompt for file killstrings/z tempfldr svar BrowserList=s_browserlist nvar Flag=V_Flag // print browser_list if (!Flag) PathToFldr="cancelled" break endif if (itemsinlist(BrowserList)==1) if (stringmatch("root:ROOT;", BrowserList)) //data browser returns strange path if root is selected BrowserList="root" endif PathToFldr=stringfromlist(0,BrowserList)+":" if(DataFolderExists(PathToFldr)) break else doalert 0, "you must select a data folder, not a wave, string or variable! => try again" endif else doalert 0, "none or multiple data folders were selected => try again" endif exit+=1 while (exit<6) //maximum six attempts End Function/S time2string(timevar) // converts a time in secs to format yyyy_mm_dd_hhmmss variable timevar string/g timestr wave timeW variable secs, mins, hrs secs=mod(timevar, 60) timevar-=secs mins=(mod(timevar,3600))/60 timevar-=(mins*60) hrs=(mod(timevar,60*60*24))/(60*60) timevar-=(hrs*60*60) string hstr=num2str(hrs), mstr=num2str(mins), sstr=num2str(secs) if(strlen(hstr)==1) hstr="0"+hstr endif // if(strlen(mstr)==1) mstr="0"+mstr endif // if(strlen(sstr)==1) sstr="0"+sstr endif timestr=secs2date(timevar,-2,"_")+"_"+hstr+mstr+sstr End Function GraphSlider(windowname, graphfunctionname) // sets up a slider window string windowname, graphfunctionname // string containing name of slider, string containing time base wave name // PROMPT USER TO SELECT FOLDER CONTAINING EXPERIMENT string PathToFldr="",CtrlName="",PromptStr="Select folder containing data to plot",CurrentFldr=getdatafolder(1) Browse4Folder(PathToFldr,CtrlName,PromptStr,CurrentFldr) DoWindow/K $windowname // kill slider if it exists variable/g val=0 // global svar timebasewave wave timeW=$timebasewave svar run_time_global run_time_global=secs2date(timeW[val],3)+" "+secs2time(timeW[val],0) display/n=$windowname/W=(100,100,600,500) // displays a graph panel, size is nit user defined Setvariable setvar font="Arial", fsize=12, limits={0,numpnts(timeW),1}, size={85,30}, win=$windowname Setvariable setvar pos={325,10}, variable=val, proc=SetVarProcDataSlider, title="Scan" // runs proc to display data Slider/Z varslider font="Arial", fsize=12, limits={0,numpnts(timeW),1},side=0, size={300,30}, win=$windowname // slider between scans Slider/Z varslider vert=0, pos={10,10}, variable=val, proc=SetSliderProcDataSlider, win=$windowname // runs proc to display data Setvariable runtime win=$windowname, bodywidth=110, font=arial, live=1, noedit=1, value=run_time_global, size={110,300}, pos={425,10}, title=" " // displays run time // svar variablefunctioname execute/q/z variablefunctioname // sets up additional variable displays End Function SetVarProcDataSlider(ctrlName,varNum,varStr,varName) : SetVariableControl String ctrlName, varStr, varName Variable varNum Variable/g SliderValue SliderValue=varNum string/g run_time_global svar timebasewave wave timeW=$timebasewave run_time_global=secs2date(timeW[varNum],3)+" "+secs2time(timeW[varNum],0) // run graph function svar graphfunctionname svar updatevars execute/q/z updatevars execute/q/z graphfunctionname End Function SetSliderProcDataSlider(ctrlName,value,event) :SliderControl // slider control String ctrlName // name of this slider control Variable value // value of slider Variable event // bit field: bit 0: value set; 1: mouse down, 2: mouse up, 3: mouse moved String/g run_time_global svar timebasewave Variable/g SliderValue SliderValue=value wave timeW=$timebasewave run_time_global=secs2date(timeW[value],3)+" "+secs2time(timeW[value],0) // run graph function svar graphfunctionname svar updatevars execute/q/z updatevars execute/q/z graphfunctionname End //****** Function time2date(time_wave) Wave time_wave // numeric wave in seconds variable i //Make a text wave with the same number of rows as the input wave. Make/O/d/N=(DimSize(time_wave, 0))/T date_time_text_wave For (i=0; i<(numpnts(time_wave)); i+=1) date_time_text_wave = secs2time(time_wave[i], 0) Endfor Appendtotable date_time_text_wave End Function LoadOPC_SPD() // Loads opc data // Prompts to select folder into which data is loaded String PathToFldr="",CtrlName="",PromptStr="Select folder to load PINE data into:",CurrentFldr=getdatafolder(1) // variables for Browse4Folder Browse4Folder(PathToFldr,CtrlName,PromptStr,CurrentFldr) // prompts user to select an experiment // Get folder with data in it NewPath/M="Select folder containing OPC_spd data:"/O/Q pathname // prompts user to select path to data folder PathInfo pathname // Abort if cancel is pressed If(V_flag==0) Abort "proceedure cancelled" EndIf // Make matrix for opc data Make/o/n=(0,10) opc_spdDataMatrix // Strings and Variables Variable numfolders,n, subdirs, numfiles, filenum, refnum // variables String folderlist, filename, name, currentfolder // strings // Counts number of files in folder NumFiles=ItemsInList(IndexedFile(pathname,-1,".txt")) // # files in folder , specify extensions e.g. ".txt" For(filenum=0;filenum0) // specify minimum file size to load e.g. >10bytes Load_opc_spd_File(filename, refnum) // calls function to load file // unique function for specific file format Wave Temp_opc_spdDataMatrix0 // add loaded waves to loaded data InsertPoints DimSize(opc_spdDataMatrix,0),DimSize(Temp_opc_spdDataMatrix0,0), opc_spdDataMatrix opc_spdDataMatrix[DimSize(opc_spdDataMatrix,0)-DimSize(Temp_opc_spdDataMatrix0,0),*][]=Temp_opc_spdDataMatrix0[p-DimSize(opc_spdDataMatrix,0)+DimSize(Temp_opc_spdDataMatrix0,0)][q] currentfolder=GetDataFolder(1) // root folder for experiment Endif // end data to folder allocation Endif EndFor // end loop through files of a dp Close/A // close open files Killwaves Temp_opc_spdDataMatrix0 // Do additional analytsis on opc_spd data Processopc_spd() // adds a time wave End Function Load_opc_spd_File(filename, refnum) // load single opc_spd file String filename Variable refnum print "Loading: " + filename //LoadWave/G/O/M/N=Temp_opc_spdDataMatrix/Q filename //this works the best, especially if the text file has tabs and spaces //LoadWave/G/l={0,7,0,0,0}/O/M/N=Temp_Temp_opc_spdDataMatrix/Q filename //this works the best, especially if the text file has tabs and spaces LoadWave/G/v={"\t","- :", 1,1}/O/M/N=Temp_Temp_opc_spdDataMatrix/Q filename //this works the best, especially if the text file has tabs and spaces End Function Processopc_spd() // Additional processing of opc_spd data Wave opc_spdDataMatrix Make/o/d/n=(DimSize(opc_spdDataMatrix,0)) OPC_SPDTime Make/o/d/n=(DimSize(opc_spdDataMatrix,0)) OPC_SPDdate SetScale d,0,0,"dat" OPC_SPDTime SetScale d,0,0,"dat" OPC_SPDdate OPC_SPDTime=OPC_SPDDataMatrix[p][1] make/D/N=(numpnts(OPC_SPDtime)) dates dates = Date2Secs(2023, 1, 1)+86400*OPC_SPDtime End End