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/Z/K=1 "SANS Data Reduction Tutorial[Average Options]" |
---|
321 | if(V_flag !=0) |
---|
322 | DoAlert 0,"The SANS Data Reduction Tutorial Help file could not be found" |
---|
323 | endif |
---|
324 | end |
---|
325 | |
---|
326 | //Sets global key=value for drawing phi-line on graph |
---|
327 | //and redraws the angles |
---|
328 | Function PhiSetVarProc(ctrlName,varNum,varStr,varName) : SetVariableControl |
---|
329 | String ctrlName |
---|
330 | Variable varNum |
---|
331 | String varStr |
---|
332 | String varName |
---|
333 | |
---|
334 | ControlInfo/W=Average_Panel phi_p |
---|
335 | Variable phi = V_Value |
---|
336 | SVAR tempStr = root:myGlobals:Drawing:gDrawInfoStr |
---|
337 | String newStr = ReplaceNumberByKey("PHI", tempStr, phi, "=", ";") |
---|
338 | |
---|
339 | String/G root:myGlobals:Drawing:gDrawInfoStr = newStr |
---|
340 | |
---|
341 | //redraw the angles |
---|
342 | MasterAngleDraw() |
---|
343 | End |
---|
344 | |
---|
345 | //draws all of the lines specified by the global keyword string |
---|
346 | //clears the old lines, and parses the string |
---|
347 | Function MasterAngleDraw() |
---|
348 | //takes the global gDrawInfoStr and Parses it to determine what to redraw on the graph |
---|
349 | |
---|
350 | //first clear the old draw Layer |
---|
351 | DoWindow/F SANS_Data |
---|
352 | if(V_flag ==0) |
---|
353 | Abort "No SANS data. Use'Display Raw Data' to display a 2D data file" |
---|
354 | Endif |
---|
355 | SetDrawLayer/K UserFront |
---|
356 | SetDrawLayer UserFront |
---|
357 | |
---|
358 | //what average type are we drawing for? |
---|
359 | SVAR drawStr = root:myGlobals:Drawing:gDrawInfoStr |
---|
360 | |
---|
361 | //get the beam center from the currently displayed data type |
---|
362 | SVAR type = root:myGlobals:gDataDisplayType |
---|
363 | Wave reals = $("root:"+type+":RealsRead") |
---|
364 | Variable x0,y0,x1,y1 |
---|
365 | x0 = reals[16] - 1 //convert to [0,127] from (1,128) detector |
---|
366 | y0 = reals[17] - 1 |
---|
367 | |
---|
368 | //right, left, or both halves? |
---|
369 | //what type of average? |
---|
370 | String side = StringByKey("SIDE",drawStr,"=",";") |
---|
371 | String av_type = StringByKey("AVTYPE",drawStr,"=",";") |
---|
372 | Variable phi = NumberByKey("PHI",drawStr,"=",";") |
---|
373 | Variable dphi = NumberByKey("DPHI",drawStr,"=",";") |
---|
374 | Variable width = NumberByKey("WIDTH",drawStr,"=",";") |
---|
375 | |
---|
376 | Variable delx,dely,slope,intcp,rr,gg,bb,thick |
---|
377 | rr = 0 |
---|
378 | gg = 0 |
---|
379 | bb = 0 |
---|
380 | thick = 2 |
---|
381 | |
---|
382 | //if circular average, just get out |
---|
383 | if(cmpstr(av_type,"Circular")==0) |
---|
384 | //clear the drawing |
---|
385 | // DoWindow/F SANS_Data |
---|
386 | // SetDrawLayer/K UserFront |
---|
387 | //go back to the average panel |
---|
388 | DoWindow/F Average_Panel |
---|
389 | |
---|
390 | Return 0 //exit the Draw routine |
---|
391 | Endif |
---|
392 | |
---|
393 | //handle sector-type and annular type averages differently |
---|
394 | if(cmpstr(av_type,"Annular")==0) |
---|
395 | //do the annular drawing |
---|
396 | //need to go from q-value to y-axis value (since x will shift a lot) |
---|
397 | //and make sure that the (radius) is allowable for drawing |
---|
398 | Variable sdd=reals[18],lam=reals[26] |
---|
399 | |
---|
400 | sdd *=100 //convert to cm |
---|
401 | //find the radius (from the y-direction) |
---|
402 | Variable QCtr = NumberByKey("QCENTER",drawStr,"=",";") |
---|
403 | Variable QDelta = NumberByKey("QDELTA",drawStr,"=",";") |
---|
404 | Variable thetay,dy,pixelSize |
---|
405 | |
---|
406 | pixelSize = reals[10]/10 //this is ONLY the x-direction, converted to cm |
---|
407 | thetay = 2*asin(Qctr*lam/4/Pi) |
---|
408 | dy = sdd/pixelSize*tan(thetay) //pixelSize is to convert from cm on detector to pixel |
---|
409 | |
---|
410 | rr=0 |
---|
411 | gg=50000 |
---|
412 | bb=0 |
---|
413 | DrawACircle(x0,y0,dy,rr,gg,bb,thick) |
---|
414 | |
---|
415 | //then do the +/- Qdelta rings |
---|
416 | //QDelta is the width of the annulus, in pixels |
---|
417 | rr=0 |
---|
418 | gg=0 |
---|
419 | bb=50000 |
---|
420 | DrawACircle(x0,y0,dy+(QDelta/2),rr,gg,bb,thick) |
---|
421 | // then the (- delta) ring |
---|
422 | DrawACircle(x0,y0,dy-(QDelta/2),rr,gg,bb,thick) |
---|
423 | |
---|
424 | //go back to the average panel |
---|
425 | DoWindow/F Average_Panel |
---|
426 | |
---|
427 | Return 0 //exit the Draw routine |
---|
428 | Endif |
---|
429 | |
---|
430 | //else sector or rectangular - draw the lines |
---|
431 | |
---|
432 | //if sector or rectangular, draw the phi line (on the desired side) |
---|
433 | if( (cmpstr(av_type,"Sector")==0) || (cmpstr(av_type,"Rectangular")==0)) |
---|
434 | if( (cmpstr(side,"left")==0) || (cmpstr(side,"both")==0) ) |
---|
435 | //draw the phi line on the left side |
---|
436 | //make sure x1,y1 is on the edge of the graph |
---|
437 | rr = 0 |
---|
438 | gg = 65535 |
---|
439 | bb = 0 |
---|
440 | DrawALineLeft(x0,y0,phi,rr,gg,bb,thick) |
---|
441 | Endif |
---|
442 | if( (cmpstr(side,"right")==0) || (cmpstr(side,"both")==0) ) |
---|
443 | //Draw the phi line on the right side |
---|
444 | //make sure x1,y1 is on the edge of the graph |
---|
445 | rr = 0 |
---|
446 | gg = 65535 |
---|
447 | bb = 0 |
---|
448 | DrawALineRight(x0,y0,phi,rr,gg,bb,thick) |
---|
449 | Endif |
---|
450 | Endif |
---|
451 | |
---|
452 | //if Sector, draw the +/- dphi lines |
---|
453 | if (cmpstr(av_type,"Sector")==0) |
---|
454 | if( (cmpstr(side,"left")==0) || (cmpstr(side,"both")==0) ) |
---|
455 | //draw the deltaPhi lines +/- lines |
---|
456 | if (dphi != 0) |
---|
457 | rr=0 |
---|
458 | gg = 0 |
---|
459 | bb = 50000 |
---|
460 | if (phi < 0 ) |
---|
461 | DrawALineLeft(x0,y0,phi+ dphi,rr,gg,bb,thick) |
---|
462 | if ( (abs(phi)+dphi) <= 90) |
---|
463 | DrawALineLeft(x0,y0,phi- dphi,rr,gg,bb,thick) |
---|
464 | else |
---|
465 | DrawALineRight(x0,y0,phi- dphi,rr,gg,bb,thick) |
---|
466 | Endif |
---|
467 | else |
---|
468 | if((phi+dphi) > 90) |
---|
469 | DrawALineRight(x0,y0,phi+ dphi,rr,gg,bb,thick) |
---|
470 | else |
---|
471 | DrawALineLeft(x0,y0,phi+ dphi,rr,gg,bb,thick) |
---|
472 | Endif |
---|
473 | DrawALineLeft(x0,y0,phi- dphi,rr,gg,bb,thick) |
---|
474 | Endif //phi<0 |
---|
475 | Endif //dphi !=0 |
---|
476 | Endif //left or both |
---|
477 | if( (cmpstr(side,"right")==0) || (cmpstr(side,"both")==0) ) |
---|
478 | //draw the deltaPhi lines +/- lines |
---|
479 | if (dphi != 0) |
---|
480 | rr = 0 |
---|
481 | gg = 0 |
---|
482 | bb = 50000 |
---|
483 | if (phi < 0 ) |
---|
484 | DrawALineRight(x0,y0,phi+ dphi,rr,gg,bb,thick) |
---|
485 | if ( (abs(phi)+dphi) <= 90) |
---|
486 | DrawALineRight(x0,y0,phi- dphi,rr,gg,bb,thick) |
---|
487 | else |
---|
488 | DrawALineLeft(x0,y0,phi- dphi,rr,gg,bb,thick) |
---|
489 | Endif |
---|
490 | else |
---|
491 | if((phi+dphi) > 90) |
---|
492 | DrawALineLeft(x0,y0,phi+ dphi,rr,gg,bb,thick) |
---|
493 | else |
---|
494 | DrawALineRight(x0,y0,phi+ dphi,rr,gg,bb,thick) |
---|
495 | Endif |
---|
496 | DrawALineRight(x0,y0,phi- dphi,rr,gg,bb,thick) |
---|
497 | Endif //phi<0 |
---|
498 | Endif //dphi !=0 |
---|
499 | Endif //right or both |
---|
500 | Endif //if sector, draw dphi lines |
---|
501 | |
---|
502 | //if rectangular, draw the parallel rectangle lines |
---|
503 | Variable xOffset,yOffset,beta |
---|
504 | if (cmpstr(av_type,"Rectangular")==0) |
---|
505 | beta = (90-phi)*Pi/180 |
---|
506 | xOffset = (width/2)*cos(beta) //need phi in radians |
---|
507 | yOffset = (width/2)*sin(beta) |
---|
508 | if (phi == 0) |
---|
509 | xOffset = 0 |
---|
510 | yOffset = width/2 |
---|
511 | Endif |
---|
512 | if( (cmpstr(side,"left")==0) || (cmpstr(side,"both")==0) ) |
---|
513 | rr = 0 |
---|
514 | gg = 0 |
---|
515 | bb = 50000 |
---|
516 | DrawALineLeft(x0-xOffset,y0+yOffset,phi,rr,gg,bb,thick) |
---|
517 | DrawALineLeft(x0+xOffset,y0-yOffset,phi,rr,gg,bb,thick) |
---|
518 | Endif |
---|
519 | if( (cmpstr(side,"right")==0) || (cmpstr(side,"both")==0) ) |
---|
520 | rr=0 |
---|
521 | gg=0 |
---|
522 | bb=50000 |
---|
523 | DrawALineRight(x0-xOffset,y0+yOffset,phi,rr,gg,bb,thick) |
---|
524 | DrawALineRight(x0+xOffset,y0-yOffset,phi,rr,gg,bb,thick) |
---|
525 | Endif |
---|
526 | Endif |
---|
527 | |
---|
528 | //go back to the average panel |
---|
529 | DoWindow/F Average_Panel |
---|
530 | |
---|
531 | Return 0 |
---|
532 | End |
---|
533 | |
---|
534 | //given beamcenter (x0,y0) and equation of line [slope and intercept] |
---|
535 | //return the point x1 where line leaves the detector image [0,127] on the left side |
---|
536 | Function FindXLeft(x0,y0,slope,intcp) |
---|
537 | Variable x0,y0,slope,intcp |
---|
538 | |
---|
539 | Variable x1=0,yat0 |
---|
540 | NVAR pixelsX = root:myGlobals:gNPixelsX |
---|
541 | NVAR pixelsY = root:myGlobals:gNPixelsY |
---|
542 | |
---|
543 | if (slope == 0) |
---|
544 | x1 = 0 |
---|
545 | return x1 |
---|
546 | endif |
---|
547 | if ((slope == Inf) || (slope == -Inf)) |
---|
548 | x1 = x0 |
---|
549 | return x1 |
---|
550 | Endif |
---|
551 | //else we have to do some math |
---|
552 | //at x=0, what is the y-axis value? |
---|
553 | yat0 = trunc(intcp) |
---|
554 | if( (yat0 >= 0) && (yat0 <=(pixelsY-1)) ) |
---|
555 | //crosses y axis, so x1 = 0 |
---|
556 | x1 = 0 |
---|
557 | else |
---|
558 | //need crossing value |
---|
559 | if (slope > 0) |
---|
560 | x1 = trunc((0-intcp)/slope) |
---|
561 | else |
---|
562 | x1 = trunc((pixelsY-1-intcp)/slope) |
---|
563 | Endif |
---|
564 | Endif |
---|
565 | return x1 |
---|
566 | End |
---|
567 | |
---|
568 | //given beamcenter (x0,y0) and equation of line [slope and intercept] |
---|
569 | //return the point y1 where line leaves the detector image [0,127] on the left side |
---|
570 | Function FindYLeft(x0,y0,slope,intcp) |
---|
571 | Variable x0,y0,slope,intcp |
---|
572 | |
---|
573 | Variable y1=0,yat0 |
---|
574 | |
---|
575 | NVAR pixelsX = root:myGlobals:gNPixelsX |
---|
576 | NVAR pixelsY = root:myGlobals:gNPixelsY |
---|
577 | |
---|
578 | if (slope == 0) |
---|
579 | y1 = y0 |
---|
580 | return y1 |
---|
581 | endif |
---|
582 | if (slope == Inf) |
---|
583 | y1 = 0 |
---|
584 | return y1 |
---|
585 | Endif |
---|
586 | If(slope == -Inf) |
---|
587 | y1 = pixelsY-1 |
---|
588 | return y1 |
---|
589 | Endif |
---|
590 | |
---|
591 | //else we have to do some math |
---|
592 | //at x=0, what is the y-axis value? |
---|
593 | yat0 = trunc(intcp) |
---|
594 | if( (yat0 >= 0) && (yat0 <=(pixelsY-1)) ) |
---|
595 | //crosses y axis, so return y1 |
---|
596 | y1 = yat0 |
---|
597 | else |
---|
598 | //need crossing value |
---|
599 | if (yat0 < 0) |
---|
600 | y1 = 0 |
---|
601 | else |
---|
602 | y1 = pixelsY-1 |
---|
603 | Endif |
---|
604 | Endif |
---|
605 | return y1 |
---|
606 | End |
---|
607 | |
---|
608 | //given beamcenter (x0,y0) and equation of line [slope and intercept] |
---|
609 | //return the point x1 where line leaves the detector image [0,127] on the right side |
---|
610 | Function FindXRight(x0,y0,slope,intcp) |
---|
611 | Variable x0,y0,slope,intcp |
---|
612 | |
---|
613 | Variable x1=0,yat127 |
---|
614 | |
---|
615 | NVAR pixelsX = root:myGlobals:gNPixelsX |
---|
616 | NVAR pixelsY = root:myGlobals:gNPixelsY |
---|
617 | |
---|
618 | if (slope == 0) |
---|
619 | x1 = pixelsX-1 |
---|
620 | return x1 |
---|
621 | endif |
---|
622 | if ((slope == Inf) || (slope == -Inf)) |
---|
623 | x1 = x0 |
---|
624 | return x1 |
---|
625 | Endif |
---|
626 | //else we have to do some math |
---|
627 | //at x=127, what is the y-axis value? |
---|
628 | yat127 = trunc(slope*(pixelsX-1)+intcp) |
---|
629 | if( (yat127 >= 0) && (yat127 <=(pixelsY-1)) ) |
---|
630 | //crosses y=127 edge, so x1 = 127 |
---|
631 | x1 = pixelsX-1 |
---|
632 | else |
---|
633 | //need crossing value |
---|
634 | if (slope > 0) |
---|
635 | x1 = trunc((pixelsX-1-intcp)/slope) |
---|
636 | else |
---|
637 | x1 = trunc((0-intcp)/slope) |
---|
638 | Endif |
---|
639 | Endif |
---|
640 | return x1 |
---|
641 | End |
---|
642 | |
---|
643 | //given beamcenter (x0,y0) and equation of line [slope and intercept] |
---|
644 | //return the point y1 where line leaves the detector image [0,127] on the right side |
---|
645 | Function FindYRight(x0,y0,slope,intcp) |
---|
646 | Variable x0,y0,slope,intcp |
---|
647 | |
---|
648 | Variable y1=0,yat127 |
---|
649 | NVAR pixelsX = root:myGlobals:gNPixelsX |
---|
650 | NVAR pixelsY = root:myGlobals:gNPixelsY |
---|
651 | |
---|
652 | if (slope == 0) |
---|
653 | y1 = y0 |
---|
654 | return y1 |
---|
655 | endif |
---|
656 | if (slope == Inf) |
---|
657 | y1 = pixelsY-1 |
---|
658 | return y1 |
---|
659 | Endif |
---|
660 | If(slope == -Inf) |
---|
661 | y1 = 0 |
---|
662 | return y1 |
---|
663 | Endif |
---|
664 | |
---|
665 | //else we have to do some math |
---|
666 | //at x=127, what is the y-axis value? |
---|
667 | yat127 = trunc(slope*(pixelsX-1)+intcp) |
---|
668 | if( (yat127 >= 0) && (yat127 <=(pixelsY-1)) ) |
---|
669 | //crosses y axis, so return y1 |
---|
670 | y1 = yat127 |
---|
671 | else |
---|
672 | //need crossing value |
---|
673 | if (yat127 < 0) |
---|
674 | y1 = 0 |
---|
675 | else |
---|
676 | y1 = pixelsY-1 |
---|
677 | Endif |
---|
678 | Endif |
---|
679 | return y1 |
---|
680 | End |
---|
681 | |
---|
682 | //draws a circle of radius rad, centered at (x0,y0) |
---|
683 | //line thickness is thick |
---|
684 | // color is (rr,gg,bb) |
---|
685 | Function DrawACircle(x0,y0,rad,rr,gg,bb,thick) |
---|
686 | Variable x0,y0,rad,rr,gg,bb,thick |
---|
687 | |
---|
688 | DoWindow/F SANS_Data |
---|
689 | SetDrawLayer UserFront |
---|
690 | SetDrawEnv xcoord= bottom,ycoord= left,linefgc= (rr,gg,bb),linethick= (thick),fillpat=0 |
---|
691 | DrawOval x0-rad,y0+rad,x0+rad,y0-rad //left,top,right,bottom |
---|
692 | End |
---|
693 | |
---|
694 | //draws a line to the left of the beamcenter (x0,y0) |
---|
695 | //angle is phi |
---|
696 | //thickness is thick |
---|
697 | //color is (rr,gg,bb) |
---|
698 | // function determines where the line will cross the edge of the image, and stops the line there. |
---|
699 | Function DrawALineLeft(x0,y0,phi,rr,gg,bb,thick) |
---|
700 | Variable x0,y0,phi,rr,gg,bb,thick |
---|
701 | |
---|
702 | Variable slope,intcp,x1,y1 |
---|
703 | |
---|
704 | slope = tan(phi*Pi/180) //need arg in radians, not degrees |
---|
705 | if ( phi == 90 ) |
---|
706 | slope = Inf |
---|
707 | Endif |
---|
708 | If (phi == -90) |
---|
709 | slope = -Inf |
---|
710 | Endif |
---|
711 | intcp = y0 - slope * x0 |
---|
712 | x1 = FindXLeft(x0,y0,slope,intcp) |
---|
713 | y1 = FindYLeft(x0,y0,slope,intcp) |
---|
714 | |
---|
715 | DoWindow/F SANS_Data |
---|
716 | SetDrawLayer UserFront |
---|
717 | SetDrawEnv xcoord= bottom,ycoord= left,linefgc= (rr,gg,bb),linethick= (thick) |
---|
718 | DrawLine x0,y0, x1,y1 |
---|
719 | End |
---|
720 | |
---|
721 | //draws a line to the right of the beamcenter (x0,y0) |
---|
722 | //angle is phi |
---|
723 | //thickness is thick |
---|
724 | //color is (rr,gg,bb) |
---|
725 | // function determines where the line will cross the edge of the image, and stops the line there. |
---|
726 | Function DrawALineRight(x0,y0,phi,rr,gg,bb,thick) |
---|
727 | Variable x0,y0,phi,rr,gg,bb,thick |
---|
728 | |
---|
729 | Variable slope,intcp,x1,y1 |
---|
730 | |
---|
731 | slope = tan(phi*Pi/180) //need arg in radians, not degrees |
---|
732 | if ( phi == 90 ) |
---|
733 | slope = Inf |
---|
734 | Endif |
---|
735 | If (phi == -90) |
---|
736 | slope = -Inf |
---|
737 | Endif |
---|
738 | intcp = y0 - slope * x0 |
---|
739 | x1 = FindXRight(x0,y0,slope,intcp) |
---|
740 | y1 = FindYRight(x0,y0,slope,intcp) |
---|
741 | |
---|
742 | DoWindow/F SANS_Data |
---|
743 | SetDrawLayer UserFront |
---|
744 | SetDrawEnv xcoord= bottom,ycoord= left,linefgc= (rr,gg,bb),linethick= (thick) |
---|
745 | DrawLine x0,y0, x1,y1 |
---|
746 | End |
---|
747 | |
---|
748 | //reads the value from the panel and updates the global string |
---|
749 | // redraws the appropriate line on the image |
---|
750 | Function DeltaPhiSetVarProc(ctrlName,varNum,varStr,varName) : SetVariableControl |
---|
751 | String ctrlName |
---|
752 | Variable varNum |
---|
753 | String varStr |
---|
754 | String varName |
---|
755 | |
---|
756 | ControlInfo/W=Average_Panel dphi_p |
---|
757 | Variable dphi = V_Value |
---|
758 | SVAR tempStr = root:myGlobals:Drawing:gDrawInfoStr |
---|
759 | String newStr = ReplaceNumberByKey("DPHI", tempStr, dphi, "=", ";") |
---|
760 | |
---|
761 | String/G root:myGlobals:Drawing:gDrawInfoStr = newStr |
---|
762 | |
---|
763 | //redraw the angles |
---|
764 | MasterAngleDraw() |
---|
765 | End |
---|
766 | |
---|
767 | //reads the value from the panel and updates the global string |
---|
768 | // redraws the appropriate line on the image |
---|
769 | Function QDeltaSetVarProc(ctrlName,varNum,varStr,varName) : SetVariableControl |
---|
770 | String ctrlName |
---|
771 | Variable varNum |
---|
772 | String varStr |
---|
773 | String varName |
---|
774 | |
---|
775 | ControlInfo/W=Average_Panel QDelta_p |
---|
776 | Variable dq = V_Value |
---|
777 | SVAR tempStr = root:myGlobals:Drawing:gDrawInfoStr |
---|
778 | String newStr = ReplaceNumberByKey("QDELTA", tempStr, dq, "=", ";") |
---|
779 | |
---|
780 | String/G root:myGlobals:Drawing:gDrawInfoStr = newStr |
---|
781 | |
---|
782 | //redraw the angles |
---|
783 | MasterAngleDraw() |
---|
784 | End |
---|
785 | |
---|
786 | //reads the value from the panel and updates the global string |
---|
787 | // redraws the appropriate line on the image |
---|
788 | Function QctrSetVarProc(ctrlName,varNum,varStr,varName) : SetVariableControl |
---|
789 | String ctrlName |
---|
790 | Variable varNum |
---|
791 | String varStr |
---|
792 | String varName |
---|
793 | |
---|
794 | ControlInfo/W=Average_Panel QCtr_p |
---|
795 | Variable ctr = V_Value |
---|
796 | SVAR tempStr = root:myGlobals:Drawing:gDrawInfoStr |
---|
797 | String newStr = ReplaceNumberByKey("QCENTER", tempStr, ctr, "=", ";") |
---|
798 | |
---|
799 | String/G root:myGlobals:Drawing:gDrawInfoStr = newStr |
---|
800 | |
---|
801 | //redraw the angles |
---|
802 | MasterAngleDraw() |
---|
803 | End |
---|
804 | |
---|
805 | //reads the value from the panel and updates the global string |
---|
806 | // redraws the appropriate line on the image |
---|
807 | Function WidthSetVarProc(ctrlName,varNum,varStr,varName) : SetVariableControl |
---|
808 | String ctrlName |
---|
809 | Variable varNum |
---|
810 | String varStr |
---|
811 | String varName |
---|
812 | |
---|
813 | ControlInfo/W=Average_Panel width_p |
---|
814 | Variable val = V_Value |
---|
815 | SVAR tempStr = root:myGlobals:Drawing:gDrawInfoStr |
---|
816 | String newStr = ReplaceNumberByKey("WIDTH", tempStr, val, "=", ";") |
---|
817 | |
---|
818 | String/G root:myGlobals:Drawing:gDrawInfoStr = newStr |
---|
819 | |
---|
820 | //redraw the angles |
---|
821 | MasterAngleDraw() |
---|
822 | End |
---|
823 | |
---|
824 | //function is called directly by averaging routines to display the averaged data |
---|
825 | //copies the newly averaged data (finds the data folder from the parameter waves) |
---|
826 | //the the copied data can be rescaled without disturbing the original data |
---|
827 | // |
---|
828 | // brings the plot_1d to the front |
---|
829 | // if no window, create the folder and globals |
---|
830 | // update the data |
---|
831 | // |
---|
832 | //there is a separate function for annular averages (I vs phi) |
---|
833 | Function Avg_1D_Graph(aveint,qval,sigave) |
---|
834 | Wave aveint,qval,sigave |
---|
835 | |
---|
836 | if(! DataFolderExists("root:myGlobals:plot_1d")) |
---|
837 | Init_Plot1d() |
---|
838 | endif |
---|
839 | |
---|
840 | // String curPath = GetWavesDataFolder(aveint,1) |
---|
841 | String CurPath="root:myGlobals:Plot_1D:" |
---|
842 | |
---|
843 | Duplicate/O aveint $(curPath+"yAxisWave") |
---|
844 | Duplicate/O sigave $(curPath+"yErrWave") |
---|
845 | Duplicate/O qval $(curPath+"xAxisWave") |
---|
846 | Wave yAxisWave=$(curPath+"yAxisWave") |
---|
847 | Wave xAxisWave=$(curPath+"xAxisWave") |
---|
848 | Wave yErrWave=$(curPath+"yErrWave") |
---|
849 | |
---|
850 | Variable/G root:myGlobals:Plot_1d:isPhiAve=0 //0 signifies (normal) x=qvals |
---|
851 | //make a completely new graph |
---|
852 | Draw_Plot1D(xAxisWave,yAxisWave,YErrWave) |
---|
853 | |
---|
854 | return(0) |
---|
855 | End |
---|
856 | |
---|
857 | //function is called directly by averaging routines to display the averaged data |
---|
858 | //copies the newly averaged data (finds the data folder from the parameter waves) |
---|
859 | //the the copied data can be rescaled without disturbing the original data |
---|
860 | // |
---|
861 | // brings the plot_1d to the front |
---|
862 | // if no window, create the folder and globals |
---|
863 | // update the data |
---|
864 | // |
---|
865 | Function Ann_1D_Graph(aveint,phival,sigave) |
---|
866 | Wave aveint,phival,sigave |
---|
867 | |
---|
868 | if(! DataFolderExists("root:myGlobals:plot_1d")) |
---|
869 | Init_Plot1d() |
---|
870 | endif |
---|
871 | // String curPath = GetWavesDataFolder(aveint,1) |
---|
872 | String CurPath="root:myGlobals:Plot_1D:" |
---|
873 | |
---|
874 | Duplicate/O aveint $(curPath+"yAxisWave") |
---|
875 | Duplicate/O sigave $(curPath+"yErrWave") |
---|
876 | Duplicate/O phival $(curPath+"xAxisWave") |
---|
877 | Wave yAxisWave=$(curPath+"yAxisWave") |
---|
878 | Wave xAxisWave=$(curPath+"xAxisWave") |
---|
879 | Wave yErrWave=$(curPath+"yErrWave") |
---|
880 | |
---|
881 | Variable/G root:myGlobals:Plot_1d:isPhiAve=1 //1 signifies x=phival |
---|
882 | //make a completely new graph |
---|
883 | Draw_Plot1D(xAxisWave,yAxisWave,YErrWave) |
---|
884 | |
---|
885 | return(0) |
---|
886 | End |
---|
887 | |
---|
888 | //initializes the scaling exponents and x-axis flag used in the control bar of the |
---|
889 | //plot_1d graph |
---|
890 | // ! keep the user-defined values when re-creating the graph, so don't re-initialize the globals |
---|
891 | Function Init_Plot1d() |
---|
892 | NewDataFolder/O/S root:myGlobals:Plot_1d |
---|
893 | NVAR/Z gExpA=gExpA |
---|
894 | NVAR/Z gExpB=gExpB |
---|
895 | NVAR/Z gExpC=gExpC |
---|
896 | NVAR/Z gXMode=gXMode |
---|
897 | NVAR/Z gYMode=gYMode |
---|
898 | if(!NVAR_Exists(gExpA)) |
---|
899 | Variable/G gExpA=1 |
---|
900 | endif |
---|
901 | if(!NVAR_Exists(gExpB)) |
---|
902 | Variable/G gExpB=1 |
---|
903 | endif |
---|
904 | if(!NVAR_Exists(gExpC)) |
---|
905 | Variable/G gExpC=1 |
---|
906 | endif |
---|
907 | //keep preferences of the display mode (axis scaling) |
---|
908 | if(!NVAR_Exists(gXMode)) |
---|
909 | Variable/G gXMode=1 |
---|
910 | endif |
---|
911 | if(!NVAR_Exists(gYMode)) |
---|
912 | Variable/G gYMode=1 |
---|
913 | endif |
---|
914 | Variable/G isPhiAve=0 //0= vs Q, 1= vs phi, alway set properly as needed by the Avg_ or Ann_1D_Graph() |
---|
915 | SetDataFolder root: |
---|
916 | End |
---|
917 | |
---|
918 | //function responsible for drawing the 1D plot, given the three necessary waves |
---|
919 | // x-axis label is determined from global "isPhiAve" switch |
---|
920 | // |
---|
921 | // plot type is recalled through globals |
---|
922 | // |
---|
923 | Function Draw_Plot1D(xw,yw,ew) |
---|
924 | Wave xw,yw,ew |
---|
925 | |
---|
926 | if(! DataFolderExists("root:myGlobals:plot_1d")) |
---|
927 | Init_Plot1d() |
---|
928 | endif |
---|
929 | DoWindow/F Plot_1d |
---|
930 | if(V_flag==1) |
---|
931 | //do nothing |
---|
932 | else |
---|
933 | Display /W=(476,96,850,429) /K=1 yw vs xw |
---|
934 | DoWindow/C Plot_1d |
---|
935 | DoWindow/T Plot_1d,"Averaged Data" |
---|
936 | ModifyGraph marker=19 |
---|
937 | ModifyGraph mode=3,msize=2,rgb=(65535,0,0) |
---|
938 | // |
---|
939 | String list=TraceNameList("",";", 1) |
---|
940 | String yname=StringFromList(0, list,";") |
---|
941 | ErrorBars $yname Y,wave=(ew,ew) |
---|
942 | ModifyGraph grid=1 |
---|
943 | ModifyGraph log=0 |
---|
944 | ModifyGraph mirror=2 |
---|
945 | ModifyGraph standoff=0 |
---|
946 | ModifyGraph tickUnit=1 |
---|
947 | ControlBar 70 |
---|
948 | PopupMenu ymodel,pos={16,5},size={71,20},title="y-axis" |
---|
949 | PopupMenu ymodel,help={"This popup selects how the y-axis will be linearized based on the chosen data"} |
---|
950 | 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)\"" |
---|
951 | PopupMenu ymodel,mode=NumVarOrDefault("root:myGlobals:Plot_1d:gYMode", 1 ),proc=YMode_PopMenuProc |
---|
952 | Button Rescale,pos={281,4},size={70,20},proc=Rescale_Plot_1D_ButtonProc,title="Rescale" |
---|
953 | Button Rescale,help={"Rescale the x and y-axes of the data"},disable=1 |
---|
954 | Button AllQ,pos={281,28},size={70,20},proc=AllQ_Plot_1D_ButtonProc,title="All Q" |
---|
955 | Button AllQ,help={"Show the full q-range of the dataset"} |
---|
956 | SetVariable expa,pos={28,28},size={80,15},title="pow \"a\"" |
---|
957 | 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"} |
---|
958 | SetVariable expa,limits={-2,10,0},value= root:myGlobals:Plot_1d:gExpA |
---|
959 | SetVariable expb,pos={27,46},size={80,15},title="pow \"b\"" |
---|
960 | 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"} |
---|
961 | SetVariable expb,limits={0,10,0},value= root:myGlobals:Plot_1d:gExpB |
---|
962 | PopupMenu xmodel,pos={150,5},size={74,20},title="x-axis" |
---|
963 | PopupMenu xmodel,help={"This popup selects how the x-axis will be linearized given the chosen data"} |
---|
964 | PopupMenu xmodel,value= #"\"q;log(q);q^2;q^c\"" |
---|
965 | PopupMenu xmodel,mode=NumVarOrDefault("root:myGlobals:Plot_1d:gXMode", 1 ),proc=XMode_PopMenuProc |
---|
966 | SetVariable expc,pos={167,28},size={80,15},title="pow \"c\"" |
---|
967 | 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"} |
---|
968 | SetVariable expc,limits={-10,10,0},value= root:myGlobals:Plot_1d:gExpC |
---|
969 | |
---|
970 | endif |
---|
971 | NVAR isPhiAve= root:myGlobals:Plot_1d:isPhiAve //0 signifies (normal) x=qvals |
---|
972 | Label left "I(q)" |
---|
973 | if(isPhiAve) |
---|
974 | Label bottom "Angle (deg)" |
---|
975 | else |
---|
976 | SVAR angst = root:myGlobals:gAngstStr |
---|
977 | Label bottom "q ("+angst+"\\S-1\\M)" |
---|
978 | Endif |
---|
979 | //force a rescale to get something other than I vs. q |
---|
980 | Rescale_Plot_1D_ButtonProc("") |
---|
981 | End |
---|
982 | |
---|
983 | //function to set the popItem (mode) of the graph, to re-create the graph based on user preferences |
---|
984 | Function YMode_PopMenuProc(ctrlName,popNum,popStr) : PopupMenuControl |
---|
985 | String ctrlName |
---|
986 | Variable popNum |
---|
987 | String popStr |
---|
988 | |
---|
989 | Variable/G root:myGlobals:Plot_1d:gYMode=popNum |
---|
990 | Rescale_Plot_1D_ButtonProc("") |
---|
991 | End |
---|
992 | |
---|
993 | //function to set the popItem (mode) of the graph, to re-create the graph based on user preferences |
---|
994 | Function XMode_PopMenuProc(ctrlName,popNum,popStr) : PopupMenuControl |
---|
995 | String ctrlName |
---|
996 | Variable popNum |
---|
997 | String popStr |
---|
998 | |
---|
999 | Variable/G root:myGlobals:Plot_1d:gXMode=popNum |
---|
1000 | Rescale_Plot_1D_ButtonProc("") |
---|
1001 | End |
---|
1002 | |
---|
1003 | //function to restore the graph axes to full scale, undoing any zooming |
---|
1004 | Function AllQ_Plot_1D_ButtonProc(ctrlName) : ButtonControl |
---|
1005 | String ctrlName |
---|
1006 | |
---|
1007 | DoWindow/F Plot_1d |
---|
1008 | SetAxis/A |
---|
1009 | End |
---|
1010 | |
---|
1011 | //function to rescale the axes of the graph as selected from the popups and the |
---|
1012 | // entered values of the exponents |
---|
1013 | //** assumes the current waves are unknown, so it goes and gets a "fresh" copy from |
---|
1014 | //the data folder specified by the waves on the graph, which is the same folder that |
---|
1015 | //contains the "fresh" copy of the 1D data |
---|
1016 | // |
---|
1017 | // for log(10) scaling, simply modify the axes, not the data - gives better plots |
---|
1018 | // |
---|
1019 | Function Rescale_Plot_1D_ButtonProc(ctrlName) : ButtonControl |
---|
1020 | String ctrlName |
---|
1021 | |
---|
1022 | DoWindow/F Plot_1d |
---|
1023 | //Scaling exponents and background value |
---|
1024 | Variable pow_a,pow_b,pow_c |
---|
1025 | ControlInfo expa |
---|
1026 | pow_a = V_value |
---|
1027 | ControlInfo expb |
---|
1028 | pow_b = V_value |
---|
1029 | ControlInfo expc |
---|
1030 | pow_c = V_value |
---|
1031 | |
---|
1032 | //check for physical limits on exponent values, abort if bad values found |
---|
1033 | if((pow_a < -2) || (pow_a > 10)) |
---|
1034 | Abort "Exponent a must be in the range (-2,10)" |
---|
1035 | endif |
---|
1036 | if((pow_b < 0) || (pow_b > 10)) |
---|
1037 | Abort "Exponent b must be in the range (0,10)" |
---|
1038 | endif |
---|
1039 | //if q^c is the x-scaling, c must be be within limits and also non-zero |
---|
1040 | ControlInfo xModel |
---|
1041 | If (cmpstr("q^c",S_Value) == 0) |
---|
1042 | if(pow_c == 0) |
---|
1043 | Abort "Exponent c must be non-zero, q^0 = 1" |
---|
1044 | endif |
---|
1045 | if((pow_c < -10) || (pow_c > 10)) |
---|
1046 | Abort "Exponent c must be in the range (-10,10)" |
---|
1047 | endif |
---|
1048 | endif //check q^c exponent |
---|
1049 | |
---|
1050 | // get the current experimental q, I, and std dev. waves |
---|
1051 | |
---|
1052 | //!! get the wave path from the window and construct the necessary wave |
---|
1053 | //references to the unmodified, averaged data (qval, aveint) |
---|
1054 | //and use these to modify the (xAxisWave,YAxisWave) that are on the graph |
---|
1055 | String dfSav = GetDataFolder(1) |
---|
1056 | //String curPath = GetWavesDataFolder(WaveRefIndexed("",0,1),1) //path for the first y-wave on the graph |
---|
1057 | SVAR curFolder=root:myGlobals:gDataDisplayType |
---|
1058 | |
---|
1059 | // SetDataFolder curPath |
---|
1060 | //get the untarnished data, so we can rescale it freshly here |
---|
1061 | Wave yw = $("root:"+curFolder+":aveint") |
---|
1062 | Wave ew = $("root:"+curFolder+":sigave") |
---|
1063 | //get the correct x values |
---|
1064 | NVAR isPhiAve= root:myGlobals:Plot_1d:isPhiAve //0 signifies (normal) x=qvals |
---|
1065 | if(isPhiAve) |
---|
1066 | //x is angle |
---|
1067 | Wave xw=$("root:"+curFolder+":phival") |
---|
1068 | else |
---|
1069 | //x is q-values |
---|
1070 | Wave xw=$("root:"+curFolder+":qval") |
---|
1071 | endif |
---|
1072 | Wave yAxisWave=root:myGlobals:Plot_1d:yAxisWave //refs to waves to be modified, hard-wired positions |
---|
1073 | Wave xAxisWave=root:myGlobals:Plot_1d:xAxisWave |
---|
1074 | Wave yErrWave=root:myGlobals:Plot_1d:yErrWave |
---|
1075 | |
---|
1076 | //variables set for each model to control look of graph |
---|
1077 | String xlabel,ylabel,xstr,ystr |
---|
1078 | Variable logLeft=0,logBottom=0 |
---|
1079 | //check for proper y-scaling selection, make the necessary waves |
---|
1080 | ControlInfo yModel |
---|
1081 | ystr = S_Value |
---|
1082 | do |
---|
1083 | If (cmpstr("I",S_Value) == 0) |
---|
1084 | SetScale d 0,0,"1/cm",yAxisWave |
---|
1085 | yErrWave = ew |
---|
1086 | yAxisWave = yw |
---|
1087 | ylabel = "I(q)" |
---|
1088 | break |
---|
1089 | endif |
---|
1090 | If (cmpstr("ln(I)",S_Value) == 0) |
---|
1091 | SetScale d 0,0,"",yAxisWave |
---|
1092 | yErrWave = ew/yw |
---|
1093 | yAxisWave = ln(yw) |
---|
1094 | ylabel = "ln(I)" |
---|
1095 | break |
---|
1096 | endif |
---|
1097 | If (cmpstr("log(I)",S_Value) == 0) |
---|
1098 | SetScale d 0,0,"",yAxisWave |
---|
1099 | yAxisWave = yw |
---|
1100 | yErrWave = ew |
---|
1101 | logLeft=1 //scale the axis, not the wave |
---|
1102 | ylabel = "I(q)" |
---|
1103 | // yErrWave = ew/(2.30*yw) |
---|
1104 | // yAxisWave = log(yw) |
---|
1105 | // ylabel = "log(I)" |
---|
1106 | break |
---|
1107 | endif |
---|
1108 | If (cmpstr("1/I",S_Value) == 0) |
---|
1109 | SetScale d 0,0,"",yAxisWave |
---|
1110 | yErrWave = ew/yw^2 |
---|
1111 | yAxisWave = 1/yw |
---|
1112 | ylabel = "1/I" |
---|
1113 | break |
---|
1114 | endif |
---|
1115 | If (cmpstr("I^a",S_Value) == 0) |
---|
1116 | SetScale d 0,0,"",yAxisWave |
---|
1117 | yErrWave = ew*abs(pow_a*(yw^(pow_a-1))) |
---|
1118 | yAxisWave = yw^pow_a |
---|
1119 | ylabel = "I^"+num2str(pow_a) |
---|
1120 | break |
---|
1121 | endif |
---|
1122 | If (cmpstr("Iq^a",S_Value) == 0) |
---|
1123 | SetScale d 0,0,"",yAxisWave |
---|
1124 | yErrWave = ew*xw^pow_a |
---|
1125 | yAxisWave = yw*xw^pow_a |
---|
1126 | ylabel = "I*q^"+num2str(pow_a) |
---|
1127 | break |
---|
1128 | endif |
---|
1129 | If (cmpstr("I^a q^b",S_Value) == 0) |
---|
1130 | SetScale d 0,0,"",yAxisWave |
---|
1131 | yErrWave = ew*abs(pow_a*(yw^(pow_a-1)))*xw^pow_b |
---|
1132 | yAxisWave = yw^pow_a*xw^pow_b |
---|
1133 | ylabel = "I^" + num2str(pow_a) + "q^"+num2str(pow_b) |
---|
1134 | break |
---|
1135 | endif |
---|
1136 | If (cmpstr("1/sqrt(I)",S_Value) == 0) |
---|
1137 | SetScale d 0,0,"",yAxisWave |
---|
1138 | yErrWave = 0.5*ew*yw^(-1.5) |
---|
1139 | yAxisWave = 1/sqrt(yw) |
---|
1140 | ylabel = "1/sqrt(I)" |
---|
1141 | break |
---|
1142 | endif |
---|
1143 | If (cmpstr("ln(Iq)",S_Value) == 0) |
---|
1144 | SetScale d 0,0,"",yAxisWave |
---|
1145 | yErrWave =ew/yw |
---|
1146 | yAxisWave = ln(xw*yw) |
---|
1147 | ylabel = "ln(q*I)" |
---|
1148 | break |
---|
1149 | endif |
---|
1150 | If (cmpstr("ln(Iq^2)",S_Value) == 0) |
---|
1151 | SetScale d 0,0,"",yAxisWave |
---|
1152 | yErrWave = ew/yw |
---|
1153 | yAxisWave = ln(xw*xw*yw) |
---|
1154 | ylabel = "ln(I*q^2)" |
---|
1155 | break |
---|
1156 | endif |
---|
1157 | //more ifs for each case as they are added |
---|
1158 | |
---|
1159 | // if selection not found, abort |
---|
1160 | DoAlert 0,"Y-axis scaling incorrect. Aborting" |
---|
1161 | Abort |
---|
1162 | while(0) //end of "case" statement for y-axis scaling |
---|
1163 | |
---|
1164 | //check for proper x-scaling selection |
---|
1165 | SVAR angst = root:myGlobals:gAngstStr |
---|
1166 | String dum |
---|
1167 | |
---|
1168 | ControlInfo xModel |
---|
1169 | xstr = S_Value |
---|
1170 | do |
---|
1171 | If (cmpstr("q",S_Value) == 0) |
---|
1172 | SetScale d 0,0,"",xAxisWave |
---|
1173 | xAxisWave = xw |
---|
1174 | if(isPhiAve) |
---|
1175 | xlabel="Angle (deg)" |
---|
1176 | else |
---|
1177 | xlabel = "q ("+angst+"\\S-1\\M)" |
---|
1178 | endif |
---|
1179 | break |
---|
1180 | endif |
---|
1181 | If (cmpstr("q^2",S_Value) == 0) |
---|
1182 | SetScale d 0,0,"",xAxisWave |
---|
1183 | xAxisWave = xw*xw |
---|
1184 | if(isPhiAve) |
---|
1185 | xlabel="(Angle (deg) )^2" |
---|
1186 | else |
---|
1187 | xlabel = "q^2 ("+angst+"\\S-2\\M)" |
---|
1188 | endif |
---|
1189 | break |
---|
1190 | endif |
---|
1191 | If (cmpstr("log(q)",S_Value) == 0) |
---|
1192 | SetScale d 0,0,"",xAxisWave |
---|
1193 | xAxisWave = xw //scale the axis, not the wave |
---|
1194 | //xAxisWave = log(xw) |
---|
1195 | logBottom=1 |
---|
1196 | if(isPhiAve) |
---|
1197 | //xlabel="log(Angle (deg))" |
---|
1198 | xlabel="Angle (deg)" |
---|
1199 | else |
---|
1200 | //xlabel = "log(q)" |
---|
1201 | xlabel = "q ("+angst+"\\S-1\\M)" |
---|
1202 | endif |
---|
1203 | break |
---|
1204 | endif |
---|
1205 | If (cmpstr("q^c",S_Value) == 0) |
---|
1206 | SetScale d 0,0,"",xAxisWave |
---|
1207 | xAxisWave = xw^pow_c |
---|
1208 | dum = num2str(pow_c) |
---|
1209 | if(isPhiAve) |
---|
1210 | xlabel="Angle^"+dum |
---|
1211 | else |
---|
1212 | xlabel = "q^"+dum+" ("+angst+"\\S-"+dum+"\\M)" |
---|
1213 | endif |
---|
1214 | break |
---|
1215 | endif |
---|
1216 | |
---|
1217 | //more ifs for each case |
---|
1218 | |
---|
1219 | // if selection not found, abort |
---|
1220 | DoAlert 0,"X-axis scaling incorrect. Aborting" |
---|
1221 | Abort |
---|
1222 | while(0) //end of "case" statement for x-axis scaling |
---|
1223 | |
---|
1224 | Label left ylabel |
---|
1225 | Label bottom xlabel //E denotes "scaling" - may want to use "units" instead |
---|
1226 | ModifyGraph log(left)=(logLeft) |
---|
1227 | ModifyGraph log(bottom)=(logBottom) |
---|
1228 | |
---|
1229 | End |
---|
1230 | |
---|