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

Last change on this file since 740 was 700, checked in by srkline, 12 years ago

fixed display bug in NSORT where normalizing to the 3rd (high Q) data file would not be displayed with the proper overlap. The data file was, however, written out correctly.

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