source: sans/SANSReduction/trunk/Put in User Procedures/SANS_Reduction_v5.00/AvgGraphics.ipf @ 40

Last change on this file since 40 was 40, checked in by srkline, 16 years ago

Initial checkin of V5.00 SANSReduction files

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