source: sans/Dev/branches/nxcansas_writer/NCNR_User_Procedures/Reduction/SANS/AvgGraphics.ipf @ 1206

Last change on this file since 1206 was 1206, checked in by krzywon, 3 years ago

Add 2D NXcanSAS output as an option in Averaging Panel.

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