1 | #pragma rtGlobals=1 // Use modern global access method. |
---|
2 | #pragma version=5.0 |
---|
3 | #pragma IgorVersion=6.0 |
---|
4 | |
---|
5 | //********************* |
---|
6 | // Vers 1.2 083101 |
---|
7 | // Procedures to interactively select the 2D to 1D averageing options and viewing the 1D data |
---|
8 | // - pink "Average" panel and associated functions, including drawing on the 2D display |
---|
9 | // - generation of the 1D graph, including rescaling options |
---|
10 | // (rescaling options are quite similar to those in FIT_Ops) |
---|
11 | //********************** |
---|
12 | |
---|
13 | //main entry for invoking the pink average panel |
---|
14 | Proc ShowAveragePanel() |
---|
15 | DoWindow/F Average_Panel |
---|
16 | If(V_flag == 0) |
---|
17 | InitializeAveragePanel() |
---|
18 | //draw panel |
---|
19 | Average_Panel() |
---|
20 | DisableUnusedParameters("Circular") //the default choice |
---|
21 | Endif |
---|
22 | End |
---|
23 | |
---|
24 | //creates the necessary globals for the operation of the panel |
---|
25 | Proc InitializeAveragePanel() |
---|
26 | //create the global variables needed to run the Average Panel |
---|
27 | //all are kept in root:myGlobals:Drawing |
---|
28 | If( ! (DataFolderExists("root:myGlobals:Drawing")) ) |
---|
29 | NewDataFolder/O/S root:myGlobals:Drawing |
---|
30 | Endif |
---|
31 | |
---|
32 | //ok, create the globals, fill the keyword string with all possible values (default) |
---|
33 | String/G root:myGlobals:Drawing:gDrawInfoStr = "AVTYPE=Circular;PHI=0;DPHI=0;WIDTH=0;SIDE=both;" |
---|
34 | root:myGlobals:Drawing:gDrawInfoStr += "QCENTER=0;QDELTA=0;" |
---|
35 | Variable/G root:myGlobals:Drawing:gDrawPhi =0 |
---|
36 | Variable/G root:myGlobals:Drawing:gDrawWidth = 1 |
---|
37 | Variable/G root:myGlobals:Drawing:gDrawDPhi = 0 |
---|
38 | Variable/G root:myGlobals:Drawing:gDrawQCtr = 0 |
---|
39 | Variable/G root:myGlobals:Drawing:gDrawQDelta = 1 |
---|
40 | |
---|
41 | //return to root |
---|
42 | SetDataFolder root: |
---|
43 | End |
---|
44 | |
---|
45 | //button procedure to close the panel, does nothing else |
---|
46 | Function AveDoneButtonProc(ctrlName) : ButtonControl |
---|
47 | String ctrlName |
---|
48 | |
---|
49 | DoWindow/K Average_Panel |
---|
50 | End |
---|
51 | |
---|
52 | //button procedure to clear the lines drawn on the graph |
---|
53 | //which were drawn in the "User Front" layer only |
---|
54 | Function ClearLinesButtonProc(ctrlName) : ButtonControl |
---|
55 | String ctrlName |
---|
56 | |
---|
57 | //Print "Clear the drawn lines from the graph" |
---|
58 | DoWindow/F SANS_Data |
---|
59 | SetDrawLayer/K UserFront |
---|
60 | End |
---|
61 | |
---|
62 | //button procedure that will perform the average on the currently displayed file |
---|
63 | //using the choices that are currently in the panel |
---|
64 | //the panel is not directly parsed, since each information box,SetVar,popup |
---|
65 | //sets a corresponding value in the global string root:myGlobals:Drawing:gDrawInfoStr |
---|
66 | Function Panel_DoAverageButtonProc(ctrlName) : ButtonControl |
---|
67 | String ctrlName |
---|
68 | |
---|
69 | // average the currently displayed data |
---|
70 | SVAR type=root:myGlobals:gDataDisplayType |
---|
71 | |
---|
72 | //Check for logscale data in "type" folder |
---|
73 | String dest = "root:"+type |
---|
74 | |
---|
75 | NVAR isLogScale = $(dest + ":gIsLogScale") |
---|
76 | if(isLogScale) |
---|
77 | ConvertFolderToLinearScale(type) |
---|
78 | //rename the button to reflect "isLin" - the displayed name must have been isLog |
---|
79 | DoWindow/F SANS_Data |
---|
80 | MapSliderProc("reset", 0, 1) //force default values for color mapping |
---|
81 | Button bisLog,title="isLin",rename=bisLin |
---|
82 | DoWindow/F Average_Panel |
---|
83 | DoUpdate |
---|
84 | Endif |
---|
85 | |
---|
86 | //set data folder back to root (redundant) |
---|
87 | SetDataFolder root: |
---|
88 | |
---|
89 | //build the string that the averaging routine is looking for |
---|
90 | //The draw string uses the SAME keywords and value list - just copy it |
---|
91 | SVAR tempstr=root:myGlobals:Drawing:gDrawInfoStr |
---|
92 | String/G root:myGlobals:Protocols:gAvgInfoStr=tempStr |
---|
93 | String choice = StringByKey("AVTYPE",tempStr,"=",";") |
---|
94 | |
---|
95 | //does the user want to save the averaged file to disk? |
---|
96 | //poll the checkbox - the keyword may not be in the string, and here we'll always ask for a filename |
---|
97 | ControlInfo/W=Average_Panel SaveCheck |
---|
98 | Variable doSave = V_Value |
---|
99 | //if the "average" choice is 2D ASCII or QxQy ASCII, then doSave=1 to force a save |
---|
100 | if(strsearch(choice,"ASCII",0) != -1) |
---|
101 | doSave = 1 |
---|
102 | endif |
---|
103 | |
---|
104 | If(doSave) |
---|
105 | //setup a "fake protocol" wave, sice I have no idea of the current state of the data |
---|
106 | Make/O/T/N=8 root:myGlobals:Protocols:fakeProtocol |
---|
107 | Wave/T fakeProtocol = $"root:myGlobals:Protocols:fakeProtocol" |
---|
108 | String junk="Unknown file from Average_Panel" |
---|
109 | fakeProtocol[0] = junk |
---|
110 | fakeProtocol[1] = junk |
---|
111 | fakeProtocol[2] = junk |
---|
112 | fakeProtocol[3] = junk |
---|
113 | fakeProtocol[4] = junk |
---|
114 | fakeProtocol[5] = junk |
---|
115 | fakeProtocol[6] = junk |
---|
116 | fakeProtocol[7] = tempStr |
---|
117 | //set the global |
---|
118 | String/G root:myGlobals:Protocols:gProtoStr = "fakeProtocol" |
---|
119 | Endif |
---|
120 | |
---|
121 | //dispatch to correct averaging routine - |
---|
122 | strswitch(choice) |
---|
123 | case "Rectangular": |
---|
124 | RectangularAverageTo1D(type) |
---|
125 | If(doSave) |
---|
126 | //save the file, acting on the currently displayed file |
---|
127 | WriteWaves_W_Protocol(type,"",1) //"" is an empty path, 1 will force a dialog |
---|
128 | Endif |
---|
129 | break |
---|
130 | case "Annular": |
---|
131 | AnnularAverageTo1D(type) |
---|
132 | If(doSave) |
---|
133 | //save the file, acting on the currently displayed file |
---|
134 | WritePhiave_W_Protocol(type,"",1) //"" is an empty path, 1 will force a dialog |
---|
135 | Endif |
---|
136 | break |
---|
137 | case "Circular": |
---|
138 | case "Sector": |
---|
139 | //circular or sector |
---|
140 | CircularAverageTo1D(type) //graph is drawn here |
---|
141 | If(doSave) |
---|
142 | //save the file, acting on the currently displayed file |
---|
143 | WriteWaves_W_Protocol(type,"",1) //"" is an empty path, 1 will force a dialog |
---|
144 | Endif |
---|
145 | break |
---|
146 | case "2D ASCII": |
---|
147 | Fast2dExport(type,"",1) |
---|
148 | break |
---|
149 | case "QxQy ASCII": |
---|
150 | QxQy_Export(type,"",1) |
---|
151 | break |
---|
152 | default: |
---|
153 | Abort "no case match in average dispatch" |
---|
154 | endswitch |
---|
155 | |
---|
156 | //clear the stuff that was created for case of saving files |
---|
157 | If(doSave) |
---|
158 | Killwaves/Z root:myGlobals:Protocols:fakeProtocol |
---|
159 | String/G root:myGlobals:Protocols:gProtoStr = "" |
---|
160 | Endif |
---|
161 | return(0) |
---|
162 | |
---|
163 | End |
---|
164 | |
---|
165 | //when "sides" popup is "popped", the value associated with the SIDE |
---|
166 | //keyword is updated in the global string |
---|
167 | //then the angles are redrawn based on the choice |
---|
168 | Function SidesPopMenuProc(ctrlName,popNum,popStr) : PopupMenuControl |
---|
169 | String ctrlName |
---|
170 | Variable popNum |
---|
171 | String popStr |
---|
172 | |
---|
173 | ControlInfo/W=Average_Panel sides |
---|
174 | String side = S_Value |
---|
175 | SVAR tempStr = root:myGlobals:Drawing:gDrawInfoStr |
---|
176 | String newStr = ReplaceStringByKey("SIDE", tempStr, side, "=", ";") |
---|
177 | |
---|
178 | String/G root:myGlobals:Drawing:gDrawInfoStr = newStr |
---|
179 | |
---|
180 | //redraw the angles |
---|
181 | MasterAngleDraw() |
---|
182 | |
---|
183 | End |
---|
184 | |
---|
185 | |
---|
186 | //when the "type of average" popup is "popped", the value associated with the AVTYPE |
---|
187 | //keyword is updated in the global string |
---|
188 | //then the angles are redrawn based on the choice |
---|
189 | // |
---|
190 | // changes the title of the "do" button to "Save" if ASCII is chosen |
---|
191 | // disables all setVars (ASCII cases), then selectively enables them as choice dictates |
---|
192 | Function AvTypePopMenuProc(ctrlName,popNum,popStr) : PopupMenuControl |
---|
193 | String ctrlName |
---|
194 | Variable popNum |
---|
195 | String popStr |
---|
196 | |
---|
197 | ControlInfo/W=Average_Panel av_choice |
---|
198 | String choice = S_Value |
---|
199 | SVAR tempStr = root:myGlobals:Drawing:gDrawInfoStr |
---|
200 | |
---|
201 | DisableUnusedParameters(choice) |
---|
202 | |
---|
203 | strswitch(choice) // string switch |
---|
204 | case "2D ASCII": // execute if case matches expression |
---|
205 | case "QxQy ASCII": |
---|
206 | String/G root:myGlobals:Drawing:gDrawInfoStr = ReplaceStringByKey("AVTYPE", tempStr, choice, "=", ";") |
---|
207 | Button P_DoAvg,title="Save ASCII" |
---|
208 | break |
---|
209 | case "Circular": |
---|
210 | case "Sector": |
---|
211 | case "Rectangular": |
---|
212 | case "Annular": |
---|
213 | String/G root:myGlobals:Drawing:gDrawInfoStr = ReplaceStringByKey("AVTYPE", tempStr, choice, "=", ";") |
---|
214 | Button P_DoAvg,title="Do Average" |
---|
215 | //redraw the angles |
---|
216 | MasterAngleDraw() |
---|
217 | break |
---|
218 | default: // optional default expression executed |
---|
219 | Abort "no case matches from averagePanel type popup" // when no case matches |
---|
220 | endswitch |
---|
221 | return(0) |
---|
222 | End |
---|
223 | |
---|
224 | // disables all of the type-specific buttons and popups on the average_Panel |
---|
225 | // currently ununsed, ans the logic is quite slippery |
---|
226 | Function DisableUnusedParameters(choice) |
---|
227 | String choice |
---|
228 | |
---|
229 | Variable yes=1,no=0 |
---|
230 | |
---|
231 | strswitch(choice) // string switch |
---|
232 | case "2D ASCII": |
---|
233 | case "QxQy ASCII": |
---|
234 | case "Circular": //disable everything for these three choices |
---|
235 | SetVariable Phi_p,disable=yes |
---|
236 | SetVariable Qctr_p,disable=yes |
---|
237 | SetVariable Qdelta_p,disable=yes |
---|
238 | SetVariable DPhi_p,disable=yes |
---|
239 | SetVariable width_p,disable=yes |
---|
240 | popupmenu sides,disable=yes |
---|
241 | break |
---|
242 | case "Sector": |
---|
243 | SetVariable Phi_p,disable=no |
---|
244 | SetVariable Qctr_p,disable=yes |
---|
245 | SetVariable Qdelta_p,disable=yes |
---|
246 | SetVariable DPhi_p,disable=no |
---|
247 | SetVariable width_p,disable=yes |
---|
248 | popupmenu sides,disable=no |
---|
249 | break |
---|
250 | case "Rectangular": |
---|
251 | SetVariable Phi_p,disable=no |
---|
252 | SetVariable Qctr_p,disable=yes |
---|
253 | SetVariable Qdelta_p,disable=yes |
---|
254 | SetVariable DPhi_p,disable=yes |
---|
255 | SetVariable width_p,disable=no |
---|
256 | popupmenu sides,disable=no |
---|
257 | break |
---|
258 | case "Annular": |
---|
259 | SetVariable Phi_p,disable=yes |
---|
260 | SetVariable Qctr_p,disable=no |
---|
261 | SetVariable Qdelta_p,disable=no |
---|
262 | SetVariable DPhi_p,disable=yes |
---|
263 | SetVariable width_p,disable=yes |
---|
264 | popupmenu sides,disable=yes |
---|
265 | break |
---|
266 | default: // optional default expression executed |
---|
267 | Abort "no case matches from averagePanel type popup" // when no case matches |
---|
268 | endswitch |
---|
269 | return(0) |
---|
270 | end |
---|
271 | |
---|
272 | //draws the Panel, with defaults for standard circular average |
---|
273 | Window Average_Panel() |
---|
274 | PauseUpdate; Silent 1 // building window... |
---|
275 | NewPanel /W=(638,65,933,347) /K=1 |
---|
276 | ModifyPanel cbRGB=(65535,49151,62258), fixedSize=1 |
---|
277 | SetDrawLayer UserBack |
---|
278 | // DrawText 192,121,"(pixels)" |
---|
279 | // DrawText 47,190,"(pixels)" |
---|
280 | GroupBox ann,pos={148,44},size={143,84},title="Annular" |
---|
281 | GroupBox rect,pos={7,133},size={134,71},title="Rectangular" |
---|
282 | GroupBox sect,pos={148,133},size={143,71},title="Sector" |
---|
283 | GroupBox sect_rect,pos={7,44},size={134,84},title="Sector/Rectangular" |
---|
284 | PopupMenu av_choice,pos={61,7},size={144,20},proc=AvTypePopMenuProc,title="AverageType" |
---|
285 | PopupMenu av_choice,help={"Select the type of average to perform, then make the required selections below and click \"DoAverage\" to plot the results"} |
---|
286 | PopupMenu av_choice,mode=1,popvalue="Circular",value= #"\"Circular;Sector;Annular;Rectangular;2D ASCII;QxQy ASCII\"" |
---|
287 | Button ave_help,pos={260,7},size={25,20},proc=ShowAvePanelHelp,title="?" |
---|
288 | Button ave_help,help={"Show the help file for averaging options"} |
---|
289 | Button ave_done,pos={199,245},size={50,20},proc=AveDoneButtonProc,title="Done" |
---|
290 | Button ave_done,help={"When done, this will close the panel. The panel may be recalled at any time from the SANS menu."} |
---|
291 | Button ClearLines,pos={198,212},size={50,20},proc=ClearLinesButtonProc,title="Clear" |
---|
292 | Button ClearLines,help={"This will clear the drawn lines from the SANS data"} |
---|
293 | SetVariable Phi_p,pos={32,92},size={70,15},proc=PhiSetVarProc,title="Phi" |
---|
294 | SetVariable Phi_p,help={"Enter the azimuthal angle phi (-90,90). Phi is defined CCW from zero at the positive x-axis. The phi line will be drawn in light green."} |
---|
295 | SetVariable Phi_p,limits={-90,90,1},value= root:myGlobals:Drawing:gDrawPhi |
---|
296 | SetVariable Qctr_p,pos={155,66},size={130,15},proc=QctrSetVarProc,title="Q-center" |
---|
297 | SetVariable Qctr_p,help={"Enter the q-center of the annular region (1/A). The circle will be drawn in light green."} |
---|
298 | SetVariable Qctr_p,limits={1e-05,0.7,0.001},value= root:myGlobals:Drawing:gDrawQCtr |
---|
299 | SetVariable QDelta_p,pos={155,90},size={130,15},proc=QDeltaSetVarProc,title="Q Delta (pixels)" |
---|
300 | SetVariable QDelta_p,help={"Enter the total width of the annulus in pixels. The bounding circles will be draw in blue."} |
---|
301 | SetVariable QDelta_p,limits={1,40,1},value= root:myGlobals:Drawing:gDrawQDelta |
---|
302 | SetVariable DPhi_p,pos={166,154},size={110,15},proc=DeltaPhiSetVarProc,title="Delta Phi" |
---|
303 | SetVariable DPhi_p,help={"Enter the +/- range (0,45) of azimuthal angles to be included in the average. The bounding angles will be drawin in blue."} |
---|
304 | SetVariable DPhi_p,limits={0,90,1},value= root:myGlobals:Drawing:gDrawDPhi |
---|
305 | SetVariable width_p,pos={15,155},size={115,15},proc=WidthSetVarProc,title="Width (pixels)" |
---|
306 | SetVariable width_p,help={"Enter the total width of the rectangular section in pixels. The bounding lines will be drawn in blue."} |
---|
307 | SetVariable width_p,limits={1,130,1},value= root:myGlobals:Drawing:gDrawWidth |
---|
308 | Button P_DoAvg,pos={30,247},size={90,20},proc=Panel_DoAverageButtonProc,title="Do Average" |
---|
309 | Button P_DoAvg,help={"This will do the averaging of the displayed dta based on the selection in this panel. The data will automatically be plotted. It will not be saved to disk unless the \"Save to disk\" box is checked BEFORE the average is performed."} |
---|
310 | PopupMenu sides,pos={16,67},size={97,20},proc=SidesPopMenuProc,title="Sides ?" |
---|
311 | PopupMenu sides,help={"Select the regions of the detector to include in the averaging. \"right\" denotes right or above the beamstop."} |
---|
312 | PopupMenu sides,mode=1,popvalue="both",value= #"\"both;left;right\"" |
---|
313 | CheckBox saveCheck,pos={14,215},size={102,14},title="Save file to disk?" |
---|
314 | CheckBox saveCheck,help={"If checked, the averaged data will be saved to disk. The user will always be prompted for the filename."} |
---|
315 | CheckBox saveCheck,value= 0 |
---|
316 | EndMacro |
---|
317 | |
---|
318 | Function ShowAvePanelHelp(ctrlName) : ButtonControl |
---|
319 | String ctrlName |
---|
320 | DisplayHelpTopic/K=1 "SANS Data Reduction Tutorial[Average Options]" |
---|
321 | end |
---|
322 | |
---|
323 | //Sets global key=value for drawing phi-line on graph |
---|
324 | //and redraws the angles |
---|
325 | Function PhiSetVarProc(ctrlName,varNum,varStr,varName) : SetVariableControl |
---|
326 | String ctrlName |
---|
327 | Variable varNum |
---|
328 | String varStr |
---|
329 | String varName |
---|
330 | |
---|
331 | ControlInfo/W=Average_Panel phi_p |
---|
332 | Variable phi = V_Value |
---|
333 | SVAR tempStr = root:myGlobals:Drawing:gDrawInfoStr |
---|
334 | String newStr = ReplaceNumberByKey("PHI", tempStr, phi, "=", ";") |
---|
335 | |
---|
336 | String/G root:myGlobals:Drawing:gDrawInfoStr = newStr |
---|
337 | |
---|
338 | //redraw the angles |
---|
339 | MasterAngleDraw() |
---|
340 | End |
---|
341 | |
---|
342 | //draws all of the lines specified by the global keyword string |
---|
343 | //clears the old lines, and parses the string |
---|
344 | Function MasterAngleDraw() |
---|
345 | //takes the global gDrawInfoStr and Parses it to determine what to redraw on the graph |
---|
346 | |
---|
347 | //first clear the old draw Layer |
---|
348 | DoWindow/F SANS_Data |
---|
349 | if(V_flag ==0) |
---|
350 | Abort "No SANS data. Use'Display Raw Data' to display a 2D data file" |
---|
351 | Endif |
---|
352 | SetDrawLayer/K UserFront |
---|
353 | SetDrawLayer UserFront |
---|
354 | |
---|
355 | //what average type are we drawing for? |
---|
356 | SVAR drawStr = root:myGlobals:Drawing:gDrawInfoStr |
---|
357 | |
---|
358 | //get the beam center from the currently displayed data type |
---|
359 | SVAR type = root:myGlobals:gDataDisplayType |
---|
360 | Wave reals = $("root:"+type+":RealsRead") |
---|
361 | Variable x0,y0,x1,y1 |
---|
362 | x0 = reals[16] - 1 //convert to [0,127] from (1,128) detector |
---|
363 | y0 = reals[17] - 1 |
---|
364 | |
---|
365 | //right, left, or both halves? |
---|
366 | //what type of average? |
---|
367 | String side = StringByKey("SIDE",drawStr,"=",";") |
---|
368 | String av_type = StringByKey("AVTYPE",drawStr,"=",";") |
---|
369 | Variable phi = NumberByKey("PHI",drawStr,"=",";") |
---|
370 | Variable dphi = NumberByKey("DPHI",drawStr,"=",";") |
---|
371 | Variable width = NumberByKey("WIDTH",drawStr,"=",";") |
---|
372 | |
---|
373 | Variable delx,dely,slope,intcp,rr,gg,bb,thick |
---|
374 | rr = 0 |
---|
375 | gg = 0 |
---|
376 | bb = 0 |
---|
377 | thick = 2 |
---|
378 | |
---|
379 | //if circular average, just get out |
---|
380 | if(cmpstr(av_type,"Circular")==0) |
---|
381 | //clear the drawing |
---|
382 | // DoWindow/F SANS_Data |
---|
383 | // SetDrawLayer/K UserFront |
---|
384 | //go back to the average panel |
---|
385 | DoWindow/F Average_Panel |
---|
386 | |
---|
387 | Return 0 //exit the Draw routine |
---|
388 | Endif |
---|
389 | |
---|
390 | //handle sector-type and annular type averages differently |
---|
391 | if(cmpstr(av_type,"Annular")==0) |
---|
392 | //do the annular drawing |
---|
393 | //need to go from q-value to y-axis value (since x will shift a lot) |
---|
394 | //and make sure that the (radius) is allowable for drawing |
---|
395 | Variable sdd=reals[18],lam=reals[26] |
---|
396 | |
---|
397 | sdd *=100 //convert to cm |
---|
398 | //find the radius (from the y-direction) |
---|
399 | Variable QCtr = NumberByKey("QCENTER",drawStr,"=",";") |
---|
400 | Variable QDelta = NumberByKey("QDELTA",drawStr,"=",";") |
---|
401 | Variable thetay,dy,pixelSize |
---|
402 | |
---|
403 | pixelSize = reals[10]/10 //this is ONLY the x-direction, converted to cm |
---|
404 | thetay = 2*asin(Qctr*lam/4/Pi) |
---|
405 | dy = sdd/pixelSize*tan(thetay) //pixelSize is to convert from cm on detector to pixel |
---|
406 | |
---|
407 | rr=0 |
---|
408 | gg=50000 |
---|
409 | bb=0 |
---|
410 | DrawACircle(x0,y0,dy,rr,gg,bb,thick) |
---|
411 | |
---|
412 | //then do the +/- Qdelta rings |
---|
413 | //QDelta is the width of the annulus, in pixels |
---|
414 | rr=0 |
---|
415 | gg=0 |
---|
416 | bb=50000 |
---|
417 | DrawACircle(x0,y0,dy+(QDelta/2),rr,gg,bb,thick) |
---|
418 | // then the (- delta) ring |
---|
419 | DrawACircle(x0,y0,dy-(QDelta/2),rr,gg,bb,thick) |
---|
420 | |
---|
421 | //go back to the average panel |
---|
422 | DoWindow/F Average_Panel |
---|
423 | |
---|
424 | Return 0 //exit the Draw routine |
---|
425 | Endif |
---|
426 | |
---|
427 | //else sector or rectangular - draw the lines |
---|
428 | |
---|
429 | //if sector or rectangular, draw the phi line (on the desired side) |
---|
430 | if( (cmpstr(av_type,"Sector")==0) || (cmpstr(av_type,"Rectangular")==0)) |
---|
431 | if( (cmpstr(side,"left")==0) || (cmpstr(side,"both")==0) ) |
---|
432 | //draw the phi line on the left side |
---|
433 | //make sure x1,y1 is on the edge of the graph |
---|
434 | rr = 0 |
---|
435 | gg = 65535 |
---|
436 | bb = 0 |
---|
437 | DrawALineLeft(x0,y0,phi,rr,gg,bb,thick) |
---|
438 | Endif |
---|
439 | if( (cmpstr(side,"right")==0) || (cmpstr(side,"both")==0) ) |
---|
440 | //Draw the phi line on the right side |
---|
441 | //make sure x1,y1 is on the edge of the graph |
---|
442 | rr = 0 |
---|
443 | gg = 65535 |
---|
444 | bb = 0 |
---|
445 | DrawALineRight(x0,y0,phi,rr,gg,bb,thick) |
---|
446 | Endif |
---|
447 | Endif |
---|
448 | |
---|
449 | //if Sector, draw the +/- dphi lines |
---|
450 | if (cmpstr(av_type,"Sector")==0) |
---|
451 | if( (cmpstr(side,"left")==0) || (cmpstr(side,"both")==0) ) |
---|
452 | //draw the deltaPhi lines +/- lines |
---|
453 | if (dphi != 0) |
---|
454 | rr=0 |
---|
455 | gg = 0 |
---|
456 | bb = 50000 |
---|
457 | if (phi < 0 ) |
---|
458 | DrawALineLeft(x0,y0,phi+ dphi,rr,gg,bb,thick) |
---|
459 | if ( (abs(phi)+dphi) <= 90) |
---|
460 | DrawALineLeft(x0,y0,phi- dphi,rr,gg,bb,thick) |
---|
461 | else |
---|
462 | DrawALineRight(x0,y0,phi- dphi,rr,gg,bb,thick) |
---|
463 | Endif |
---|
464 | else |
---|
465 | if((phi+dphi) > 90) |
---|
466 | DrawALineRight(x0,y0,phi+ dphi,rr,gg,bb,thick) |
---|
467 | else |
---|
468 | DrawALineLeft(x0,y0,phi+ dphi,rr,gg,bb,thick) |
---|
469 | Endif |
---|
470 | DrawALineLeft(x0,y0,phi- dphi,rr,gg,bb,thick) |
---|
471 | Endif //phi<0 |
---|
472 | Endif //dphi !=0 |
---|
473 | Endif //left or both |
---|
474 | if( (cmpstr(side,"right")==0) || (cmpstr(side,"both")==0) ) |
---|
475 | //draw the deltaPhi lines +/- lines |
---|
476 | if (dphi != 0) |
---|
477 | rr = 0 |
---|
478 | gg = 0 |
---|
479 | bb = 50000 |
---|
480 | if (phi < 0 ) |
---|
481 | DrawALineRight(x0,y0,phi+ dphi,rr,gg,bb,thick) |
---|
482 | if ( (abs(phi)+dphi) <= 90) |
---|
483 | DrawALineRight(x0,y0,phi- dphi,rr,gg,bb,thick) |
---|
484 | else |
---|
485 | DrawALineLeft(x0,y0,phi- dphi,rr,gg,bb,thick) |
---|
486 | Endif |
---|
487 | else |
---|
488 | if((phi+dphi) > 90) |
---|
489 | DrawALineLeft(x0,y0,phi+ dphi,rr,gg,bb,thick) |
---|
490 | else |
---|
491 | DrawALineRight(x0,y0,phi+ dphi,rr,gg,bb,thick) |
---|
492 | Endif |
---|
493 | DrawALineRight(x0,y0,phi- dphi,rr,gg,bb,thick) |
---|
494 | Endif //phi<0 |
---|
495 | Endif //dphi !=0 |
---|
496 | Endif //right or both |
---|
497 | Endif //if sector, draw dphi lines |
---|
498 | |
---|
499 | //if rectangular, draw the parallel rectangle lines |
---|
500 | Variable xOffset,yOffset,beta |
---|
501 | if (cmpstr(av_type,"Rectangular")==0) |
---|
502 | beta = (90-phi)*Pi/180 |
---|
503 | xOffset = (width/2)*cos(beta) //need phi in radians |
---|
504 | yOffset = (width/2)*sin(beta) |
---|
505 | if (phi == 0) |
---|
506 | xOffset = 0 |
---|
507 | yOffset = width/2 |
---|
508 | Endif |
---|
509 | if( (cmpstr(side,"left")==0) || (cmpstr(side,"both")==0) ) |
---|
510 | rr = 0 |
---|
511 | gg = 0 |
---|
512 | bb = 50000 |
---|
513 | DrawALineLeft(x0-xOffset,y0+yOffset,phi,rr,gg,bb,thick) |
---|
514 | DrawALineLeft(x0+xOffset,y0-yOffset,phi,rr,gg,bb,thick) |
---|
515 | Endif |
---|
516 | if( (cmpstr(side,"right")==0) || (cmpstr(side,"both")==0) ) |
---|
517 | rr=0 |
---|
518 | gg=0 |
---|
519 | bb=50000 |
---|
520 | DrawALineRight(x0-xOffset,y0+yOffset,phi,rr,gg,bb,thick) |
---|
521 | DrawALineRight(x0+xOffset,y0-yOffset,phi,rr,gg,bb,thick) |
---|
522 | Endif |
---|
523 | Endif |
---|
524 | |
---|
525 | //go back to the average panel |
---|
526 | DoWindow/F Average_Panel |
---|
527 | |
---|
528 | Return 0 |
---|
529 | End |
---|
530 | |
---|
531 | //given beamcenter (x0,y0) and equation of line [slope and intercept] |
---|
532 | //return the point x1 where line leaves the detector image [0,127] on the left side |
---|
533 | Function FindXLeft(x0,y0,slope,intcp) |
---|
534 | Variable x0,y0,slope,intcp |
---|
535 | |
---|
536 | Variable x1=0,yat0 |
---|
537 | NVAR pixelsX = root:myGlobals:gNPixelsX |
---|
538 | NVAR pixelsY = root:myGlobals:gNPixelsY |
---|
539 | |
---|
540 | if (slope == 0) |
---|
541 | x1 = 0 |
---|
542 | return x1 |
---|
543 | endif |
---|
544 | if ((slope == Inf) || (slope == -Inf)) |
---|
545 | x1 = x0 |
---|
546 | return x1 |
---|
547 | Endif |
---|
548 | //else we have to do some math |
---|
549 | //at x=0, what is the y-axis value? |
---|
550 | yat0 = trunc(intcp) |
---|
551 | if( (yat0 >= 0) && (yat0 <=(pixelsY-1)) ) |
---|
552 | //crosses y axis, so x1 = 0 |
---|
553 | x1 = 0 |
---|
554 | else |
---|
555 | //need crossing value |
---|
556 | if (slope > 0) |
---|
557 | x1 = trunc((0-intcp)/slope) |
---|
558 | else |
---|
559 | x1 = trunc((pixelsY-1-intcp)/slope) |
---|
560 | Endif |
---|
561 | Endif |
---|
562 | return x1 |
---|
563 | End |
---|
564 | |
---|
565 | //given beamcenter (x0,y0) and equation of line [slope and intercept] |
---|
566 | //return the point y1 where line leaves the detector image [0,127] on the left side |
---|
567 | Function FindYLeft(x0,y0,slope,intcp) |
---|
568 | Variable x0,y0,slope,intcp |
---|
569 | |
---|
570 | Variable y1=0,yat0 |
---|
571 | |
---|
572 | NVAR pixelsX = root:myGlobals:gNPixelsX |
---|
573 | NVAR pixelsY = root:myGlobals:gNPixelsY |
---|
574 | |
---|
575 | if (slope == 0) |
---|
576 | y1 = y0 |
---|
577 | return y1 |
---|
578 | endif |
---|
579 | if (slope == Inf) |
---|
580 | y1 = 0 |
---|
581 | return y1 |
---|
582 | Endif |
---|
583 | If(slope == -Inf) |
---|
584 | y1 = pixelsY-1 |
---|
585 | return y1 |
---|
586 | Endif |
---|
587 | |
---|
588 | //else we have to do some math |
---|
589 | //at x=0, what is the y-axis value? |
---|
590 | yat0 = trunc(intcp) |
---|
591 | if( (yat0 >= 0) && (yat0 <=(pixelsY-1)) ) |
---|
592 | //crosses y axis, so return y1 |
---|
593 | y1 = yat0 |
---|
594 | else |
---|
595 | //need crossing value |
---|
596 | if (yat0 < 0) |
---|
597 | y1 = 0 |
---|
598 | else |
---|
599 | y1 = pixelsY-1 |
---|
600 | Endif |
---|
601 | Endif |
---|
602 | return y1 |
---|
603 | End |
---|
604 | |
---|
605 | //given beamcenter (x0,y0) and equation of line [slope and intercept] |
---|
606 | //return the point x1 where line leaves the detector image [0,127] on the right side |
---|
607 | Function FindXRight(x0,y0,slope,intcp) |
---|
608 | Variable x0,y0,slope,intcp |
---|
609 | |
---|
610 | Variable x1=0,yat127 |
---|
611 | |
---|
612 | NVAR pixelsX = root:myGlobals:gNPixelsX |
---|
613 | NVAR pixelsY = root:myGlobals:gNPixelsY |
---|
614 | |
---|
615 | if (slope == 0) |
---|
616 | x1 = pixelsX-1 |
---|
617 | return x1 |
---|
618 | endif |
---|
619 | if ((slope == Inf) || (slope == -Inf)) |
---|
620 | x1 = x0 |
---|
621 | return x1 |
---|
622 | Endif |
---|
623 | //else we have to do some math |
---|
624 | //at x=127, what is the y-axis value? |
---|
625 | yat127 = trunc(slope*(pixelsX-1)+intcp) |
---|
626 | if( (yat127 >= 0) && (yat127 <=(pixelsY-1)) ) |
---|
627 | //crosses y=127 edge, so x1 = 127 |
---|
628 | x1 = pixelsX-1 |
---|
629 | else |
---|
630 | //need crossing value |
---|
631 | if (slope > 0) |
---|
632 | x1 = trunc((pixelsX-1-intcp)/slope) |
---|
633 | else |
---|
634 | x1 = trunc((0-intcp)/slope) |
---|
635 | Endif |
---|
636 | Endif |
---|
637 | return x1 |
---|
638 | End |
---|
639 | |
---|
640 | //given beamcenter (x0,y0) and equation of line [slope and intercept] |
---|
641 | //return the point y1 where line leaves the detector image [0,127] on the right side |
---|
642 | Function FindYRight(x0,y0,slope,intcp) |
---|
643 | Variable x0,y0,slope,intcp |
---|
644 | |
---|
645 | Variable y1=0,yat127 |
---|
646 | NVAR pixelsX = root:myGlobals:gNPixelsX |
---|
647 | NVAR pixelsY = root:myGlobals:gNPixelsY |
---|
648 | |
---|
649 | if (slope == 0) |
---|
650 | y1 = y0 |
---|
651 | return y1 |
---|
652 | endif |
---|
653 | if (slope == Inf) |
---|
654 | y1 = pixelsY-1 |
---|
655 | return y1 |
---|
656 | Endif |
---|
657 | If(slope == -Inf) |
---|
658 | y1 = 0 |
---|
659 | return y1 |
---|
660 | Endif |
---|
661 | |
---|
662 | //else we have to do some math |
---|
663 | //at x=127, what is the y-axis value? |
---|
664 | yat127 = trunc(slope*(pixelsX-1)+intcp) |
---|
665 | if( (yat127 >= 0) && (yat127 <=(pixelsY-1)) ) |
---|
666 | //crosses y axis, so return y1 |
---|
667 | y1 = yat127 |
---|
668 | else |
---|
669 | //need crossing value |
---|
670 | if (yat127 < 0) |
---|
671 | y1 = 0 |
---|
672 | else |
---|
673 | y1 = pixelsY-1 |
---|
674 | Endif |
---|
675 | Endif |
---|
676 | return y1 |
---|
677 | End |
---|
678 | |
---|
679 | //draws a circle of radius rad, centered at (x0,y0) |
---|
680 | //line thickness is thick |
---|
681 | // color is (rr,gg,bb) |
---|
682 | Function DrawACircle(x0,y0,rad,rr,gg,bb,thick) |
---|
683 | Variable x0,y0,rad,rr,gg,bb,thick |
---|
684 | |
---|
685 | DoWindow/F SANS_Data |
---|
686 | SetDrawLayer UserFront |
---|
687 | SetDrawEnv xcoord= bottom,ycoord= left,linefgc= (rr,gg,bb),linethick= (thick),fillpat=0 |
---|
688 | DrawOval x0-rad,y0+rad,x0+rad,y0-rad //left,top,right,bottom |
---|
689 | End |
---|
690 | |
---|
691 | //draws a line to the left of the beamcenter (x0,y0) |
---|
692 | //angle is phi |
---|
693 | //thickness is thick |
---|
694 | //color is (rr,gg,bb) |
---|
695 | // function determines where the line will cross the edge of the image, and stops the line there. |
---|
696 | Function DrawALineLeft(x0,y0,phi,rr,gg,bb,thick) |
---|
697 | Variable x0,y0,phi,rr,gg,bb,thick |
---|
698 | |
---|
699 | Variable slope,intcp,x1,y1 |
---|
700 | |
---|
701 | slope = tan(phi*Pi/180) //need arg in radians, not degrees |
---|
702 | if ( phi == 90 ) |
---|
703 | slope = Inf |
---|
704 | Endif |
---|
705 | If (phi == -90) |
---|
706 | slope = -Inf |
---|
707 | Endif |
---|
708 | intcp = y0 - slope * x0 |
---|
709 | x1 = FindXLeft(x0,y0,slope,intcp) |
---|
710 | y1 = FindYLeft(x0,y0,slope,intcp) |
---|
711 | |
---|
712 | DoWindow/F SANS_Data |
---|
713 | SetDrawLayer UserFront |
---|
714 | SetDrawEnv xcoord= bottom,ycoord= left,linefgc= (rr,gg,bb),linethick= (thick) |
---|
715 | DrawLine x0,y0, x1,y1 |
---|
716 | End |
---|
717 | |
---|
718 | //draws a line to the right of the beamcenter (x0,y0) |
---|
719 | //angle is phi |
---|
720 | //thickness is thick |
---|
721 | //color is (rr,gg,bb) |
---|
722 | // function determines where the line will cross the edge of the image, and stops the line there. |
---|
723 | Function DrawALineRight(x0,y0,phi,rr,gg,bb,thick) |
---|
724 | Variable x0,y0,phi,rr,gg,bb,thick |
---|
725 | |
---|
726 | Variable slope,intcp,x1,y1 |
---|
727 | |
---|
728 | slope = tan(phi*Pi/180) //need arg in radians, not degrees |
---|
729 | if ( phi == 90 ) |
---|
730 | slope = Inf |
---|
731 | Endif |
---|
732 | If (phi == -90) |
---|
733 | slope = -Inf |
---|
734 | Endif |
---|
735 | intcp = y0 - slope * x0 |
---|
736 | x1 = FindXRight(x0,y0,slope,intcp) |
---|
737 | y1 = FindYRight(x0,y0,slope,intcp) |
---|
738 | |
---|
739 | DoWindow/F SANS_Data |
---|
740 | SetDrawLayer UserFront |
---|
741 | SetDrawEnv xcoord= bottom,ycoord= left,linefgc= (rr,gg,bb),linethick= (thick) |
---|
742 | DrawLine x0,y0, x1,y1 |
---|
743 | End |
---|
744 | |
---|
745 | //reads the value from the panel and updates the global string |
---|
746 | // redraws the appropriate line on the image |
---|
747 | Function DeltaPhiSetVarProc(ctrlName,varNum,varStr,varName) : SetVariableControl |
---|
748 | String ctrlName |
---|
749 | Variable varNum |
---|
750 | String varStr |
---|
751 | String varName |
---|
752 | |
---|
753 | ControlInfo/W=Average_Panel dphi_p |
---|
754 | Variable dphi = V_Value |
---|
755 | SVAR tempStr = root:myGlobals:Drawing:gDrawInfoStr |
---|
756 | String newStr = ReplaceNumberByKey("DPHI", tempStr, dphi, "=", ";") |
---|
757 | |
---|
758 | String/G root:myGlobals:Drawing:gDrawInfoStr = newStr |
---|
759 | |
---|
760 | //redraw the angles |
---|
761 | MasterAngleDraw() |
---|
762 | End |
---|
763 | |
---|
764 | //reads the value from the panel and updates the global string |
---|
765 | // redraws the appropriate line on the image |
---|
766 | Function QDeltaSetVarProc(ctrlName,varNum,varStr,varName) : SetVariableControl |
---|
767 | String ctrlName |
---|
768 | Variable varNum |
---|
769 | String varStr |
---|
770 | String varName |
---|
771 | |
---|
772 | ControlInfo/W=Average_Panel QDelta_p |
---|
773 | Variable dq = V_Value |
---|
774 | SVAR tempStr = root:myGlobals:Drawing:gDrawInfoStr |
---|
775 | String newStr = ReplaceNumberByKey("QDELTA", tempStr, dq, "=", ";") |
---|
776 | |
---|
777 | String/G root:myGlobals:Drawing:gDrawInfoStr = newStr |
---|
778 | |
---|
779 | //redraw the angles |
---|
780 | MasterAngleDraw() |
---|
781 | End |
---|
782 | |
---|
783 | //reads the value from the panel and updates the global string |
---|
784 | // redraws the appropriate line on the image |
---|
785 | Function QctrSetVarProc(ctrlName,varNum,varStr,varName) : SetVariableControl |
---|
786 | String ctrlName |
---|
787 | Variable varNum |
---|
788 | String varStr |
---|
789 | String varName |
---|
790 | |
---|
791 | ControlInfo/W=Average_Panel QCtr_p |
---|
792 | Variable ctr = V_Value |
---|
793 | SVAR tempStr = root:myGlobals:Drawing:gDrawInfoStr |
---|
794 | String newStr = ReplaceNumberByKey("QCENTER", tempStr, ctr, "=", ";") |
---|
795 | |
---|
796 | String/G root:myGlobals:Drawing:gDrawInfoStr = newStr |
---|
797 | |
---|
798 | //redraw the angles |
---|
799 | MasterAngleDraw() |
---|
800 | End |
---|
801 | |
---|
802 | //reads the value from the panel and updates the global string |
---|
803 | // redraws the appropriate line on the image |
---|
804 | Function WidthSetVarProc(ctrlName,varNum,varStr,varName) : SetVariableControl |
---|
805 | String ctrlName |
---|
806 | Variable varNum |
---|
807 | String varStr |
---|
808 | String varName |
---|
809 | |
---|
810 | ControlInfo/W=Average_Panel width_p |
---|
811 | Variable val = V_Value |
---|
812 | SVAR tempStr = root:myGlobals:Drawing:gDrawInfoStr |
---|
813 | String newStr = ReplaceNumberByKey("WIDTH", tempStr, val, "=", ";") |
---|
814 | |
---|
815 | String/G root:myGlobals:Drawing:gDrawInfoStr = newStr |
---|
816 | |
---|
817 | //redraw the angles |
---|
818 | MasterAngleDraw() |
---|
819 | End |
---|
820 | |
---|
821 | //function is called directly by averaging routines to display the averaged data |
---|
822 | //copies the newly averaged data (finds the data folder from the parameter waves) |
---|
823 | //the the copied data can be rescaled without disturbing the original data |
---|
824 | // |
---|
825 | // brings the plot_1d to the front |
---|
826 | // if no window, create the folder and globals |
---|
827 | // update the data |
---|
828 | // |
---|
829 | //there is a separate function for annular averages (I vs phi) |
---|
830 | Function Avg_1D_Graph(aveint,qval,sigave) |
---|
831 | Wave aveint,qval,sigave |
---|
832 | |
---|
833 | if(! DataFolderExists("root:myGlobals:plot_1d")) |
---|
834 | Init_Plot1d() |
---|
835 | endif |
---|
836 | |
---|
837 | // String curPath = GetWavesDataFolder(aveint,1) |
---|
838 | String CurPath="root:myGlobals:Plot_1D:" |
---|
839 | |
---|
840 | Duplicate/O aveint $(curPath+"yAxisWave") |
---|
841 | Duplicate/O sigave $(curPath+"yErrWave") |
---|
842 | Duplicate/O qval $(curPath+"xAxisWave") |
---|
843 | Wave yAxisWave=$(curPath+"yAxisWave") |
---|
844 | Wave xAxisWave=$(curPath+"xAxisWave") |
---|
845 | Wave yErrWave=$(curPath+"yErrWave") |
---|
846 | |
---|
847 | Variable/G root:myGlobals:Plot_1d:isPhiAve=0 //0 signifies (normal) x=qvals |
---|
848 | //make a completely new graph |
---|
849 | Draw_Plot1D(xAxisWave,yAxisWave,YErrWave) |
---|
850 | |
---|
851 | return(0) |
---|
852 | End |
---|
853 | |
---|
854 | //function is called directly by averaging routines to display the averaged data |
---|
855 | //copies the newly averaged data (finds the data folder from the parameter waves) |
---|
856 | //the the copied data can be rescaled without disturbing the original data |
---|
857 | // |
---|
858 | // brings the plot_1d to the front |
---|
859 | // if no window, create the folder and globals |
---|
860 | // update the data |
---|
861 | // |
---|
862 | Function Ann_1D_Graph(aveint,phival,sigave) |
---|
863 | Wave aveint,phival,sigave |
---|
864 | |
---|
865 | if(! DataFolderExists("root:myGlobals:plot_1d")) |
---|
866 | Init_Plot1d() |
---|
867 | endif |
---|
868 | // String curPath = GetWavesDataFolder(aveint,1) |
---|
869 | String CurPath="root:myGlobals:Plot_1D:" |
---|
870 | |
---|
871 | Duplicate/O aveint $(curPath+"yAxisWave") |
---|
872 | Duplicate/O sigave $(curPath+"yErrWave") |
---|
873 | Duplicate/O phival $(curPath+"xAxisWave") |
---|
874 | Wave yAxisWave=$(curPath+"yAxisWave") |
---|
875 | Wave xAxisWave=$(curPath+"xAxisWave") |
---|
876 | Wave yErrWave=$(curPath+"yErrWave") |
---|
877 | |
---|
878 | Variable/G root:myGlobals:Plot_1d:isPhiAve=1 //1 signifies x=phival |
---|
879 | //make a completely new graph |
---|
880 | Draw_Plot1D(xAxisWave,yAxisWave,YErrWave) |
---|
881 | |
---|
882 | return(0) |
---|
883 | End |
---|
884 | |
---|
885 | //initializes the scaling exponents and x-axis flag used in the control bar of the |
---|
886 | //plot_1d graph |
---|
887 | // ! keep the user-defined values when re-creating the graph, so don't re-initialize the globals |
---|
888 | Function Init_Plot1d() |
---|
889 | NewDataFolder/O/S root:myGlobals:Plot_1d |
---|
890 | NVAR/Z gExpA=gExpA |
---|
891 | NVAR/Z gExpB=gExpB |
---|
892 | NVAR/Z gExpC=gExpC |
---|
893 | NVAR/Z gXMode=gXMode |
---|
894 | NVAR/Z gYMode=gYMode |
---|
895 | if(!NVAR_Exists(gExpA)) |
---|
896 | Variable/G gExpA=1 |
---|
897 | endif |
---|
898 | if(!NVAR_Exists(gExpB)) |
---|
899 | Variable/G gExpB=1 |
---|
900 | endif |
---|
901 | if(!NVAR_Exists(gExpC)) |
---|
902 | Variable/G gExpC=1 |
---|
903 | endif |
---|
904 | //keep preferences of the display mode (axis scaling) |
---|
905 | if(!NVAR_Exists(gXMode)) |
---|
906 | Variable/G gXMode=1 |
---|
907 | endif |
---|
908 | if(!NVAR_Exists(gYMode)) |
---|
909 | Variable/G gYMode=1 |
---|
910 | endif |
---|
911 | Variable/G isPhiAve=0 //0= vs Q, 1= vs phi, alway set properly as needed by the Avg_ or Ann_1D_Graph() |
---|
912 | SetDataFolder root: |
---|
913 | End |
---|
914 | |
---|
915 | //function responsible for drawing the 1D plot, given the three necessary waves |
---|
916 | // x-axis label is determined from global "isPhiAve" switch |
---|
917 | // |
---|
918 | // plot type is recalled through globals |
---|
919 | // |
---|
920 | Function Draw_Plot1D(xw,yw,ew) |
---|
921 | Wave xw,yw,ew |
---|
922 | |
---|
923 | if(! DataFolderExists("root:myGlobals:plot_1d")) |
---|
924 | Init_Plot1d() |
---|
925 | endif |
---|
926 | DoWindow/F Plot_1d |
---|
927 | if(V_flag==1) |
---|
928 | //do nothing |
---|
929 | else |
---|
930 | Display /W=(476,96,850,429) /K=1 yw vs xw |
---|
931 | DoWindow/C Plot_1d |
---|
932 | DoWindow/T Plot_1d,"Averaged Data" |
---|
933 | ModifyGraph marker=19 |
---|
934 | ModifyGraph mode=3,msize=2,rgb=(65535,0,0) |
---|
935 | // |
---|
936 | String list=TraceNameList("",";", 1) |
---|
937 | String yname=StringFromList(0, list,";") |
---|
938 | ErrorBars $yname Y,wave=(ew,ew) |
---|
939 | ModifyGraph grid=1 |
---|
940 | ModifyGraph log=0 |
---|
941 | ModifyGraph mirror=2 |
---|
942 | ModifyGraph standoff=0 |
---|
943 | ModifyGraph tickUnit=1 |
---|
944 | ControlBar 70 |
---|
945 | PopupMenu ymodel,pos={16,5},size={71,20},title="y-axis" |
---|
946 | PopupMenu ymodel,help={"This popup selects how the y-axis will be linearized based on the chosen data"} |
---|
947 | PopupMenu ymodel,value= #"\"I;log(I);ln(I);1/I;I^a;Iq^a;I^a q^b;1/sqrt(I);ln(Iq);ln(Iq^2)\"" |
---|
948 | PopupMenu ymodel,mode=NumVarOrDefault("root:myGlobals:Plot_1d:gYMode", 1 ),proc=YMode_PopMenuProc |
---|
949 | Button Rescale,pos={281,4},size={70,20},proc=Rescale_Plot_1D_ButtonProc,title="Rescale" |
---|
950 | Button Rescale,help={"Rescale the x and y-axes of the data"},disable=1 |
---|
951 | Button AllQ,pos={281,28},size={70,20},proc=AllQ_Plot_1D_ButtonProc,title="All Q" |
---|
952 | Button AllQ,help={"Show the full q-range of the dataset"} |
---|
953 | SetVariable expa,pos={28,28},size={80,15},title="pow \"a\"" |
---|
954 | SetVariable expa,help={"This sets the exponent \"a\" for some y-axis formats. The value is ignored if the model does not use an adjustable exponent"} |
---|
955 | SetVariable expa,limits={-2,10,0},value= root:myGlobals:Plot_1d:gExpA |
---|
956 | SetVariable expb,pos={27,46},size={80,15},title="pow \"b\"" |
---|
957 | SetVariable expb,help={"This sets the exponent \"b\" for some x-axis formats. The value is ignored if the model does not use an adjustable exponent"} |
---|
958 | SetVariable expb,limits={0,10,0},value= root:myGlobals:Plot_1d:gExpB |
---|
959 | PopupMenu xmodel,pos={150,5},size={74,20},title="x-axis" |
---|
960 | PopupMenu xmodel,help={"This popup selects how the x-axis will be linearized given the chosen data"} |
---|
961 | PopupMenu xmodel,value= #"\"q;log(q);q^2;q^c\"" |
---|
962 | PopupMenu xmodel,mode=NumVarOrDefault("root:myGlobals:Plot_1d:gXMode", 1 ),proc=XMode_PopMenuProc |
---|
963 | SetVariable expc,pos={167,28},size={80,15},title="pow \"c\"" |
---|
964 | SetVariable expc,help={"This sets the exponent \"c\" for some x-axis formats. The value is ignored if the model does not use \"c\" as an adjustable exponent"} |
---|
965 | SetVariable expc,limits={-10,10,0},value= root:myGlobals:Plot_1d:gExpC |
---|
966 | |
---|
967 | endif |
---|
968 | NVAR isPhiAve= root:myGlobals:Plot_1d:isPhiAve //0 signifies (normal) x=qvals |
---|
969 | Label left "I(q)" |
---|
970 | if(isPhiAve) |
---|
971 | Label bottom "Angle (deg)" |
---|
972 | else |
---|
973 | SVAR angst = root:myGlobals:gAngstStr |
---|
974 | Label bottom "q ("+angst+"\\S-1\\M)" |
---|
975 | Endif |
---|
976 | //force a rescale to get something other than I vs. q |
---|
977 | Rescale_Plot_1D_ButtonProc("") |
---|
978 | End |
---|
979 | |
---|
980 | //function to set the popItem (mode) of the graph, to re-create the graph based on user preferences |
---|
981 | Function YMode_PopMenuProc(ctrlName,popNum,popStr) : PopupMenuControl |
---|
982 | String ctrlName |
---|
983 | Variable popNum |
---|
984 | String popStr |
---|
985 | |
---|
986 | Variable/G root:myGlobals:Plot_1d:gYMode=popNum |
---|
987 | Rescale_Plot_1D_ButtonProc("") |
---|
988 | End |
---|
989 | |
---|
990 | //function to set the popItem (mode) of the graph, to re-create the graph based on user preferences |
---|
991 | Function XMode_PopMenuProc(ctrlName,popNum,popStr) : PopupMenuControl |
---|
992 | String ctrlName |
---|
993 | Variable popNum |
---|
994 | String popStr |
---|
995 | |
---|
996 | Variable/G root:myGlobals:Plot_1d:gXMode=popNum |
---|
997 | Rescale_Plot_1D_ButtonProc("") |
---|
998 | End |
---|
999 | |
---|
1000 | //function to restore the graph axes to full scale, undoing any zooming |
---|
1001 | Function AllQ_Plot_1D_ButtonProc(ctrlName) : ButtonControl |
---|
1002 | String ctrlName |
---|
1003 | |
---|
1004 | DoWindow/F Plot_1d |
---|
1005 | SetAxis/A |
---|
1006 | End |
---|
1007 | |
---|
1008 | //function to rescale the axes of the graph as selected from the popups and the |
---|
1009 | // entered values of the exponents |
---|
1010 | //** assumes the current waves are unknown, so it goes and gets a "fresh" copy from |
---|
1011 | //the data folder specified by the waves on the graph, which is the same folder that |
---|
1012 | //contains the "fresh" copy of the 1D data |
---|
1013 | // |
---|
1014 | // for log(10) scaling, simply modify the axes, not the data - gives better plots |
---|
1015 | // |
---|
1016 | Function Rescale_Plot_1D_ButtonProc(ctrlName) : ButtonControl |
---|
1017 | String ctrlName |
---|
1018 | |
---|
1019 | DoWindow/F Plot_1d |
---|
1020 | //Scaling exponents and background value |
---|
1021 | Variable pow_a,pow_b,pow_c |
---|
1022 | ControlInfo expa |
---|
1023 | pow_a = V_value |
---|
1024 | ControlInfo expb |
---|
1025 | pow_b = V_value |
---|
1026 | ControlInfo expc |
---|
1027 | pow_c = V_value |
---|
1028 | |
---|
1029 | //check for physical limits on exponent values, abort if bad values found |
---|
1030 | if((pow_a < -2) || (pow_a > 10)) |
---|
1031 | Abort "Exponent a must be in the range (-2,10)" |
---|
1032 | endif |
---|
1033 | if((pow_b < 0) || (pow_b > 10)) |
---|
1034 | Abort "Exponent b must be in the range (0,10)" |
---|
1035 | endif |
---|
1036 | //if q^c is the x-scaling, c must be be within limits and also non-zero |
---|
1037 | ControlInfo xModel |
---|
1038 | If (cmpstr("q^c",S_Value) == 0) |
---|
1039 | if(pow_c == 0) |
---|
1040 | Abort "Exponent c must be non-zero, q^0 = 1" |
---|
1041 | endif |
---|
1042 | if((pow_c < -10) || (pow_c > 10)) |
---|
1043 | Abort "Exponent c must be in the range (-10,10)" |
---|
1044 | endif |
---|
1045 | endif //check q^c exponent |
---|
1046 | |
---|
1047 | // get the current experimental q, I, and std dev. waves |
---|
1048 | |
---|
1049 | //!! get the wave path from the window and construct the necessary wave |
---|
1050 | //references to the unmodified, averaged data (qval, aveint) |
---|
1051 | //and use these to modify the (xAxisWave,YAxisWave) that are on the graph |
---|
1052 | String dfSav = GetDataFolder(1) |
---|
1053 | //String curPath = GetWavesDataFolder(WaveRefIndexed("",0,1),1) //path for the first y-wave on the graph |
---|
1054 | SVAR curFolder=root:myGlobals:gDataDisplayType |
---|
1055 | |
---|
1056 | // SetDataFolder curPath |
---|
1057 | //get the untarnished data, so we can rescale it freshly here |
---|
1058 | Wave yw = $("root:"+curFolder+":aveint") |
---|
1059 | Wave ew = $("root:"+curFolder+":sigave") |
---|
1060 | //get the correct x values |
---|
1061 | NVAR isPhiAve= root:myGlobals:Plot_1d:isPhiAve //0 signifies (normal) x=qvals |
---|
1062 | if(isPhiAve) |
---|
1063 | //x is angle |
---|
1064 | Wave xw=$("root:"+curFolder+":phival") |
---|
1065 | else |
---|
1066 | //x is q-values |
---|
1067 | Wave xw=$("root:"+curFolder+":qval") |
---|
1068 | endif |
---|
1069 | Wave yAxisWave=root:myGlobals:Plot_1d:yAxisWave //refs to waves to be modified, hard-wired positions |
---|
1070 | Wave xAxisWave=root:myGlobals:Plot_1d:xAxisWave |
---|
1071 | Wave yErrWave=root:myGlobals:Plot_1d:yErrWave |
---|
1072 | |
---|
1073 | //variables set for each model to control look of graph |
---|
1074 | String xlabel,ylabel,xstr,ystr |
---|
1075 | Variable logLeft=0,logBottom=0 |
---|
1076 | //check for proper y-scaling selection, make the necessary waves |
---|
1077 | ControlInfo yModel |
---|
1078 | ystr = S_Value |
---|
1079 | do |
---|
1080 | If (cmpstr("I",S_Value) == 0) |
---|
1081 | SetScale d 0,0,"1/cm",yAxisWave |
---|
1082 | yErrWave = ew |
---|
1083 | yAxisWave = yw |
---|
1084 | ylabel = "I(q)" |
---|
1085 | break |
---|
1086 | endif |
---|
1087 | If (cmpstr("ln(I)",S_Value) == 0) |
---|
1088 | SetScale d 0,0,"",yAxisWave |
---|
1089 | yErrWave = ew/yw |
---|
1090 | yAxisWave = ln(yw) |
---|
1091 | ylabel = "ln(I)" |
---|
1092 | break |
---|
1093 | endif |
---|
1094 | If (cmpstr("log(I)",S_Value) == 0) |
---|
1095 | SetScale d 0,0,"",yAxisWave |
---|
1096 | yAxisWave = yw |
---|
1097 | yErrWave = ew |
---|
1098 | logLeft=1 //scale the axis, not the wave |
---|
1099 | ylabel = "I(q)" |
---|
1100 | // yErrWave = ew/(2.30*yw) |
---|
1101 | // yAxisWave = log(yw) |
---|
1102 | // ylabel = "log(I)" |
---|
1103 | break |
---|
1104 | endif |
---|
1105 | If (cmpstr("1/I",S_Value) == 0) |
---|
1106 | SetScale d 0,0,"",yAxisWave |
---|
1107 | yErrWave = ew/yw^2 |
---|
1108 | yAxisWave = 1/yw |
---|
1109 | ylabel = "1/I" |
---|
1110 | break |
---|
1111 | endif |
---|
1112 | If (cmpstr("I^a",S_Value) == 0) |
---|
1113 | SetScale d 0,0,"",yAxisWave |
---|
1114 | yErrWave = ew*abs(pow_a*(yw^(pow_a-1))) |
---|
1115 | yAxisWave = yw^pow_a |
---|
1116 | ylabel = "I^"+num2str(pow_a) |
---|
1117 | break |
---|
1118 | endif |
---|
1119 | If (cmpstr("Iq^a",S_Value) == 0) |
---|
1120 | SetScale d 0,0,"",yAxisWave |
---|
1121 | yErrWave = ew*xw^pow_a |
---|
1122 | yAxisWave = yw*xw^pow_a |
---|
1123 | ylabel = "I*q^"+num2str(pow_a) |
---|
1124 | break |
---|
1125 | endif |
---|
1126 | If (cmpstr("I^a q^b",S_Value) == 0) |
---|
1127 | SetScale d 0,0,"",yAxisWave |
---|
1128 | yErrWave = ew*abs(pow_a*(yw^(pow_a-1)))*xw^pow_b |
---|
1129 | yAxisWave = yw^pow_a*xw^pow_b |
---|
1130 | ylabel = "I^" + num2str(pow_a) + "q^"+num2str(pow_b) |
---|
1131 | break |
---|
1132 | endif |
---|
1133 | If (cmpstr("1/sqrt(I)",S_Value) == 0) |
---|
1134 | SetScale d 0,0,"",yAxisWave |
---|
1135 | yErrWave = 0.5*ew*yw^(-1.5) |
---|
1136 | yAxisWave = 1/sqrt(yw) |
---|
1137 | ylabel = "1/sqrt(I)" |
---|
1138 | break |
---|
1139 | endif |
---|
1140 | If (cmpstr("ln(Iq)",S_Value) == 0) |
---|
1141 | SetScale d 0,0,"",yAxisWave |
---|
1142 | yErrWave =ew/yw |
---|
1143 | yAxisWave = ln(xw*yw) |
---|
1144 | ylabel = "ln(q*I)" |
---|
1145 | break |
---|
1146 | endif |
---|
1147 | If (cmpstr("ln(Iq^2)",S_Value) == 0) |
---|
1148 | SetScale d 0,0,"",yAxisWave |
---|
1149 | yErrWave = ew/yw |
---|
1150 | yAxisWave = ln(xw*xw*yw) |
---|
1151 | ylabel = "ln(I*q^2)" |
---|
1152 | break |
---|
1153 | endif |
---|
1154 | //more ifs for each case as they are added |
---|
1155 | |
---|
1156 | // if selection not found, abort |
---|
1157 | DoAlert 0,"Y-axis scaling incorrect. Aborting" |
---|
1158 | Abort |
---|
1159 | while(0) //end of "case" statement for y-axis scaling |
---|
1160 | |
---|
1161 | //check for proper x-scaling selection |
---|
1162 | SVAR angst = root:myGlobals:gAngstStr |
---|
1163 | String dum |
---|
1164 | |
---|
1165 | ControlInfo xModel |
---|
1166 | xstr = S_Value |
---|
1167 | do |
---|
1168 | If (cmpstr("q",S_Value) == 0) |
---|
1169 | SetScale d 0,0,"",xAxisWave |
---|
1170 | xAxisWave = xw |
---|
1171 | if(isPhiAve) |
---|
1172 | xlabel="Angle (deg)" |
---|
1173 | else |
---|
1174 | xlabel = "q ("+angst+"\\S-1\\M)" |
---|
1175 | endif |
---|
1176 | break |
---|
1177 | endif |
---|
1178 | If (cmpstr("q^2",S_Value) == 0) |
---|
1179 | SetScale d 0,0,"",xAxisWave |
---|
1180 | xAxisWave = xw*xw |
---|
1181 | if(isPhiAve) |
---|
1182 | xlabel="(Angle (deg) )^2" |
---|
1183 | else |
---|
1184 | xlabel = "q^2 ("+angst+"\\S-2\\M)" |
---|
1185 | endif |
---|
1186 | break |
---|
1187 | endif |
---|
1188 | If (cmpstr("log(q)",S_Value) == 0) |
---|
1189 | SetScale d 0,0,"",xAxisWave |
---|
1190 | xAxisWave = xw //scale the axis, not the wave |
---|
1191 | //xAxisWave = log(xw) |
---|
1192 | logBottom=1 |
---|
1193 | if(isPhiAve) |
---|
1194 | //xlabel="log(Angle (deg))" |
---|
1195 | xlabel="Angle (deg)" |
---|
1196 | else |
---|
1197 | //xlabel = "log(q)" |
---|
1198 | xlabel = "q ("+angst+"\\S-1\\M)" |
---|
1199 | endif |
---|
1200 | break |
---|
1201 | endif |
---|
1202 | If (cmpstr("q^c",S_Value) == 0) |
---|
1203 | SetScale d 0,0,"",xAxisWave |
---|
1204 | xAxisWave = xw^pow_c |
---|
1205 | dum = num2str(pow_c) |
---|
1206 | if(isPhiAve) |
---|
1207 | xlabel="Angle^"+dum |
---|
1208 | else |
---|
1209 | xlabel = "q^"+dum+" ("+angst+"\\S-"+dum+"\\M)" |
---|
1210 | endif |
---|
1211 | break |
---|
1212 | endif |
---|
1213 | |
---|
1214 | //more ifs for each case |
---|
1215 | |
---|
1216 | // if selection not found, abort |
---|
1217 | DoAlert 0,"X-axis scaling incorrect. Aborting" |
---|
1218 | Abort |
---|
1219 | while(0) //end of "case" statement for x-axis scaling |
---|
1220 | |
---|
1221 | Label left ylabel |
---|
1222 | Label bottom xlabel //E denotes "scaling" - may want to use "units" instead |
---|
1223 | ModifyGraph log(left)=(logLeft) |
---|
1224 | ModifyGraph log(bottom)=(logBottom) |
---|
1225 | |
---|
1226 | End |
---|
1227 | |
---|