source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/AvgGraphics.ipf @ 779

Last change on this file since 779 was 764, checked in by srkline, 12 years ago
  • fixed a few bugs with GenCurveFit?, and how the reports are generated


  • the DEFAULT.MASK file is automatically loaded when the path is set, if it can be found. this only happens from the main (yellow) panel. Nothing happens if that exact file is not found.


  • a "Sector_PlusMinus" averaging option is added. This defines the LEFT sector as being "negative" q-values. Everything else behaves as a normal sector average. This is from Lionel, a very old ticket #31


  • if sectors or annular regions are drawn on RAW data files, the drawn lines are re-drawn correctly as the data is scrolled using the < and > buttons.


  • a super secret option for a "histogram pair" has been added. May be useful for alignment, may ditch if Jeff and Cedric don't like it. To do this, put cursor A on the 2D image at the center of where you want the vertical and horizontal swath to be. +-5 pixels is hard-wired. draw any marquee(size, location is ignored) and select SANS Histogram, and you get the pair. If cursor A is not on the graph, you get the normal histogram as defined by the marquee.


  • arrow buttons on RAW 2D data display now search +- 10 data files for "next", in case there are missing file numbers.


  • Incorporated Lionel's changes to ILL_* files for his generation of a "DIV" file for D22


  • Added the offset traces checkbox back to the SASCALC panel. previously it was hidden on the simulation panels.


  • loosened the tolerance for SDD matching onn the MRED panel to 0.1 m



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