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

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

Change the data output from a checkbox to a radio button. Tie the writer into base 'Reduce a File' method. Tested and working.

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