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

Last change on this file since 1164 was 1164, checked in by krzywon, 4 years ago

Revert changes meant for NXcanSAS branch.

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