#pragma rtGlobals=3 // Use modern global access method and strict wave access. Function LoadPAM() // Loads PAM data // Prompts to select folder into which data is loaded String PathToFldr="",CtrlName="",PromptStr="Select folder to load PAM 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 PAM 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 PAM data Make/o/n=(0,45) PAMDataMatrix // Strings and Variables Variable numfolders,n, subdirs, numfiles, filenum, refnum, thetime // variables String folderlist, filename, name, currentfolder, pathname,flag // strings // Counts number of files in folder NumFiles=ItemsInList(IndexedFile(pathname,-1,".txt")) // # files in folder , specify extensions e.g. ".txt" For(filenum=0;filenum10) // specify minimum file size to load e.g. >10bytes Load_PAM_File(filename, refnum) // calls function to load file // unique function for specific file format AMPMTimeAdjustment(theTime, flag) //LoadPAMFile(pathName, fileName) Wave Temp_PAMDataMatrix0 // add loaded waves to loaded data InsertPoints DimSize(PAMDataMatrix,0),DimSize(Temp_PAMDataMatrix0,0), PAMDataMatrix PAMDataMatrix[DimSize(PAMDataMatrix,0)-DimSize(Temp_PAMDataMatrix0,0),*][]=Temp_PAMDataMatrix0[p-DimSize(PAMDataMatrix,0)+DimSize(Temp_PAMDataMatrix0,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_PAMDataMatrix0 // Do additional analytsis on PAM data ProcessPAM() // adds a time wave End Function Load_PAM_File(filename, refnum) // load single PAM file String filename Variable refnum String columnInfoStr String pathName // Name of an Igor symbolic path or "". columnInfoStr = "N=DateAndTime,F=8;" print "Loading: " + filename loadwave/v={"/: \t", "", 1,1}/q/a/n=Temp_PAMDataMatrix/m/o/j/k=1/l={0,0,0,0,0} filename // loads PAM data as a matrix //LoadWave /J /Q /L={0,1,0,0,1} /V={"/: \t","",0,0} /A /O /B=columninfostr/R={English, 1, 2, 1, 1, "Month/DayofMonth/Year", 40} /P=$pathName fileName End Menu "Load Waves" "Load PAM File...", Load_PAM_File("", "") End // AMPMTimeAdjustment(theTime, flag) // Returns the necessary adjustment in seconds to convert a time from AM/PM representation // to 24 hour representation. Function AMPMTimeAdjustment(theTime, flag) Variable theTime String flag // Must be either "a" or "p" Variable adjustment = 0 Variable secondsIn12Hours = 43200 if (CmpStr(flag, "a") == 0) // AM: If the hour is 12:xx, subtract seconds in 12 hours if (theTime >= secondsIn12Hours) adjustment = -secondsIn12Hours endif else // PM: Adds 12 hours unless hour is 12:xx. if (theTime < secondsIn12Hours) adjustment = secondsIn12Hours endif endif return adjustment End Function LoadPAMFile(pathName, fileName) String pathName // Name of an Igor symbolic path or "". String fileName // Name of file or full path to file. // First get a valid reference to a file. if ((strlen(pathName)==0) || (strlen(fileName)==0)) // Display dialog looking for file. Variable refNum Open/D/R/F="*.txt"/P=$pathName refNum as fileName fileName = S_fileName // S_fileName is set by Open/D if (strlen(fileName) == 0) // User cancelled? return -1 endif endif String columnInfoStr String delimiters // First load the date/time column delimiters = "\t" columnInfoStr = "N=DateAndTime,F=8;" // Load as date/time LoadWave /J /Q /L={0,1,0,0,1} /V={delimiters,"",0,0} /A /O /B=columnInfoStr /R={English, 1, 2, 1, 1, "Month/DayofMonth/Year", 40} /P=$pathName fileName Wave DateAndTime // Next load the AM/PM column delimiters = "\t" + " " // Need space so that the AM/PM column will be taken as distinct from the preceding time column columnInfoStr = "N='Date',F=6;" // Skip first column (date) columnInfoStr += "N='Time',F=7;" // Skip first column (time) columnInfoStr += "N=AMPM,F=-2;" // Load as text LoadWave /J /Q /L={0,1,0,2,1} /V={delimiters,"",0,0} /A /O /B=columnInfoStr /P=$pathName fileName Wave/T AMPM // Account for AM/PM affect on time DateAndTime += AMPMTimeAdjustment(DateAndTime, AMPM) KillWaves/Z AMPM // This is no longer needed // Finally load the rest of the columns as a matrix delimiters = "\t" // We will treat everything up to the first tab as text to easily skip it columnInfoStr = "N='_skip_',F=-2;" // Treat as text columnInfoStr += "N=PAMDataMatrix,F=0;" // Load as numeric LoadWave /J /Q /M /L={0,1,0,1,0} /V={delimiters,"",0,0} /A /O /B=columnInfoStr /P=$pathName fileName Wave PAMDataMatrix Printf "Loaded PAM data from \"%s\"\r", fileName Edit DateAndTime, PAMDataMatrix ModifyTable format(DateAndTime)=8, width(DateAndTime)=160 return 0 // Success End Function ProcessPAM() // Additional processing of PAM data Wave PAMDataMatrix Make/o/d/n=(DimSize(PAMDataMatrix,0)) PAMTime SetScale d,0,0,"dat" PAMTime PAMTime=Date2Secs(PAMDataMatrix[p][2],PAMDataMatrix[p][0],PAMDataMatrix[p][1])+PAMDataMatrix[p][3]*3600+PAMDataMatrix[p][4]*60+PAMDataMatrix[P][5] End