#pragma rtGlobals=1 // Use modern global access method. #pragma IgorVersion = 6.2 #pragma version = 4.0 #include #include #include #include #include // written by Matt Sfeir, Brookhaven National Laboratory // msfeir@bnl.gov // v.4 beta 3 May 9. 2011 // Build menu items Menu "Load Waves" "Load Helios TA Data...", ProcessTA() End Menu "TA Analysis" "Load Helios TA Data...", OpenTA() "-" // "Inspect Image Data", ImageHookGen() // "Kill Data Inspector", KillHookGen() // "-" "Extract Kinetics", ExtractKin() "Extract Spectra", ExtractSpec() "-" "Time Zero Correction", T0ImCorr() "Scattered Light Correction", DisplayIntBkgdControlPanel() "-" "Generate Progressive Time Axis", ExpTimeAxis() End /////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////// // For debugging. Remove Later. Function KillHookGen() //DoWindow/K kinetics0 //DoWindow/K spectra0 DoWindow/K kinetics DoWindow/K spectra KillDataFolder root:Packages:InspectData return 0 End /////////////////////////////////////////////////////////////////////////////////////////////// // Modify Open File Dialog to break if cancelled Function OpenTA() Variable refNum String message = "Select a file" String outputPath, fileHandle, wName, wName2 String fileFilters = "Helios TA Data Files (*.csv):.csv;" fileFilters += "All Files:.*;" Open /D /R /F=fileFilters /M=message refNum outputPath = S_fileName printf "%s\r" outputPath fileHandle = ParseFilePath(5, outputPath, ":", 0,0) fileHandle = ParseFilePath(3, outputPath, ":", 0,0) printf "%s\r" fileHandle Variable lengthTest = strlen(fileHandle) // shorten string to 22 characters to satisfy Igor constraints on wave name length // max is 31. start with 22 so that we can append suffix. fileHandle = CleanUpName(fileHandle, 0) if(lengthTest >= 22) Variable i = lengthTest - 22 Variable j=0 do fileHandle = RemoveEnding(fileHandle) j+=1 while(j <= i) else fileHandle = fileHandle endif LoadWave/J/M/U={0,2,0,2}/D/A=$fileHandle/K=0 outputPath Wave w =outputPath // WaveExists 1 valid 0 invalid wName = fileHandle +"0" Variable b=0 if (WaveExists ($wName) == 1) wName2 = fileHandle + num2str(b+1) if (WaveExists ($wName2) == 1) wName = wName2 b += 1 else wName = fileHandle + num2str(b) endif endif Print wName Variable cancelTest = cmpstr(outputPath, "") if (cancelTest == 0) Print "Open file cancelled." else ProcessTA(wName) endif End // Loads waves and processes them for plotting // Called by OpenTA() Function ProcessTA(wName) // CMD - . aborts the procedure String wName Duplicate $wName w String RPName = "RP_" + wName String CPName = "CP_" + wName Wave RP =RPName Wave CP =CPName Duplicate $RPName RP Duplicate $CPName CP // Wave w,RP,CP Variable m, n, pp, qq, r // remove NaNs and Infs. Replace with zeros. m = Dimsize(w,0) // numer of rows // printf "%f\r" m n = Dimsize(w,1) // number of columns Make/N=(m,n) /D/O Zmat Zmat= (numtype(w) == 1) ? 0 : w Zmat= (numtype(Zmat) == 2) ? 0 : Zmat Make/N=(m) /D/O ContX ContX= (numtype(RP) == 1) ? 0 : RP ContX= (numtype(ContX) == 2) ? 0 : ContX // remove extra rows - often contain bad data // re-write to handle arbitrary sized wavelength dimension while scaling is monotonic, increasing qq = Dimsize(ContX,0) Variable aa = qq Do Redimension /N=(aa) ContX Redimension /N=(aa,-1) Zmat aa-=1 While(ContX[aa] <= ContX [aa-1]) qq = Dimsize(ContX,0) // Print qq // continue with formatting m = Dimsize(Zmat,0) // numer of rows n = Dimsize(Zmat,1) // number of columns pp = m*n Make/N=(n) /D/O ContY ContY= (numtype(CP) == 1) ? 0 : CP ContY= (numtype(ContY) == 2) ? 0 : ContY Make/N=(pp) /D/O tempXwave Make/N=(pp) /D/O tempYwave Make/N=(pp) /D/O tempZwave Make/N=(m+1) /D/O ImageX Make/N=(n+1) /D/O ImageY Make/N=(M,N,3) /O ParametricWave // create new processed row, column positions and z matrix // can be used to generate contour plot Variable i,j i=0 do j=0 do tempXwave[j+m*i]=ContX[j] tempYwave[j+m*i]=ContY[floor((j+m*i)/m)] tempZwave[j+m*i]=Zmat[j][i] j +=1 while (j <=m) i +=1 while (i <= n) Concatenate/O {tempXwave, tempYwave, tempZwave}, wScatterMatrix KillWaves tempXwave, tempYwave, tempZwave // Format for Image Plot // Create x and y wave for image. Points define start and end of pixel positions, not center // so need to generate N+1 points from N. // Add point at [-1] at same distance from [0] as [1] // and shift by [0] - [1] distance OR pick midpoint between consecutive points // assuming smallest increment at start of wave Variable g, h ImageX[0]= ContX[0]-((ContX[1]-ContX[0])/2) // g = 0 // do // ImageX[g+1]=ContX[g]+((ContX[1]-ContX[0])/2) // g += 1 // while (g <= m) g=1 do ImageX[g] = (ContX[g] + ContX[g-1])/2 g += 1 while (g < m) ImageX[m] = ContX[m-1] + ((ContX[m-1] - ContX[m-2])/2) ImageY[0]= ContY[0]-((ContY[1]-ContY[0])/2) // h=0 // do // ImageY[h+1]=ContY[h]+((ContY[1]-ContY[0])/2) // h += 1 // while (h <= n) h=1 do ImageY[h] = (ContY[h] + ContY[h-1])/2 h+= 1 while (h < n) ImageY[n] = ContY[n-1] + ((ContY[n-1] - ContY[n-2])/2) // generate Parametic data. // used for uneven spacings in surface plots Variable k,l k=0 do l=0 do ParametricWave[k][l][0]=ContX[k] ParametricWave[k][l][1]=ContY[l] ParametricWave[k][l][2]=Zmat[k][l] l +=1 while (l <= n) k +=1 while (k <= m) // clean up wave names // String ZmatName = NameOfWave(w) + "_zmat" String ZmatName = wName + "_zmat" Duplicate/O Zmat, $ZmatName KillWaves Zmat // String ContXName = NameOfWave(w) + "_xc" String ContXName = wName + "_xc" Duplicate/O ContX, $ContXName KillWaves ContX // String ContYName = NameOfWave(w) + "_yc" String ContYName = wName + "_yc" Duplicate/O ContY, $ContYName KillWaves ContY // String ImageXName = NameOfWave(w) + "_xim" String ImageXName = wName + "_xim" Duplicate/O ImageX, $ImageXName KillWaves ImageX // String ImageYName = NameOfWave(w) + "_yim" String ImageYName = wName + "_yim" Duplicate/O ImageY, $ImageYName KillWaves ImageY // String ScatMatName = NameOfWave(w) + "_sca" String ScatMatName = wName + "_sca" Duplicate/O wScatterMatrix, $ScatMatName KillWaves wScatterMatrix // String ParaName = NameOfWave(w) + "_par" String ParaName = wName + "_par" Duplicate/O ParametricWave, $ParaName KillWaves ParametricWave, w, RP, CP // Generate default image Display;AppendImage $ZmatName vs {$ImageXName,$ImageYName};DelayUpdate ModifyImage $ZmatName ctab= {*,*,Rainbow,0} ModifyImage $ZmatName ctabAutoscale=3,lookup= $"" ShowInfo GetWindow kwTopWin wtitle String imTitle = S_Value imTitle = RemoveEnding(imTitle, ":") Cursor/I/H=1 /W=$imTitle A $ZmatName 1,1 Cursor/M/H=1 B // if inspector is already enabled on other images // enable by default on subsequent images //DoWindow kinetics0 // DoWindow kinetics // if (V_Flag == 1) // SetWindow $imTitle, hook(MyHook)=MyWindowHook // else // return 0 // endif // DoUpdate ImageHookGen() return 0 End ///////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////// // Inspect Image Data section // Apply Window Hook Calls to existing image Function ImageHookGen() // No need to build new image // Just apply window hook function to top window // first make sure this is an image String ImTest = ImageInfo("","",0) if(cmpstr(Imtest,"",0) == 0) return 0 // Print "Not an image." else GetWindow kwTopWin, wavelist // don't forget to declare wave Wave/T wl = W_WaveList // figure out which one is z // not the most elegant solution String Zregex = "(.*?)(zmat|zibg)" String ZMatName String S00 = wl[0][0] String S10 = wl[1][0] String S20 = wl[2][0] if(GrepString(S00, Zregex) == 1) ZMatName = S00 elseif(GrepString(S10, Zregex) == 1) ZMatName = S10 elseif(GrepString(S20, Zregex) == 1) ZMatName = S20 else Print "No image found." endif Print "Z = " + ZMatNAme GetWindow kwTopWin, wtitle String imTitle = S_Value // Cursor/I A $ZMatName 1,1 // add call for Window Hook - testing phase SetWindow kwTopWin, hook(MyHook)=MyWindowHook // build window for displaying kinetics String base String suffix String regex = "(.*?)(zmat|zibg)" SplitString /E=(regex) ZMatName, base, suffix String xwName String ywName if(CmpStr(zmatName,"")==0) xwName = "NewXWave" ywName = "NewYWave" else xwName = base + "xc" ywName = base + "yc" endif // first data to display for kinetics Variable xpos, lambda xpos = pcsr(A) lambda = hcsr(A) // first data to display for spectra Variable ypos, stime ypos = qcsr(A) stime = vcsr(A) // build kinetics graph Wave kM = $ZMatName // Wave lM = $xwName // generate target wave for kinetic information // named appropriately with the wavelength Variable m,n m = Dimsize(kM,0) // numer of rows n = Dimsize(kM,1) // number of columns // name with generic name so it can be continuously overwritten // can be copied later with appropriate command // String kWaveName = "kinetics" // String sWaveName = "spectra" String kWaveName = "kineticsA" String sWaveName = "spectraA" // we do need the right time wave though . . . String tWave if(CmpStr(base,"")==0) tWave = "EmptyTimeWave" else tWave = base + "yc" endif Make/D/O/N=(n) $kWaveName Wave w = $kWaveName // . . . and lambda wave String sWave if(CmpStr(base,"")==0) sWave = "EmptyLamWave" else sWave = base + "xc" endif Make/D/O/N=(m) $sWaveName Wave v = $sWaveName // use built-in indexing capabilities to // extract a row // I find this implementation to be partuclarly confusing w = kM[xpos] [p] v = kM[p][ypos] // create new graph if it doesn't exist // DoWindow/F kinetics0 // if (V_Flag == 0) // Display/K=2/N=kinetics w vs $tWave as "kinetics" // endif // DoUpdate // DoWindow/F spectra0 // if (V_Flag == 0) // Display/K=2/N=spectra v vs $sWave as "spectra" // endif // DoUpdate // break out graphing function so that the panel can be modified // first create global variables if they don't exist if(DataFolderExists("root:Packages:InspectData") == 0) NewDataFolder/O root:Packages:InspectData endif String/G root:Packages:InspectData:gMessagek= "" String/G root:Packages:InspectData:gMessagekB= "" String/G root:Packages:InspectData:gMessageki= "" String/G root:Packages:InspectData:gMessageXSck= "" String/G root:Packages:InspectData:gMessageYSck= "" Variable/G root:Packages:InspectData:gCursB= 0 String/G root:Packages:InspectData:gMessages= "" String/G root:Packages:InspectData:gMessagesB= "" String/G root:Packages:InspectData:gMessagesi= "" String/G root:Packages:InspectData:gMessageXScs= "" String/G root:Packages:InspectData:gMessageYScs= "" // next fill in string values SVAR gMessagek = root:Packages:InspectData:gMessagek SVAR gMessagekB = root:Packages:InspectData:gMessagekB SVAR gMessageki = root:Packages:InspectData:gMessageki gMessagek = num2str(lambda) gMessageki = ZMatName NVAR gCursB = root:Packages:InspectData:gCursB SVAR gMessages = root:Packages:InspectData:gMessages SVAR gMessagesB = root:Packages:InspectData:gMessagesB SVAR gMessagesi = root:Packages:InspectData:gMessagesi gMessages = num2str(stime) gMessagesi = ZMatName // make waves for cursor B anyway // same size as A String kWaveNameB = "kineticsB" String sWaveNameB = "spectraB" Make/D/O/N=(n) $kWaveNameB Make/D/O/N=(m) $sWaveNameB Wave wB = $kWaveNameB Wave vB = $sWaveNameB Variable xposB, lambdaB Variable yposB, stimeB // initialize properly if B is on graph Variable bExists= strlen(CsrInfo(B)) > 0 if (bExists == 1) gCursB = 1 // first data to display for kinetics xposB = pcsr(B) lambdaB = hcsr(B) gMessagekB= num2str(lambdaB) // first data to display for spectra yposB = qcsr(B) stimeB = vcsr(B) gMessagesB = num2str(stimeB) wB = kM[xposB] [p] vB = kM[p][yposB] else gCursB = 0 gMessagekB = "" gMessagesB = "" endif // now build graphs InspectGraphK(kWaveName, tWave, "kinetics") InspectGraphS(sWaveName, sWave, "spectra") // do these only if cursor B is already on the graph if (bExists == 1) InspectGraphK(kWaveNameB, tWave, "kinetics") InspectGraphS(sWaveNameB, sWave, "spectra") endif return 0 endif End Function InspectGraphK(ywave, xwave, wvname) String ywave, xwave, wvname //String wwname = wvname + "0" String wwname = wvname // Print wwname // make sure proper folder exists for global variables // do not switch to this folder SVAR gMessagek = root:Packages:InspectData:gMessagek SVAR gMessageki = root:Packages:InspectData:gMessageki SVAR gMessagekB = root:Packages:InspectData:gMessagekB NVAR gCursB = root:Packages:InspectData:gCursB SVAR gMessageXSck = root:Packages:InspectData:gMessageXSck SVAR gMessageYSck = root:Packages:InspectData:gMessageYSck String grState // create new graph if it doesn't exist // this will only add the first trace that is called (A cursor) // we need to incorporate logic that will add the second trace under the right conditions DoWindow/F $wwname if (V_Flag == 0) Display/W=(505,42,1068,414)/K=2/N=$wvname $ywave vs $xwave as wvname ControlBar 50 SetVariable msg,pos={12,10},size={120,17},title="A Wavelength " SetVariable msg,limits={-Inf,Inf,1},value= root:Packages:InspectData:gMessagek SetVariable msg5,pos={142,10},size={120,17},fcolor=(65535,0,0),title="B Wavelength " SetVariable msg5,limits={-Inf,Inf,1},value= gMessagekB SetVariable msg2,pos={280,10},size={230,17},title="Image " SetVariable msg2,limits={-Inf,Inf,1},value= root:Packages:InspectData:gMessageki SetVariable msg3,pos={12,30},size={250,17},title="X Scaling " SetVariable msg3,limits={-Inf,Inf,1},value= root:Packages:InspectData:gMessageXSck SetVariable msg4,pos={280,30},size={230,17},title="Y Scaling " SetVariable msg4,limits={-Inf,Inf,1},value= root:Packages:InspectData:gMessageYSck ModifyGraph/Z rgb[0] = (0,0,0) ModifyGraph/Z rgb[1] = (65535,0,0) else grState = TraceNameList("",":",1) // first ask if both traces are already on the graph // then we do nothing if(CmpStr(grState, "kineticsA:kineticsB:")== 0) return 0 // next ask if the wave on which we are running this function already exists on the graph elseif(CmpStr(grState, ywave + ":") == 0) return 0 // if not, append to graph else AppendToGraph $ywave vs $xwave endif endif // SetWindow kwTopWin,hook(MyHook)=MyWindowHook //hook=SimpleInfoHook,hookevents=3 SetWindow $wwname,hook(MyHook)=MyWindowHook //hook=SimpleInfoHook,hookevents=3 // SetWindow kwTopWin,hook=MyWindowHook DoUpdate End Function InspectGraphS(ywave, xwave, wvname) String ywave, xwave, wvname //String wwname = wvname + "0" String wwname = wvname // make sure proper folder exists for global variables // do not switch to this folder if(DataFolderExists("root:Packages:InspectData") == 0) NewDataFolder/O root:Packages:InspectData endif SVAR gMessages = root:Packages:InspectData:gMessages SVAR gMessagesi = root:Packages:InspectData:gMessagesi SVAR gMessageXScs = root:Packages:InspectData:gMessageXScs SVAR gMessageYScs = root:Packages:InspectData:gMessageYScs String grState // create new graph if it doesn't exist DoWindow/F $wwname if (V_Flag == 0) Display/W=(505,442,1068,814)/K=2/N=$wvname $ywave vs $xwave as wvname ControlBar 50 SetVariable msg,pos={12,10},size={120,17},title="A Time " SetVariable msg,limits={-Inf,Inf,1},value= root:Packages:InspectData:gMessages SetVariable msg5,pos={142,10},size={120,17},fcolor=(65535,0,0),title="B Time " SetVariable msg5,limits={-Inf,Inf,1},value= root:Packages:InspectData:gMessagesB SetVariable msg2,pos={280,10},size={230,17},title="Image " SetVariable msg2,limits={-Inf,Inf,1},value= root:Packages:InspectData:gMessagesi SetVariable msg3,pos={12,30},size={250,17},title="X Scaling " SetVariable msg3,limits={-Inf,Inf,1},value= root:Packages:InspectData:gMessageXScs SetVariable msg4,pos={280,30},size={230,17},title="Y Scaling " SetVariable msg4,limits={-Inf,Inf,1},value= root:Packages:InspectData:gMessageYScs ModifyGraph/Z rgb[0] = (0,0,0) ModifyGraph/Z rgb[1] = (65535,0,0) else grState = TraceNameList("",":",1) if(CmpStr(grState, "spectraA:spectraB:")== 0) return 0 elseif(CmpStr(grState, ywave + ":") == 0) return 0 else AppendToGraph $ywave vs $xwave endif endif SetWindow $wwname,hook(MyHook)=MyWindowHook DoUpdate End // begin Window Hook implementation // testing phase Function MyWindowHook(s) STRUCT WMWinHookStruct &s Variable hookResult = 0 // Wave wk = kinetics // Wave ws = spectra Wave wk = kineticsA Wave ws = spectraA Wave wkB = kineticsB Wave wsB = spectraB // do this when procedure is called String Zregex = "(.*?)(zmat|zibg)" String ZMatName String S00, S10, S20 GetWindow/Z kwTopWin, wavelist Wave/T wl = W_WaveList // make sure this is an image String ImTest = ImageInfo("","",0) // if((cmpstr(Imtest,"",0) == 0) && (! V_Flag == 0)) if((cmpstr(Imtest,"",0) == 0)) // Print "Not an image." // else // Print "Image" // endif // if(DimSize(wl,0) == 3) // need to switch order of if then statement // comment out return 0 and else to switch back // Print "Not an image." // return 0 else // Wave/T wl = W_WaveList if(Dimsize(wl,0) == 3) S00 = wl[0][0] S10 = wl[1][0] S20 = wl[2][0] else S00 = "" S10 = "" S20 = "" endif if(GrepString(S00, Zregex) == 1) ZMatName = S00 elseif(GrepString(S10, Zregex) == 1) ZMatName = S10 elseif(GrepString(S20, Zregex) == 1) ZMatName = S20 else ZMatName ="" return 0 endif Wave kM = $ZMatName endif // initalize variables for case 0, image window get activated String grtitle String base String suffix String regex = "(.*?)(zmat|zibg)" String tWave, sWave Variable colsize, rowsize, xpos, ypos, lambda, stime Variable xposB, lambdaB Variable yposB, stimeB Variable bExists // add global variable references for the PreserveGraphScaling function PreserveGraphScaling("kinetics","k") PreserveGraphScaling("spectra","s") // what is happening here? // are we resetting the values somehow??? NVAR gvaslk = root:Packages:InspectData:gvaslk NVAR gvasbk = root:Packages:InspectData:gvasbk NVAR gvlmink = root:Packages:InspectData:gvlmink NVAR gvlmaxk = root:Packages:InspectData:gvlmaxk NVAR gvbmink = root:Packages:InspectData:gvbmink NVAR gvbmaxk = root:Packages:InspectData:gvbmaxk //PreserveGraphScaling("spectra0","s") // add global variable references for the PreserveGraphScaling function NVAR gvasls = root:Packages:InspectData:gvasls NVAR gvasbs = root:Packages:InspectData:gvasbs NVAR gvlmins = root:Packages:InspectData:gvlmins NVAR gvlmaxs = root:Packages:InspectData:gvlmaxs NVAR gvbmins = root:Packages:InspectData:gvbmins NVAR gvbmaxs = root:Packages:InspectData:gvbmaxs // global variables for graph messages SVAR gMessagek = root:Packages:InspectData:gMessagek SVAR gMessageki = root:Packages:InspectData:gMessageki SVAR gMessageXSck = root:Packages:InspectData:gMessageXSck SVAR gMessageYSck = root:Packages:InspectData:gMessageYSck SVAR gMessagekB = root:Packages:InspectData:gMessagekB SVAR gMessagesB = root:Packages:InspectData:gMessagesB NVAR gCursB = root:Packages:InspectData:gCursB SVAR gMessages = root:Packages:InspectData:gMessages SVAR gMessagesi = root:Packages:InspectData:gMessagesi SVAR gMessageXScs = root:Packages:InspectData:gMessageXScs SVAR gMessageYScs = root:Packages:InspectData:gMessageYScs // Print gvaslk switch(s.eventcode) // activate window case 0: //Print "case 0" //Print gvaslk //PreserveGraphScaling("kinetics0","k") PreserveGraphScaling("kinetics","k") // update for window hook calls on kinetics or spectra window // just updates control bar fields GetWindow kwTopWin, wtitle grTitle = S_Value // Print grTitle if(CmpStr(grTitle,"kinetics",0) == 0) PreserveGraphScaling("kinetics","k") if(gvaslk == 1) gMessageYSck = num2str(gvlmink) +", "+ num2str(gvlmaxk) else gMessageYSck = "Auto" endif if(gvasbk == 1) gMessageXSck = num2str(gvbmink) +", "+ num2str(gvbmaxk) else gMessageXSck = "Auto" endif hookresult = 1 break endif // do the same for the spectra graph GetWindow kwTopWin, wtitle grTitle = S_Value // Print grTitle if(CmpStr(grTitle,"spectra",0) == 0) PreserveGraphScaling("spectra","s") if(gvasls == 1) gMessageYScs = num2str(gvlmins) +", "+ num2str(gvlmaxs) else gMessageYScs = "Auto" endif if(gvasbs == 1) gMessageXScs = num2str(gvbmins) +", "+ num2str(gvbmaxs) else gMessageXScs = "Auto" endif hookresult = 1 break endif // otherwise, make sure we are operating on the active image GetWindow kwTopWin, wavelist // make this only applicable to images if(cmpstr(Imtest,"",0) == 0) // Print "Not an image." return 0 else S00 = wl[0][0] S10 = wl[1][0] S20 = wl[2][0] if(GrepString(S00, Zregex) == 1) ZMatName = S00 elseif(GrepString(S10, Zregex) == 1) ZMatName = S10 elseif(GrepString(S20, Zregex) == 1) ZMatName = S20 else return 0 // abort endif Wave kM = $ZMatName // else // return 0 // endif // if(DimSize(wl,0) == 3) // S00 = wl[0][0] // S10 = wl[1][0] // S20 = wl[2][0] // if(GrepString(S00, Zregex) == 1) // ZMatName = S00 // elseif(GrepString(S10, Zregex) == 1) // ZMatName = S10 // elseif(GrepString(S20, Zregex) == 1) // ZMatName = S20 // else // Print "No image found." // endif // may need to plot against new time wave if we have switched windows SplitString /E=(regex) ZMatName, base, suffix if(CmpStr(base,"")==0) tWave = "EmptyTimeWave" sWave = "EmptyLamWave" else tWave = base + "yc" sWave = base + "xc" endif // update dimensions of the kinetics wave colsize = Dimsize(kM,1) // numer of columns rowsize = DimSize(kM,0) // number of rows Redimension/N=(colsize) kineticsA Redimension/N=(rowsize) spectraA // re-initialize graph //DoWindow kinetics0 DoWindow kinetics if (V_Flag == 0) return 0 else // RemoveFromGraph/W=kinetics0 kinetics // AppendToGraph/W=kinetics0 kinetics vs $tWave RemoveFromGraph/W=kinetics kineticsA AppendToGraph/W=kinetics kineticsA vs $tWave endif //DoWindow spectra0 DoWindow spectra if (V_Flag == 0) return 0 else // RemoveFromGraph/W=spectra0 spectra // AppendToGraph/W=spectra0 spectra vs $sWave RemoveFromGraph/W=spectra spectraA AppendToGraph/W=spectra spectraA vs $sWave endif xpos = pcsr(A) ypos = qcsr(A) lambda = hcsr(A) stime = vcsr(A) gMessagek = num2str(lambda) gMessageki = ZMatName gMessages = num2str(stime) gMessagesi = ZMatName wk = kM[xpos] [p] ws = kM[p] [ypos] // the cursor calls reset the graph scaling need to fix it here // include temp variable to reset axes back to default Variable gvaslktemp = gvaslk Variable gvasbktemp = gvasbk Variable gvaslstemp = gvasls Variable gvasbstemp = gvasbs Cursor/H=2/W=kinetics A kineticsA ypos Cursor/H=2/W=spectra A spectraA xpos gvaslk = gvaslktemp gvasbk = gvasbktemp gvasls = gvaslstemp gvasbs = gvasbstemp // this is repeated during image operations // also calls setaxis so state of graph is preseved if not autoscaled if(gvaslk == 1) //SetAxis/W=kinetics0 left, gvlmink, gvlmaxk SetAxis/W=kinetics left, gvlmink, gvlmaxk gMessageYSck = num2str(gvlmink) +", "+ num2str(gvlmaxk) else gMessageYSck = "Auto" endif if(gvasbk == 1) //SetAxis/W=kinetics0 bottom, gvbmink, gvbmaxk SetAxis/W=kinetics bottom, gvbmink, gvbmaxk gMessageXSck = num2str(gvbmink) +", "+ num2str(gvbmaxk) else gMessageXSck = "Auto" endif if(gvasls == 1) //SetAxis/W=spectra0 left, gvlmins, gvlmaxs SetAxis/W=spectra left, gvlmins, gvlmaxs gMessageYScs = num2str(gvlmins) +", "+ num2str(gvlmaxs) else gMessageYScs = "Auto" endif if(gvasbs == 1) //SetAxis/W=spectra0 bottom, gvbmins, gvbmaxs SetAxis/W=spectra bottom, gvbmins, gvbmaxs gMessageXScs = num2str(gvbmins) +", "+ num2str(gvbmaxs) else gMessageXScs = "Auto" endif // updates for cursor B bExists= strlen(CsrInfo(B)) > 0 if (bExists == 1) gCursB = 1 Redimension/N=(colsize) kineticsB Redimension/N=(rowsize) spectraB DoWindow kinetics if (V_Flag == 0) return 0 else RemoveFromGraph/Z/W=kinetics kineticsB AppendToGraph/W=kinetics kineticsB vs $tWave endif DoWindow spectra if (V_Flag == 0) return 0 else RemoveFromGraph/Z/W=spectra spectraB AppendToGraph/W=spectra spectraB vs $sWave endif // first data to display for kinetics xposB = pcsr(B) lambdaB = hcsr(B) gMessagekB= num2str(lambdaB) // first data to display for spectra yposB = qcsr(B) stimeB = vcsr(B) gMessagesB = num2str(stimeB) wkB = kM[xposB] [p] wsB = kM[p][yposB] Cursor/H=2/C=(65535,0,0)/W=kinetics B kineticsB yposB Cursor/H=2/C=(65535,0,0)/W=spectra B spectraB xposB else gCursB = 0 gMessagekB = "" gMessagesB = "" RemoveFromGraph/Z/W=kinetics kineticsB RemoveFromGraph/Z/W=spectra spectraB Cursor/K/W=kinetics B Cursor/K/W=spectra B endif ModifyGraph/Z/W=kinetics rgb[0] = (0,0,0) ModifyGraph/Z/W=kinetics rgb[1] = (65535,0,0) ModifyGraph/Z/W=spectra rgb[0] = (0,0,0) ModifyGraph/Z/W=spectra rgb[1] = (65535,0,0) hookresult = 1 break // else // return 0 endif // implement cursor move part // current problem with cursor move - activate seems ok //null string variable on startup case 7: //Print "case 7" //Print "1: " + num2str(gvaslk) // mouse move // Print s.pointnumber // Print s.yPointNumber //PreserveGraphScaling("kinetics0","k") PreserveGraphScaling("kinetics","k") //PreserveGraphScaling("spectra0","s") PreserveGraphScaling("spectra","s") //Print "2: " + num2str(gvaslk) // make sure we are operating on the active image GetWindow kwTopWin, wavelist // make this only applicable to images if(cmpstr(Imtest,"",0) == 0) // Print "Not an image." return 0 else //Print "3: " + num2str(gvaslk) PreserveGraphScaling("kinetics","k") S00 = wl[0][0] S10 = wl[1][0] S20 = wl[2][0] if(GrepString(S00, Zregex) == 1) ZMatName = S00 elseif(GrepString(S10, Zregex) == 1) ZMatName = S10 elseif(GrepString(S20, Zregex) == 1) ZMatName = S20 else return 0 endif Wave kM = $ZMatName SplitString /E=(regex) ZMatName, base, suffix if(CmpStr(base,"")==0) tWave = "EmptyTimeWave" sWave = "EmptyLamWave" else tWave = base + "yc" sWave = base + "xc" endif xpos = pcsr(A) ypos = qcsr(A) wk = kM[xpos] [p] ws = kM[p][ypos] lambda = hcsr(A) gMessagek = num2str(lambda) gMessageki = ZMatName stime = vcsr(A) gMessages = num2str(stime) gMessagesi = ZMatName Cursor/H=2/W=kinetics A kineticsA ypos Cursor/H=2/W=spectra A spectraA xpos if(gvaslk == 1) //SetAxis/W=kinetics0 left, gvlmink, gvlmaxk SetAxis/W=kinetics left, gvlmink, gvlmaxk endif if(gvasbk == 1) //SetAxis/W=kinetics0 bottom, gvbmink, gvbmaxk SetAxis/W=kinetics bottom, gvbmink, gvbmaxk endif if(gvasls == 1) //SetAxis/W=spectra0 left, gvlmins, gvlmaxs SetAxis/W=spectra left, gvlmins, gvlmaxs endif if(gvasbs == 1) //SetAxis/W=spectra0 bottom, gvbmins, gvbmaxs SetAxis/W=spectra bottom, gvbmins, gvbmaxs endif // updates for cursor B // Variable xposB, lambdaB // Variable yposB, stimeB bExists= strlen(CsrInfo(B)) > 0 if (bExists == 1) gCursB = 1 // first data to display for kinetics xposB = pcsr(B) lambdaB = hcsr(B) gMessagekB= num2str(lambdaB) // first data to display for spectra yposB = qcsr(B) stimeB = vcsr(B) gMessagesB = num2str(stimeB) wkB = kM[xposB] [p] wsB = kM[p][yposB] CheckDisplayed/W=kinetics kineticsB if(V_flag == 1) Cursor/H=2/C=(65535,0,0)/W=kinetics B kineticsB yposB // return 0 else AppendToGraph/W=kinetics kineticsB vs $tWave endif CheckDisplayed/W=spectra spectraB if(V_flag == 1) Cursor/H=2/C=(65535,0,0)/W=spectra B spectraB xposB // return 0 else AppendToGraph/W=spectra spectraB vs $sWave endif else gCursB = 0 gMessagekB = "" gMessagesB = "" RemoveFromGraph/Z/W=kinetics kineticsB RemoveFromGraph/Z/W=spectra spectraB Cursor/K/W=kinetics B Cursor/K/W=spectra B endif endif //Print "4: " + num2str(gvaslk) hookresult = 1 break case 8: //Print "case 8" //Print gvaslk // update if we rescale the kinetics graph GetWindow kwTopWin, wtitle grTitle = S_Value if(CmpStr(grTitle,"kinetics",0) == 0) //Print "modified kinetics running" // PreserveGraphScaling("kinetics0","k") PreserveGraphScaling("kinetics","k") if(gvaslk == 1) gMessageYSck = num2str(gvlmink) +", "+ num2str(gvlmaxk) else gMessageYSck = "Auto" endif if(gvasbk == 1) gMessageXSck = num2str(gvbmink) +", "+ num2str(gvbmaxk) else gMessageXSck = "Auto" endif hookresult = 1 break endif if(CmpStr(grTitle,"spectra",0) == 0) //PreserveGraphScaling("spectra0","s") PreserveGraphScaling("spectra","s") if(gvasls == 1) gMessageYScs = num2str(gvlmins) +", "+ num2str(gvlmaxs) else gMessageYScs = "Auto" endif if(gvasbs == 1) gMessageXScs = num2str(gvbmins) +", "+ num2str(gvbmaxs) else gMessageXScs = "Auto" endif // commenting out the following section because it is not shown above and // the kinetics plot is not broken (while spectra is) // bExists= strlen(CsrInfo(B)) > 0 // if (bExists == 1) // gCursB = 1 // RemoveFromGraph/Z/W=kinetics kineticsB // AppendToGraph/W=kinetics kineticsB vs $tWave // RemoveFromGraph/Z/W=spectra spectraB // AppendToGraph/W=spectra spectraB vs $sWave // else // RemoveFromGraph/Z/W=kinetics kineticsB // RemoveFromGraph/Z/W=spectra spectraB // endif // everything was fixed when this code was removed // don't think about it too hard hookresult = 1 break endif endswitch return hookResult End // After a Window Hook call, graph axis limits automatically reset // We want to preserve the axis range as the window is activated // But, we want to preserve autoscaling so that things are easy when // we switch images. Use this function in combination with SetScale Function PreserveGraphScaling(graphname, suffix) // be careful that suffix is less than 25 or so characters String graphname String suffix DoWindow $graphname if (V_Flag == 0) Print "Window doesn't exist" return 0 else // create folder to store global variables which will be accessed // by our window hook functions DFREF saveDFR = GetDataFolderDFR() if(DataFolderExists("root:Packages:InspectData") == 1) SetDataFolder("root:Packages:InspectData") else NewDataFolder/O/S root:Packages:InspectData endif // create global variables for manual or auto // default is autoscale // left axis String vaslname = ":gvasl" + suffix Variable vasl = NumVarOrDefault(vaslname, 0) Variable/G $vaslname = vasl NVAR gvasl = $vaslname // bottom axis String vasbname = ":gvasb" + suffix Variable vasb = NumVarOrDefault(vasbname, 0) Variable/G $vasbname = vasb NVAR gvasb = $vasbname // create global variables for axis limits // left axis String vlminname = ":gvlmin" + suffix Variable vlmin = NumVarOrDefault(vlminname, -1) Variable/G $vlminname = vlmin NVAR gvlmin = $vlminname String vlmaxname = ":gvlmax" + suffix Variable vlmax = NumVarOrDefault(vlmaxname, 1) Variable/G $vlmaxname = vlmax NVAR gvlmax = $vlmaxname // bottom axis String vbminname = ":gvbmin" + suffix Variable vbmin = NumVarOrDefault(vbminname, -1) Variable/G $vbminname = vbmin NVAR gvbmin = $vbminname String vbmaxname = ":gvbmax" + suffix Variable vbmax = NumVarOrDefault(vbmaxname, 1) Variable/G $vbmaxname = vbmax NVAR gvbmax = $vbmaxname //NVAR gvaslk //Print gvaslk // test for autoscaling // variables created 1 for manual, 0 for auto String asl = StringByKey("SETAXISFLAGS", AxisInfo(graphname,"left")) // Print asl if(CmpStr(asl,"",0) == 0) // Print "left manual" gvasl = 1 else // Print "left auto" gvasl = 0 endif String asb = StringByKey("SETAXISFLAGS", AxisInfo(graphname,"bottom")) // Print asb if(CmpStr(asb,"",0) == 0) // Print "bottom manual" gvasb = 1 else // Print "bottom auto" gvasb = 0 endif // store min and max values if set to manual if(gvasl == 1) GetAxis/Q/W=$graphname left gvlmin = V_min // Print V_min // Print gvlmin gvlmax = V_max // Print V_max // Print gvlmax endif if(gvasb == 1) GetAxis/Q/W=$graphname bottom gvbmin = V_min // Print V_min // Print gvbmin gvbmax = V_max // Print V_max // Print gvbmax endif // return to default folder SetDataFolder saveDFR //Print gvaslk endif End ///////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////// Function ExtractKin() // WAVE/Z w = CsrWaveRef(A) // if (!WaveExists(w)) // return NaN // endif // String zmatName = NameOfWave(w) String ImTest = ImageInfo("","",0) // make this only applicable to images if(cmpstr(Imtest,"",0) == 0) Print "Not an image." return 0 else NVAR gCursB = root:Packages:InspectData:gCursB String info= ImageInfo("","",0) String zmatName = StringByKey("ZWAVE",info) // String xwName = StringByKey("XWAVE",info) String base String suffix String regex = "(.*?)(zmat|zibg)" SplitString /E=(regex) zmatName, base, suffix String xwName if(CmpStr(zmatName,"")==0) xwName = "NewMatrix" else xwName = base + "xc" endif // String xwName = RemoveEnding(zmatName, "zmat") // xwName = RemoveEnding(zmatName, "zibg") Variable xpos, lambda, CursName Variable xposB, lambdaB xpos = pcsr(A) lambda = hcsr(A) if(gCursB == 1) xposB = pcsr(B) lambdaB = hcsr(B) endif Prompt CursName, "Cursor used to generate plot:", popup, "Cursor A;Cursor B;ROI Cursor A/B" Prompt zmatName, "Enter matrix wave name: " // Prompt zmatName, "Enter matrix wave name: ", popup, StringByKey("ZWAVE",ImageInfo("","",0)) Prompt xpos, "Enter cursor A postion for desired wavelength: " Prompt xposB, "Enter cursor B postion for desired wavelength: " Prompt xwName, "Enter wavelength wave name: " if(gCursB == 1) DoPrompt "Generate Kinetics", CursName, zmatName, xpos, xposB, xwName else DoPrompt "Generate Kinetics", zmatName, xpos, xwName CursName = 1 endif if (V_Flag) return -1 endif if(CursName == 1) Print "A" Plot1DFromMat(zmatName, xpos, xpos, xwName, 0) elseif(CursName == 2) Print "B" Plot1DFromMat(zmatName, xposB, xposB, xwName, 0) elseif(CursName == 3) Print "A/B" Plot1DFromMat(zmatName, xpos, xposB, xwName, 0) endif // Print zmatName; Print xwName // Variable tName = NumberByKey("RECREATION",CsrInfo(A)) // KineticsPlot2(zmatName,xpos,xwName) return 0 endif End Function ExtractSpec() // WAVE/Z w = CsrWaveRef(A) // if (!WaveExists(w)) // return NaN // endif // String zmatName = NameOfWave(w) String ImTest = ImageInfo("","",0) // make this only applicable to images if(cmpstr(Imtest,"",0) == 0) Print "Not an image." return 0 else NVAR gCursB = root:Packages:InspectData:gCursB String info= ImageInfo("","",0) String zmatName = StringByKey("ZWAVE",info) String base String suffix String regex = "(.*?)(zmat|zibg)" SplitString /E=(regex) zmatName, base, suffix String ywName if(CmpStr(zmatName,"")==0) ywName = "NewMatrix" else ywName = base + "yc" endif // String ywName = RemoveEnding(zmatName, "zmat") // ywName = ywName + "yc" Variable ypos, stime, CursName Variable yposB, stimeB ypos = qcsr(A) stime = vcsr(A) if(gCursB == 1) yposB = qcsr(B) stimeB = vcsr(B) endif Prompt CursName, "Cursor used to generate plot:", popup, "Cursor A;Cursor B;ROI Cursor A/B" Prompt zmatName, "Enter matrix wave name: " Prompt ypos, "Enter cursor A postion for desired time: " Prompt yposB, "Enter cursor B postion for desired time: " Prompt ywName, "Enter time wave name: " if(gCursB == 1) DoPrompt "Generate Spectra", CursName, zmatName, ypos, yposB, ywName else DoPrompt "Generate Spectra", zmatName, ypos, ywName CursName = 1 endif if (V_Flag) return -1 endif if(CursName == 1) Print "A" Plot1DFromMat(zmatName, ypos, ypos, ywName, 1) elseif(CursName == 2) Print "B" Plot1DFromMat(zmatName, yposB, yposB, ywName, 1) elseif(CursName == 3) Print "A/B" Plot1DFromMat(zmatName, ypos, yposB, ywName, 1) endif // Print zmatName; Print ywName // SpectraPlot2(zmatName,ypos,ywName) return 0 endif End Function Plot1DFromMat(Mat, ACurs, BCurs, ltWave, mode) // this function will average 1D slices over a range given by the 2 cursor positions // for extraction at a single pixel, make sure that ACurs = B Curs // mode should be set to 0 for vertical image slice (kinetics) // mode should be set to 1 for horizontal slice (spectra) // written to behave like KineticsPlot2 (found in v. 4alpha3) String Mat, ltWave Variable ACurs, BCurs, mode Wave ksM = $Mat Variable m,n m = Dimsize(ksM,0) // numer of rows n = Dimsize(ksM,1) // number of columns // get base name to append to // also define name of time wave to plot against String base String suffix // First write for kinetics plot String kWaveName, sWaveName // Name for common plot String kWinName, sWinName String tWave, swave String dfSave String regex = "(.*?)(zmat|zibg)" SplitString /E=(regex) Mat, base, suffix if(CmpStr(base,"")==0) kWaveName = "NewMatrix" tWave = "EmptyTimeWave" sWave = "EmstySpectraWave" // plot all extracted kinetics on the same graph // define window name to be base + kp kWinName = "Empty K Name" sWinName = "Empty S Plot" else tWave = base + "yc" sWave = base + "xc" // plot all extracted kinetics on the same graph // define window name to be base + kp kWinName = base + "kp" sWinName = base + "sp" endif // make sure it is not more than 31 chars if(mode == 0) // kinetics Wave ltM = $sWave elseif(mode == 1) // spectra Wave ltM = $tWave endif Variable DAB = abs(ACurs - BCurs) String IName Variable IA = ltM[ACurs] Variable lB = ltM[BCurs] Variable lAB = abs(IA - lB) Variable minpix, maxpix if(ACurs <= BCurs) // Print "Less than or equal" minpix = ACurs maxpix = BCurs // IName = num2Str(IA + ((IA - lB)/2)) if(mode == 0) sprintf IName, "%3.0f", (IA + (lAB/2)) else sprintf IName, "%1.3f", (IA + (lAB/2)) endif else // Print "GT!" minpix = BCurs maxpix = ACurs // IName = num2Str(lB + ((lB - IA)/2)) if(mode == 0) sprintf IName, "%3.0f", (lB + (lAB/2)) else sprintf IName, "%1.3f", (lB + (lAB/2)) endif endif kWaveName = base + "k" + IName + "_" + num2iStr(DAB) sWaveName = base + "s" + IName + "_" + num2iStr(DAB) kWaveName = CleanupName(kWaveName, 1) sWaveName = CleanupName(sWaveName, 1) Variable i = 0 Variable j = 0 if(mode == 0) Make/D/O/N=(n) $kWaveName Wave w = $kWaveName w = 0 // use built-in indexing capabilities to // extract a row // I find this implementation to be partuclarly confusing do w += ksM[minpix+i] [p] i+=1 while(minpix+i <= maxpix) w /= i // show all extracted traces on the same graph // create new graph if it doesn't exist DoWindow/F $kWinName if (V_Flag == 0) Display/K=2/N=$kWinName w vs $tWave else AppendToGraph/W=$kWinName w vs $tWave endif // DoUpdate elseif(mode == 1) Make/D/O/N=(m) $sWaveName Wave v = $sWaveName v = 0 do v += ksM[p][minpix+j] j+=1 while(minpix+j <= maxpix) v /= j // show all extracted traces on the same graph // create new graph if it doesn't exist DoWindow/F $sWinName if (V_Flag == 0) Display/K=2/N=$sWinName v vs $sWave else AppendToGraph/W=$sWinName v vs $sWave endif else // just fail if mode set to anything else return 0 endif End Function KineticsPlot2(KMat, lambdaPos, lambdaWave) String KMat, lambdaWave Variable lambdaPos Wave kM = $KMat Wave lM = $lambdaWave // generate target wave for kinetic information // named appropriately with the wavelength Variable m,n m = Dimsize(kM,0) // numer of rows n = Dimsize(kM,1) // number of columns String kWaveName // Name for common plot String kWinName String tWave Variable l = lM[lambdaPos] String lName = num2str(l) String dfSave // get base name to append to // also define name of time wave to plot against String base String suffix String regex = "(.*?)(zmat|zibg)" SplitString /E=(regex) kMat, base, suffix if(CmpStr(base,"")==0) kWaveName = "NewMatrix" tWave = "EmptyTimeWave" // plot all extracted kinetics on the same graph // define window name to be base + kp kWinName = "Empty K Name" else kWaveName = base + "k" +lName tWave = base + "yc" // plot all extracted kinetics on the same graph // define window name to be base + kp kWinName = base + "kp" endif // make sure it is not more than 31 chars kWaveName = CleanupName(kWaveName, 1) Make/D/O/N=(n) $kWaveName Wave w = $kWaveName // use built-in indexing capabilities to // extract a row // I find this implementation to be partuclarly confusing w = kM[lambdaPos] [p] // show all extracted traces on the same graph // create new graph if it doesn't exist DoWindow/F $kWinName if (V_Flag == 0) Display/K=2/N=$kWinName w vs $tWave else AppendToGraph/W=$kWinName w vs $tWave endif // DoUpdate return 0 end Function SpectraPlot2(SMat, timePos, timeWave) String SMat, timeWave Variable timePos String sWave //= RemoveEnding(SMat, "zmat") + "xc" Wave sM = $SMat Wave tM = $timeWave Variable m,n m = Dimsize(sM,0) // numer of rows n = Dimsize(sM,1) // number of columns String tWaveName, tWinName Variable tme = tM[timePos] String tmeName = num2str(tme) String base String suffix String regex = "(.*?)(zmat|zibg)" SplitString /E=(regex) SMat, base, suffix if(CmpStr(base,"")==0) tWaveName = "EmptyTimeWave" tWinName = "Empty S Name" else tWaveName = base + "s" +tmeName sWave = base + "xc" tWinName = base + "sp" endif // tWaveName = RemoveEnding(SMat, "zmat") + "s" +tmeName tWaveName = CleanupName(tWaveName, 1) Make/D/O/N=(m) $tWavename Wave v = $tWavename v = SM[p][timepos] // Display v vs $sWave // show all extracted traces on the same graph // create new graph if it doesn't exist DoWindow/F $tWinName if (V_Flag == 0) Display/K=2/N=$tWinName v vs $sWave else AppendToGraph/W=$tWinName v vs $sWave endif // DoUpdate return 0 end ///////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////// // Subtract scattered light procedures (laser + fluorescence) // This is not used for other background subtraction // This is the display recreation macro, created by Igor // and then manually tweaked. The parts that were tweaked // are shown in bold. NOTE: Some lines are wrapped to fit on the page. Window IntBackControlPanel() : Panel PauseUpdate; Silent 1 // building window... NewPanel/W=(150,100,600,320)/K=1 as "Get Cursor Positions" SetDrawEnv fsize= 16 DrawText 109,28,"Scattered Light Correction" SetVariable XSetVar,pos={40,45},size={150,15},title="Cursor A:" SetVariable XSetVar,limits={0,Inf,1},value=root:Packages:IntensityBackground:cAComponent SetVariable YSetVar,pos={210,45},size={150,15},title="Cursor B:" SetVariable YSetVar,limits={0,Inf,1},value=root:Packages:IntensityBackground:cBComponent Button ComputeButton,pos={110,76},size={90,20}, proc=GetCursorPositions,title="Preview" Button ComputeButton2,pos={227,76},size={90,20}, proc=GetCursorPositions2,title="Save" SetVariable setvar0 title="matrix:",size={284,15},bodyWidth=250, pos={77,115}, value=root:Packages:IntensityBackground:zWave SetVariable setvar0_1 title="sca_bkgd:",size={298,15},bodyWidth=250, pos={63,142}, value=root:Packages:IntensityBackground:scaWave SetVariable setvar0_2 title="corrected:",size={299,15},bodyWidth=250, pos={62,171}, value=root:Packages:IntensityBackground:corrWave // embed graph // String IntBackPlot // Display/host=# /W=(50,200,400,350) as IntBackPlot End // This is the action procedure for the Compute button. // We created it using the Button dialog. Function GetCursorPositions(ctrlName) : ButtonControl String ctrlName // Make sure both cursors are on the same wave. WAVE wA = CsrWaveRef(A) WAVE wB = CsrWaveRef(B) String dfA = GetWavesDataFolder(wA, 2) String dfB = GetWavesDataFolder(wB, 2) if (CmpStr(dfA, dfB) != 0) Abort "Both cursors must be on the same wave." return -1 endif String info= ImageInfo("","",0) String zmatName = StringByKey("ZWAVE",info) Print zmatName // Wave wZ = $zmatName Variable n = Dimsize($zmatName,0) // number of columns String dfSave = GetDataFolder(1) // SetDataFolder root:Packages:IntensityBackground SVAR zWave = root:Packages:IntensityBackground:zWave zWave = zmatName NVAR cAComponent = root:Packages:IntensityBackground:cAComponent NVAR cBComponent = root:Packages:IntensityBackground:cBComponent cAComponent = qcsr(A) Printf "Cursor A=%g\r", cAComponent Variable imin = cAComponent cBComponent = qcsr(B) Printf "Cursor B=%g\r", cBComponent Variable imax = cBComponent // SetDataFolder dfSave //restore original location // Print imin // Print imax // Print n PreviewSLC(zmatName, imin, imax) End Function GetCursorPositions2(ctrlName) : ButtonControl String ctrlName DoWindow/K tempGraph // Make sure both cursors are on the same wave. WAVE wA = CsrWaveRef(A) WAVE wB = CsrWaveRef(B) String dfA = GetWavesDataFolder(wA, 2) String dfB = GetWavesDataFolder(wB, 2) if (CmpStr(dfA, dfB) != 0) Abort "Both cursors must be on the same wave." return -1 endif String info= ImageInfo("","",0) String zmatName = StringByKey("ZWAVE",info) Print zmatName Wave wZ = $zmatName Variable n = Dimsize(wZ,0) // number of columns String dfSave = GetDataFolder(1) // SetDataFolder root:Packages:IntensityBackground SVAR zWave = root:Packages:IntensityBackground:zWave zWave = zmatName NVAR cAComponent = root:Packages:IntensityBackground:cAComponent NVAR cBComponent = root:Packages:IntensityBackground:cBComponent// Access current data folder. cAComponent = qcsr(A) Printf "Cursor A=%g\r", cAComponent Variable imin = cAComponent cBComponent = qcsr(B) Printf "Cursor B=%g\r", cBComponent Variable imax = cBComponent // SetDataFolder dfSave //restore original location // Print imin // Print imax // Print n ApplySLC(zmatName, imin, imax) End Function PreviewSLC(zMat, tmin, tmax) String zMat Variable tmin, tmax Wave fM = $zMat String scaBName = RemoveEnding(zMat, "zmat") + "scab" Variable minSig, maxSig if(tmin <= tmax) minSig = tmin maxSig = tmax elseif(tmin > tmax) minSig = tmax maxSig = tmin endif Variable m,n m = Dimsize(fM,0) // numer of rows n = Dimsize(fM,1) // number of columns String dfSave = GetDataFolder(1) SetDataFolder root:Packages:IntensityBackground // Make/O/N=(m) dummyS1 Make/O/N=(m) dummyS_avg Display/N=tempGraph Variable i,j i=0 do String dumstr = "dummyS_" + num2str(i) Make/O/N=(m) $dumstr Wave dS = $dumstr j=0 do dS[j] = fM[j][i+minSig] j+=1 while (j<=m) i+=1 dummyS_avg += dS AppendToGraph $dumstr while (i+minSig <= maxSig) dummyS_avg /= i SVAR scaWave = root:Packages:IntensityBackground:scaWave scaWave = scaBName Duplicate/O dummyS_avg, $scaBName KillWaves dummyS_avg SetDataFolder dfSave //restore original location return 0 end Function ApplySLC(zMat, tmin, tmax) String zMat Variable tmin, tmax String scaBName = RemoveEnding(zMat, "zmat") + "scab" String zcorName = RemoveEnding(zMat, "zmat") + "zibg" String ImageXName = RemoveEnding(zMat, "zmat") + "xim" String ImageYName = RemoveEnding(zMat, "zmat") + "yim" Wave fM = $zMat Duplicate/O $zMat, root:Packages:IntensityBackground:zMatTemp Variable minSig, maxSig if(tmin <= tmax) minSig = tmin maxSig = tmax elseif(tmin > tmax) minSig = tmax maxSig = tmin endif Variable m,n m = Dimsize(fM,0) // numer of rows n = Dimsize(fM,1) // number of columns Make/O/N=(m) dummyS1 Make/O/N=(m) dummyS_avg String dfSave = GetDataFolder(1) SetDataFolder root:Packages:IntensityBackground Variable i,j i=0 do j=0 do dummyS1[j] = fM[j][i+minSig] j+=1 while (j<=m) i+=1 dummyS_avg += dummyS1 while (i+minSig <= maxSig) dummyS_avg /= i SVAR scaWave = root:Packages:IntensityBackground:scaWave scaWave = scaBName KillWaves dummyS1 Duplicate/O dummyS_avg, $scaBName Duplicate/O dummyS_avg, root:$scaBName Wave wcorr = zMatTemp Variable k,l k=0 do l=0 do wcorr[l][k] = -log(10^(-(fM[l][k])) - 10^(-(dummyS_avg[l])) +1) // wcorr[k][l] = -log(10^(-(fM[k][l]))) // wcorr[k][l] = fM[k][l] l+=1 while (l<=m) k+=1 while(k