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

Revision 570, 37.9 KB checked in by srkline, 5 years ago (diff)

Change (1):
In preparation for release, updated pragma IgorVersion?=6.1 in all procedures

Change (2):
As a side benefit of requiring 6.1, we can use the MultiThread? keyword to thread any model function we like. The speed benefit is only noticeable on functions that require at least one integration and at least 100 points (resolution smearing is NOT threaded, too many threadSafe issues, too little benefit). I have chosen to use the MultiThread? only on the XOP assignment. In the Igor code there are too many functions that are not explicitly declared threadsafe, making for a mess.

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