#pragma rtGlobals=1 // Use modern global access method. #include "specMore" #include "spec" Menu "Macros" "Bin Range of Laserscans",BinRangeOfScans(NaN,"") "Squeeze multiple laserscans",SqueezeHorizOffsets(NaN) End Function SqueezeHorizOffsets(timeSpace) Variable timeSpace // =10 if (timeSpace<0 || numtype(timeSpace)) timeSpace = 10 Prompt timeSpace, "time between each laserscan (sec)" DoPrompt "give time",timeSpace if (V_flag) return Nan endif endif String traceList = TraceNameList("",";",1) Variable N = ItemsInList(traceList) Variable i,j String traceNameStr Make/N=(N)/O timeStarts__,timeEnds__ timeStarts__ = NaN timeEnds__ = NaN // first loop through the speculars to fill list of starting times for (i=0,j=0;i=0) // binning is present Variable binning=str2num(specComment[i+9,i+20]) if (binning>1) String binStr="binning="+num2istr(binning)+";" prependNote(Io,binStr) prependNote(Time_,binStr) prependNote(Det_bot,binStr) if (exists("Det_top")==1) // a dual detector scan prependNote(Det_top,binStr) endif endif endif endif Wave Det_bot=Det_bot Wave Det_top=Det_top Variable filterTrans=specInfo(scanNum,"filterTrans") filterTrans = numtype(filterTrans) ? 1 : filterTrans if (exists("Det_top")==1) // a dual detector scan if (remakeNorm) Duplicate/O Io specular,offspec specular = Det_bot / Io / filterTrans offspec = Det_top / Io / filterTrans endif AppendToGraph specular vs Time_ AppendToGraph offspec vs Time_ else if (remakeNorm) Duplicate/O Io sig sig = Det_bot / Io / filterTrans endif AppendToGraph sig vs Time_ endif if (exists("Trigger")==1) if (remakeNorm) Wave Trigger=Trigger if (abs(sum(Trigger)-1)>0.2) // did not get just 1 laser pulse String str sprintf str,"scan #%d in '%s' has %d laser pulses",scanNum,fileName,sum(Trigger) print str if (!quiet) DoAlert 0, str else beep endif endif Duplicate/O Trigger laserShots laserShots = Trigger ? Trigger/2 : NaN endif AppendToGraph lasershots vs Time_ endif LaserStyle(!quiet) SetScale d 0,0,"sec", Time_ SetDataFolder fldrSav End //Proc Fix_LoadLaserScan(scanNum,fileName,path,overlay) // // fixes up a laser scan, reads it in if necessary // Variable scanNum=-1 // spec scan number // Prompt scanNum, "scan number (if < 0, you will get a list choices)" // String fileName=StrVarOrDefault("root:specDefaultFile","") // String path=StrVarOrDefault("root:specDefaultPath","raw") // Prompt path, "path for raw data", popup, PathList("*", ";", "") // String overlay="new" // Prompt overlay, "new plot", popup "new;append;" // Silent 1 // // String fldrSav= GetDataFolder(1) // if (scanNum<1) // String/G temp__list_ = GetListOfLaserscans(fileName,path,";") // ChooseScanNum() // scanNum = str2num(temp__list_) // KillStrings/Z temp__list_ // fileName = root:specDefaultFile // path = root:specDefaultPath // endif // // String folderName = ":spec"+num2istr(scanNum) // // if (!DataFolderExists(folderName)) // no data, read it in // if (exists("root:Packages:spec:extraProcess")==2) //// NVAR extraProcess=root:Packages:spec:extraProcess // Variable extraOld = root:Packages:spec:extraProcess // root:Packages:spec:extraProcess=0 // specRead(fileName,scanNum,path) // root:Packages:spec:extraProcess=extraOld // else // specRead(fileName,scanNum,path) // endif // endif // if (!DataFolderExists(folderName)) // data alredy read in, remove it and read again // DoAlert 0, "data folder '"+folderName+"', not found" // return // endif // SetDataFolder folderName // if (numpnts(Io)<1) // no data, so stop here // SetDataFolder fldrSav // DoAlert 0, "Aborting, scan found, but zero length data" // return // endif // // if ((exists("specular")==1) %| (exists("sig")==1)) // already done, repeat? // DoAlert 1, "remake normalized waves?" // if (V_Flag!=1) // SetDataFolder fldrSav // DoAlert 0, "Aborting" // return // endif // endif // Variable filterTrans=specInfo(scanNum,"filterTrans") // filterTrans = numtype(filterTrans) ? 1 : filterTrans // if (cmpstr("append",overlay)) // a new graph, create the graph window // Display // String gname="Graph_Laser"+num2istr(scanNum) // if (!exists(gname) && strlen(WinList(gname,"",""))<1) // DoWindow/C $gname // endif // endif // // // if binned, put binning into wave note // if (exists("specComment")==2) // Variable i = strsearch(specComment,"binned by ",0) // if (i>=0) // binning is present // Variable binning=str2num(specComment[i+9,i+20]) // if (binning>1) // String binStr="binning="+num2istr(binning)+";" // prependNote(Io,binStr) // prependNote(Time_,binStr) // prependNote(Det_bot,binStr) // if (exists("Det_top")==1) // a dual detector scan // prependNote(Det_top,binStr) // endif // endif // endif // endif // // if (exists("Det_top")==1) // a dual detector scan // duplicate/O Io specular,offspec // specular = Det_bot / Io / filterTrans // offspec = Det_top / Io / filterTrans // AppendToGraph specular vs Time_ // AppendToGraph offspec vs Time_ // else // duplicate/O Io sig // sig = Det_bot / Io / filterTrans // AppendToGraph sig vs Time_ // endif // LaserStyle_() // SetScale d 0,0,"sec", Time_ // SetDataFolder fldrSav //EndMacro //Proc ChooseScanNum(scanNum) // Variable scanNum // Prompt scanNum,"laserscan number", popup, :temp__list_ // Silent 1 // :temp__list_ = StringFromList(scanNum-1, :temp__list_ ) //EndMacro Function prependNote(wav,nStr) // prepend a string to a wave note, just return is additional part is empty Wave wav // wave String nStr // string to prepend to wave note if (strlen(nStr)<1) return 1 endif String noteStr=note(wav) // save current wavenote Note/K wav // clear wavenote Note wav, nStr+noteStr End Function/T GetListOfLaserscans(fileName,path,sep) // get scan number for laserscans in a spec file String fileName String path String sep // separator, defaults to semicolon sep = SelectString(strlen(sep),";",sep) Variable fileVar // file ref number Variable i,j Variable V_flag String scanList="",posList Open /R/P=$path/M="spec data file"/Z fileVar as fileName if (V_flag) Open /R/M="spec data file" fileVar as fileName endif FStatus(fileVar) if (exists("root:specDefaultFile")!=2) String /G root:specDefaultFile endif String/G root:specDefaultFile = S_fileName if (exists("root:specDefaultPath")!=2) String /G root:specDefaultPath endif String/G root:specDefaultPath = path posList = ListPosOfLineTypes(fileVar," laserscan ") if (strlen(posList)<1) return "" endif String line=" " line = PadString(line, 80, 0) i = 0 Variable N=ItemsInList(posList) do FSetPos fileVar, str2num(StringFromList(i, posList))-20 FBinRead fileVar, line j = strsearch(line, "#S ", 0)+2 if (j>=0) scanList += num2istr(str2num(line[j,j+10]))+sep endif i += 1 while(i=5.01) // ModifyGraph gfRelSize=4 ModifyGraph gfMult=130 endif ModifyGraph/Z tick=2, minor=1, standoff=0 ModifyGraph lowTrip=0.001 ModifyGraph/Z mirror(bottom)=1 ModifyGraph/Z mirror(left)=1 ModifyGraph/Z rgb[0]=(0,0,62000) Variable i=0 String wname, wlist wlist = TraceNameList("", ";", 1) do wname = StringFromList(i, wlist) if (stringmatch(wname,"specularBT*")) ModifyGraph rgb($wname)=(0,45000,0) elseif (stringmatch(wname,"specular*")) ModifyGraph/Z rgb($wname)=(0,0,62000) endif if (stringmatch(wname,"offspec*")) ModifyGraph/Z rgb($wname)=(65535,0,0) endif if (stringmatch(wname,"laserShots*")) ModifyGraph/Z mode($wname)=3, marker($wname)=29, rgb($wname)=(0,52224,0), msize($wname)=3 endif i += 1 while(strlen(wname)>0) Label left "detector / I\\Bo\\M";DelayUpdate Label bottom "time (\\U)" SetAxis/A/E=1 left String str=GetDataFolder(0) Variable scanNum=0 if (!cmpstr("spec",str[0,3])) // can decode scan number from current folder scanNum = str2num(str[4,inf]) endif String textStr = "" // String textStr = "Escete ?, " if (exists("specComment2")==2) SVAR specComment2=specComment2 textStr += specComment2+"\r" endif if (exists("specComment1")==2) SVAR specComment1=specComment1 textStr += specComment1+"\r" endif if (exists("specComment")==2) SVAR specComment=specComment textStr += specComment+"\r" endif textStr += "\\Z12" if (exists("timeWritten")==2) SVAR timeWritten=timeWritten textStr += timeWritten else if (exists("specCommand")==2) SVAR specCommand=specCommand i = strsearch(specCommand," #D ",0) if (i>0) if (char2num(specCommand[i+3])==32) // remove any leading space i += 1 endif textStr += specCommand[i+3,inf] else textStr += specCommand endif endif endif if (scanNum>0) textStr += ", #"+num2istr(scanNum) endif textStr += "\\M\r" Variable temp = specInfo(scanNum,"temperature") if (!numtype(temp) && temp>0) textStr += "T\\BTC\\M = "+num2str(temp)+"¡ C" else textStr += "T\\BTC\\M = ???¡ C" endif textStr += ", " temp = GetTxray(scanNum,askT) if (!numtype(temp) && temp>0) textStr += "T\\Bx-ray\\M = "+num2str(temp)+"¡ C" else textStr += "T\\Bx-ray\\M = ???¡ C" endif Wave wav = $StringFromList(0, wlist) if (WaveExists(wav)) str = StringByKey("DATAFILE", note(wav),"=") if (strlen(str)>0) textStr = textStr +"\r\\Z12file = "+str+"\\M" endif endif Textbox/C/N=text0/F=0/S=3 textStr End Function BinRangeOfScans(binTime,range) Variable binTime // delta time for binning, ie combine bins up to a time of binTime String range // range of scans to bin up String command="" if (!(binTime>0) || strlen(range)<=0) binTime = !(binTime>0) ? 0.1 : binTime Prompt binTime, "bin together points within this time (sec)" Prompt range,"range of scans to process" DoPrompt "bin up",binTime,range if (V_flag) return 1 endif sprintf command, "BinRangeOfScans(%g,\"%s\")",binTime,range print command endif if (!(binTime>0) || strlen(range)<=0) DoAlert 0, "ERROR, "+command endif Variable scanNum String fldr, wName, sy1,sy2,sio, twName,trigName for(scanNum=NextInRange(range,-Inf);!numtype(scanNum);scanNum = NextInRange(range,scanNum)) fldr = "root:raw:spec"+num2istr(scanNum)+":" wName = fldr+"Time_" if (exists(wName)==1) Wave tw=$wName twName = BinUpNonUniform(binTime,tw,tw,1,0) else DoAlert 0, "could not find time wave, "+wName continue endif wName = fldr+"Det_bot" if (exists(wName)==1) Wave sig=$wName sy1=BinUpNonUniform(binTime,tw,sig,0,0) endif wName = fldr+"Det_top" if (exists(wName)==1) Wave sig=$wName sy2=BinUpNonUniform(binTime,tw,sig,0,0) endif wName = fldr+"I0" if (exists(wName)==1) Wave sig=$wName sio=BinUpNonUniform(binTime,tw,sig,0,0) endif wName = fldr+"Trigger" if (exists(wName)==1) Wave sig=$wName trigName = BinUpNonUniform(binTime,tw,sig,0,0) endif Wave y1=$sy1, y2=$sy2, io=$sio if (WaveExists(y1) && WaveExists(y2) && WaveExists(io)) SVAR xAxisName=$(fldr+"xAxisName") xAxisName = twName wName = fldr+"specular" Duplicate/O y1 $wName Wave sig=$wName sig = y1/io wName = fldr+"offspec" Duplicate/O y2 $wName Wave sig=$wName sig = y2/io endif Wave trigW = $trigName if (WaveExists(trigW)) // re-create laserShots[] if Trigger present wName = fldr+"laserShots" Duplicate/O trigW $wName Wave laserShots=$wName laserShots = trigW ? trigW/2 : NaN endif endfor End Static Function/S BinUpNonUniform(binTime,tw,sig,hist,unique) Variable binTime // delta time for binning, ie combine bins up to a time of binTime Wave tw // wave of times, the start time for each bin Wave sig // signal to be binned (this can be the same as tw) Variable hist // flag, give first value in sig as binned value, other wise sum. Use hist=1 for the time wave, =0 for counts Variable unique // if true, make name unique, otherwise overwrite with standard name if (!(binTime>0)) DoAlert 0, "BinUpNonUniform() has a delta time = "+num2str(binTime)+", quitting" return "" endif Variable N=min(numpnts(sig),numpnts(tw)) // number of points in unbinned wave String wName = GetWavesDataFolder(sig,2)+"Bin" if (unique && exists(wName)==1) // need a unique name for wName wName = GetWavesDataFolder(sig,1)+UniqueName(NameOfWave(sig)+"Bin",1,0) endif Duplicate/O sig, $wName Wave bin=$wName bin = NaN Variable m // number of points in binned wave Variable i,i0,i1 i0 = 0 i1 = i0 m = 0 do for (i1=i0;((tw[i1]-tw[i0])