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

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

Tie the NXcanSAS writers into the GUI for 1D SANS and USANS reduction (untested).

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