source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/FIT_Ops.ipf @ 779

Last change on this file since 779 was 749, checked in by srkline, 12 years ago

Put I(0) errors in most of the places that I could make sense to put them. #215

Also removed FIT_Ops entirely by copying FITRPA functions to LinearizedFIts, and simply pointing FIT_Ops to include LinearizedFits? (this was done for backwards compatibility). part of ticket #275

File size: 24.7 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma version=5.0
3#pragma IgorVersion=6.1
4
5
6// this was a duplicate of the LinearizedFits procedure file. This one was not being properly updated,
7// so this one has been cut. The only differences in the files are the "A_" prefixes, and the location
8// of the data folder. the old FIT_Ops location was:
9//                              NewDataFolder/O root:myGlobals:FIT
10//
11// in the LinearizedFits, it's a more standard location:
12//              NewDataFolder/O root:Packages:NIST:FIT
13//
14//
15// -- in case an old experiment points to FIT_Ops, load this instead
16
17
18#include "LinearizedFits_v40"
19
20
21
22
23////**************************
24////procedures for creating and initializing the FIT panel
25////global variables (numerical only) are kept in root:myGlobals:FIT folder,
26////created as needed
27////
28////also contains code for the FIT_RPA panel and its fitting procedures
29////
30////**************************
31////
32//
33////main procedures to open the panel, initializing the data folder and global variables
34////as necessary. All are kept in a :FIT subfolder to avoid overlap with other variables
35////
36//// To use any of the fit functions in the FIT panel, I(Q) data must already
37//// be loaded into memory (using "plot" from the 1-D data operations
38//// ** this may be useful to change in the future, replacing the 3 popups
39//// with a list box - allowing the user to pick/load the data from the fit panel
40//// and not offering any choice of q/i/s waves to use. (more consistent with the operation
41//// of the FIT/RPA panel)
42////
43//Proc OpenFitPanel()
44//      If(WinType("FitPanel") == 0)
45//              //create the necessary data folder
46//              NewDataFolder/O root:myGlobals:FIT
47//              //initialize the values
48//              Variable/G root:myGlobals:FIT:gLolim = 0.02
49//              Variable/G root:myGlobals:FIT:gUplim = 0.04
50//              Variable/G root:myGlobals:FIT:gExpA = 1
51//              Variable/G root:myGlobals:FIT:gExpB = 1
52//              Variable/G root:myGlobals:FIT:gExpC = 1
53//              Variable/G root:myGlobals:FIT:gBack = 0
54//              String/G root:myGlobals:FIT:gDataPopList = "none"
55//              FitPanel()
56//      else
57//              //window already exists, just bring to front for update
58//              DoWindow/F FitPanel
59//              CheckBox check0,value=0         //deselect the checkbox to use cursors
60//      endif
61//      //pop the file menu
62//      FIT_FilePopMenuProc("",1,"")
63//End
64//
65////the actual window recreation macro to draw the fit panel. Globals and data folder must
66//// already be initialized
67//Window FitPanel()
68//      String angst = root:myGlobals:gAngstStr
69//      PauseUpdate; Silent 1           // building window...
70//      NewPanel /W=(461,46,735,455)/K=1
71//      ModifyPanel cbRGB=(32768,54615,65535), fixedSize=1
72//      SetDrawLayer UserBack
73//      DrawText 56,20,"Select Experimental Data"
74//      DrawText 66,138,"q-range to fit ("+angst+"^-1)"
75//      DrawText 42,268,"Select the y and x-axis scaling"
76//      DrawLine 1,21,271,21
77//      DrawLine -1,272,273,272
78//      DrawLine -1,140,272,140
79////    PopupMenu xwave,pos={13,31},size={158,19},title="q-values"
80////    PopupMenu xwave,help={"Select the experimental q-values. If no data is available, use Macro LoadQISData or LoadQSIGData."}
81////    PopupMenu xwave,mode=1,value= #"WaveList(\"*q\",\";\",\"\")"
82//      PopupMenu ywave,pos={13,40},size={154,19},title="Data File"
83//      PopupMenu ywave,help={"Select the experimental intensity values"}
84//      PopupMenu ywave,mode=1,value=root:myGlobals:FIT:gDataPopList,proc=FIT_FilePopMenuProc
85//      Button loadButton,pos={25,80},size={130,20},proc=FIT_Load_Proc,title="Load and Plot File"
86//      Button loadButton,help={"After choosing a file, load it into memory and plot it with this button."}
87//      Button helpButton,pos={200,80},size={25,20},proc=showFITHelp,title="?"
88//      Button helpButton,help={"Show help file for linearized fitting"}
89////    PopupMenu ewave,pos={13,87},size={186,19},title="Std. Deviation"
90////    PopupMenu ewave,help={"Select the standard deviation of the intensity"}
91////    PopupMenu ewave,mode=1,value= #"WaveList(\"*s\",\";\",\"\")"
92//      PopupMenu ymodel,pos={20,281},size={76,19},title="y-axis"
93//      PopupMenu ymodel,help={"This popup selects how the y-axis will be linearized based on the chosen data"}
94//      PopupMenu ymodel,mode=1,value= #"\"I;log(I);ln(I);1/I;I^a;Iq^a;I^a q^b;1/sqrt(I);ln(Iq);ln(Iq^2)\""
95//      Button GoFit,pos={60,367},size={70,20},proc=DispatchModel,title="Do the Fit"
96//      Button GoFit,help={"This button will do the specified fit using the selections in this panel"}
97//      Button DoneButton,pos={180,367},size={50,20},proc=FITDoneButton,title="Done"
98//      Button DoneButton,help={"This button will close the panel and the associated graph"}
99//      SetVariable lolim,pos={64,147},size={134,17},title="Lower Limit"
100//      SetVariable lolim,help={"Enter the lower q-limit to perform the fit ("+angst+"^-1)"}
101//      SetVariable lolim,limits={0,5,0},value= root:myGlobals:FIT:gLolim
102//      SetVariable uplim,pos={63,169},size={134,17},title="Upper Limit"
103//      SetVariable uplim,help={"Enter the upper q-limit to perform the fit ("+angst+"^-1)"}
104//      SetVariable uplim,limits={0,5,0},value= root:myGlobals:FIT:gUplim
105//      SetVariable expa,pos={13,311},size={80,17},title="pow \"a\""
106//      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"}
107//      SetVariable expa,limits={-2,10,0},value= root:myGlobals:FIT:gExpA
108//      SetVariable expb,pos={98,311},size={80,17},title="pow \"b\""
109//      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"}
110//      SetVariable expb,limits={0,10,0},value= root:myGlobals:FIT:gExpB
111//      PopupMenu xmodel,pos={155,280},size={79,19},title="x-axis"
112//      PopupMenu xmodel,help={"This popup selects how the x-axis will be linearized given the chosen data"}
113//      PopupMenu xmodel,mode=1,value= #"\"q;log(q);q^2;q^c\""
114//      CheckBox check0,pos={18,223},size={240,20},title="Use cursor range from FitWindow"
115//      CheckBox check0,help={"Checking this will perform a fit between the cursors on the graph in FitWindow and ignore the numerical limits typed above"},value=0
116//      SetVariable back,pos={70,338},size={139,17},title="background"
117//      SetVariable back,help={"This constant background value will be subtracted from the experimental intensity before fitting is done"}
118//      SetVariable back,limits={-Inf,Inf,0},value= root:myGlobals:FIT:gBack
119//      SetVariable expc,pos={182,310},size={80,17},title="pow \"c\""
120//      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"}
121//      SetVariable expc,limits={-10,10,0},value= root:myGlobals:FIT:gExpC
122//      Button sh_all,pos={65,193},size={130,20},proc=ShowAllButtonProc,title="Show Full q-range"
123//      Button sh_all,help={"Use this to show the entire q-range of the data rather than just the fitted range."}
124//EndMacro
125//
126//
127//Proc FITDoneButton(ctrlName): ButtonControl
128//      String ctrlName
129//      DoWindow/K FitWindow
130//      DoWindow/K FitPanel
131//end
132//
133//Proc showFITHelp(ctrlName): ButtonControl
134//      String ctrlName
135//      DisplayHelpTopic/K=1/Z "SANS Data Reduction Tutorial[Fit Lines to Your Data]"
136//      if(V_flag !=0)
137//              DoAlert 0,"The SANS Data Reduction Tutorial Help file could not be found"
138//      endif
139//end
140//
141////Loads the selected file for fitting
142////graphs the data as needed
143//Proc FIT_Load_Proc(ctrlName): ButtonControl
144//      String ctrlName
145//     
146//      //Load the data
147//      String tempName="",partialName=""
148//      Variable err
149//      ControlInfo $"ywave"
150//      //find the file from the partial filename
151//      If( (cmpstr(S_value,"")==0) || (cmpstr(S_value,"none")==0) )
152//              //null selection, or "none" from any popup
153//              Abort "no file selected in popup menu"
154//      else
155//              //selection not null
156//              partialName = S_value
157//              //Print partialName
158//      Endif
159//      //get a valid file based on this partialName and catPathName
160//      tempName = FindValidFilename(partialName)
161//
162//      //prepend path to tempName for read routine
163//      PathInfo catPathName
164//     
165//      tempName = S_path + tempName
166//     
167//      //load in the data (into the its own folder)
168//      A_LoadOneDDataWithName(tempName,0)
169//      //Print S_fileName
170//      //Print tempName
171//     
172//      String cleanLastFileName = CleanupName(root:Packages:NIST:gLastFileName,0)
173//
174//      tempName="root:"+cleanLastFileName+":"+cleanLastFileName
175//      Duplicate/O $(tempName+"_q") xAxisWave
176//      //tempName=cleanLastFileName+"_i"
177//      Duplicate/O $(tempName+"_i") yAxisWave
178//      //tempName=cleanLastFileName+"_s"
179//      Duplicate/O $(tempName+"_s") yErrWave
180//
181//      //Plot, and adjust the scaling to match the axis scaling set by the popups
182//      Rescale_Data()
183//     
184//End
185//
186////gets a valid file list (simply not the files with ".SAn" in the name)
187////
188//Function FIT_FilePopMenuProc(ctrlName,popNum,popStr) : PopupMenuControl
189//      String ctrlName
190//      Variable popNum
191//      String popStr
192//     
193//      String tempStr=ReducedDataFileList(ctrlName)
194//      if(strlen(tempStr)==0)
195//              tempStr = "Pick the data path"
196//      Endif
197//      String/G root:myGlobals:FIT:gDataPopList =tempStr               //function is in NSORT.ipf
198//      ControlUpdate ywave
199//     
200//End
201//
202////direct porting of the fit program from the VAX, with no corrections and only
203////minor modifications of additional  linearizations and the option
204////to subtract a constant (q-independent) background value before doing any
205////of the fits. The original data on disk (and as loaded) is never modified, all
206////manipulation is done from a copy of the data.
207//
208////button procedure to show the entire axis range of the data, rather than just
209////the fitted range, which is the default display after a fit is performed
210////
211//Function ShowAllButtonProc(ctrlName) : ButtonControl
212//      String ctrlName
213//
214//      //bring the FitWindow to the front and Autoscale the axes
215//      DoWindow/F FitWindow
216//      SetAxis/A
217//End
218//
219//// function that takes the current dataset (already loaded)
220//// and replots it based on the X/Y axis scaling selected in the popups
221//// (does not fit the data)
222////
223//Function Rescale_Data()
224//     
225//      //Scaling exponents and background value
226//      Variable pow_a,pow_b,pow_c,bkg
227//      ControlInfo/W=FitPanel expa
228//      pow_a = V_value
229//      ControlInfo/W=FitPanel expb
230//      pow_b = V_value
231//      ControlInfo/W=FitPanel expc
232//      pow_c = V_value
233//      ControlInfo/W=FitPanel back
234//      bkg = V_value
235//     
236////check for physical limits on exponent values
237//// if bad values found, alert, and reset to good values so the rescaling can continue
238//      NVAR gA = root:myGlobals:FIT:gExpA
239//      NVAR gB = root:myGlobals:FIT:gExpB
240//      NVAR gC = root:myGlobals:FIT:gExpC
241//      if((pow_a < -2) || (pow_a > 10))
242//              DoAlert 0,"Exponent a must be in the range (-2,10) - the exponent a has been reset to 1"
243//              gA = 1
244//      endif
245//      if((pow_b < 0) || (pow_b > 10))
246//              DoAlert 0,"Exponent b must be in the range (0,10) - the exponent b has been reset to 1"
247//              gB = 1
248//      endif
249//      //if q^c is the x-scaling, c must be be within limits and also non-zero
250//      ControlInfo/W=FitPanel xModel
251//      If (cmpstr("q^c",S_Value) == 0)
252//              if(pow_c == 0)
253//                      DoAlert 0,"Exponent c must be non-zero, c has been reset to 1"
254//                      gC = 1
255//              endif
256//              if((pow_c < -10) || (pow_c > 10))
257//                      DoAlert 0,"Exponent c must be in the range (-10,10), c has been reset to 1"
258//                      gC = 1
259//              endif
260//      endif
261//     
262//      //do the rescaling of the data
263//      // get the current experimental q, I, and std dev. waves (as they would be loaded )
264//
265//      //ControlInfo/W=FitPanel ywave
266//      //get the filename from the global as it's loaded, rather from the popup - as version numbers
267//      // do cause problems here. This global is also used later in this function
268//      SVAR gLastFileName = root:Packages:NIST:gLastFileName
269//      String tempStr = CleanupName(gLastFileName,0)
270//      String tempName = "root:"+tempStr+":"+tempStr
271//     
272//      Wave xw = $(tempName+"_q")
273//      Wave yw = $(tempName+"_i")
274//      Wave ew = $(tempName+"_s")
275//     
276//      //variables set for each model to control look of graph
277//      Variable xlow,xhigh,ylow,yhigh,yes_cursors
278//      String xlabel,ylabel,xstr,ystr
279//      //check for proper y-scaling selection, make the necessary waves
280//      ControlInfo/W=FitPanel yModel
281//      ystr = S_Value
282////    print "ystr = ",ystr
283//      do
284//              // make the new yaxis waves, including weighting wave
285//              Duplicate/O yw yAxisWave,yErrWave,yWtWave,residWave
286//              //subtract the background value from yAxisWave before doing any rescaling
287//              yAxisWave = yw - bkg
288//             
289//              If (cmpstr("I",S_Value) == 0)
290//                      SetScale d 0,0,"1/cm",yAxisWave
291//                      yErrWave = ew
292//                      yWtWave = 1/yErrWave
293//                      yAxisWave = yAxisWave
294//                      ylabel = "I(q)"
295//                      break   
296//              endif
297//              If (cmpstr("ln(I)",S_Value) == 0)
298//                      SetScale d 0,0,"",yAxisWave
299//                      yErrWave = ew/yAxisWave
300//                      yWtWave = 1/yErrWave
301//                      yAxisWave = ln(yAxisWave)
302//                      ylabel = "ln(I)"
303//                      break   
304//              endif
305//              If (cmpstr("log(I)",S_Value) == 0)
306//                      SetScale d 0,0,"",yAxisWave
307//                      yErrWave = ew/(2.30*yAxisWave)
308//                      yWtWave = 1/yErrWave
309//                      yAxisWave = log(yAxisWave)
310//                      ylabel = "log(I)"
311//                      break   
312//              endif
313//              If (cmpstr("1/I",S_Value) == 0)
314//                      SetScale d 0,0,"",yAxisWave
315//                      yErrWave = ew/yAxisWave^2
316//                      yWtWave = 1/yErrWave
317//                      yAxisWave = 1/yAxisWave
318//                      ylabel = "1/I"
319//                      break
320//              endif
321//              If (cmpstr("I^a",S_Value) == 0)
322//                      SetScale d 0,0,"",yAxisWave
323//                      yErrWave = ew*abs(pow_a*(yAxisWave^(pow_a-1)))
324//                      yWtWave = 1/yErrWave
325//                      yAxisWave = yAxisWave^pow_a
326//                      ylabel = "I^"+num2str(pow_a)
327//                      break
328//              endif
329//              If (cmpstr("Iq^a",S_Value) == 0)
330//                      SetScale d 0,0,"",yAxisWave
331//                      yErrWave = ew*xw^pow_a
332//                      yWtWave = 1/yErrWave
333//                      yAxisWave = yAxisWave*xw^pow_a
334//                      ylabel = "I*q^"+num2str(pow_a)
335//                      break
336//              endif
337//              If (cmpstr("I^a q^b",S_Value) == 0)
338//                      SetScale d 0,0,"",yAxisWave
339//                      yErrWave = ew*abs(pow_a*(yAxisWave^(pow_a-1)))*xw^pow_b
340//                      yWtWave = 1/yErrWave
341//                      yAxisWave = yAxisWave^pow_a*xw^pow_b
342//                      ylabel = "I^" + num2str(pow_a) + "q^"+num2str(pow_b)
343//                      break
344//              endif
345//              If (cmpstr("1/sqrt(I)",S_Value) == 0)
346//                      SetScale d 0,0,"",yAxisWave
347//                      yErrWave = 0.5*ew*yAxisWave^(-1.5)
348//                      yWtWave = 1/yErrWave
349//                      yAxisWave = 1/sqrt(yAxisWave)
350//                      ylabel = "1/sqrt(I)"
351//                      break
352//              endif
353//              If (cmpstr("ln(Iq)",S_Value) == 0)
354//                      SetScale d 0,0,"",yAxisWave
355//                      yErrWave =ew/yAxisWave
356//                      yWtWave = 1/yErrWave
357//                      yAxisWave = ln(xw*yAxisWave)
358//                      ylabel = "ln(q*I)"
359//                      break
360//              endif
361//              If (cmpstr("ln(Iq^2)",S_Value) == 0)
362//                      SetScale d 0,0,"",yAxisWave
363//                      yErrWave = ew/yAxisWave
364//                      yWtWave = 1/yErrWave
365//                      yAxisWave = ln(xw*xw*yAxisWave)
366//                      ylabel = "ln(I*q^2)"
367//                      break
368//              endif
369//              //more ifs for each case
370//             
371//              // if selection not found, abort
372//              DoAlert 0,"Y-axis scaling incorrect. Aborting"
373//              Abort
374//      while(0)        //end of "case" statement for y-axis scaling
375//     
376//     
377//      //check for proper x-scaling selection
378//      Variable low,high
379//     
380//      ControlInfo/W=FitPanel lolim
381//      low = V_value
382//      ControlInfo/W=FitPanel uplim
383//      high = V_value
384//      if ((high<low) || (high==low))
385//              DoAlert 0,"Unphysical fitting limits - re-enter better values"
386//              Abort
387//      endif
388//     
389//      SVAR aStr = root:myGlobals:gAngstStr
390//     
391//      ControlInfo/W=FitPanel xModel
392//      xstr = S_Value
393//      do
394//              // make the new yaxis wave
395//              Duplicate/o xw xAxisWave
396//              If (cmpstr("q",S_Value) == 0)   
397//                      SetScale d 0,0,aStr+"^-1",xAxisWave
398//                      xAxisWave = xw
399//                      xlabel = "q"
400//                      xlow = low
401//                      xhigh = high
402//                      break   
403//              endif
404//              If (cmpstr("q^2",S_Value) == 0)
405//                      SetScale d 0,0,aStr+"^-2",xAxisWave
406//                      xAxisWave = xw*xw
407//                      xlabel = "q^2"
408//                      xlow = low^2
409//                      xhigh = high^2
410//                      break   
411//              endif
412//              If (cmpstr("log(q)",S_Value) == 0)     
413//                      SetScale d 0,0,"",xAxisWave
414//                      xAxisWave = log(xw)
415//                      xlabel = "log(q)"
416//                      xlow = log(low)
417//                      xhigh = log(high)
418//                      break   
419//              endif
420//              If (cmpstr("q^c",S_Value) == 0)
421//                      SetScale d 0,0,"",xAxisWave
422//                      xAxisWave = xw^pow_c
423//                      xlabel = "q^"+num2str(pow_c)
424//                      xlow = low^pow_c
425//                      xhigh = high^pow_c
426//                      break
427//              endif
428//     
429//              //more ifs for each case
430//             
431//              // if selection not found, abort
432//              DoAlert 0,"X-axis scaling incorrect. Aborting"
433//              Abort
434//      while(0)        //end of "case" statement for x-axis scaling
435//
436//      //plot the data
437//     
438//      String cleanLastFileName = "root:"+CleanupName(gLastFileName,0)
439//      If(WinType("FitWindow") == 0)
440//              Display /W=(5,42,480,400)/K=1 yAxisWave vs xAxisWave
441//              ModifyGraph mode=3,standoff=0,marker=8
442//              ErrorBars/T=0 yAxisWave Y,wave=(yErrWave,yErrWave)
443//              ModifyGraph opaque(yAxisWave)=1
444//              DoWindow/C FitWindow
445//      else
446//              //window already exists, just bring to front for update
447//              DoWindow/F FitWindow
448//              // remove old text boxes
449//              TextBox/K/N=text_1
450//              TextBox/K/N=text_2
451//              TextBox/K/N=text_3
452//      endif
453//      SetAxis/A
454//      ModifyGraph tickUnit=1          //suppress tick units in labels
455//      TextBox/C/N=textLabel/A=RB "File = "+cleanLastFileName
456//      //clear the old fit from the window, if it exists
457//      RemoveFromGraph/W=FitWindow/Z fit_yAxisWave
458//     
459//      // add the cursors if desired...       
460//      //see if the user wants to use the data specified by the cursors - else use numerical values
461//     
462//      ControlInfo/W=FitPanel check0           //V_value = 1 if it is checked, meaning yes, use cursors
463//      yes_cursors = V_value
464//
465//      DoWindow/F FitWindow
466//      ShowInfo
467//      if(yes_cursors)
468//              xlow = xAxisWave[xcsr(A)]
469//              xhigh = xAxisWave[xcsr(B)]
470//              if(xlow > xhigh)
471//                      xhigh = xlow
472//                      xlow = xAxisWave[xcsr(B)]
473//              endif
474////            Print xlow,xhigh
475//      else
476//              FindLevel/P/Q xAxisWave, xlow
477//              if(V_flag == 1)                 //level NOT found
478//                      DoAlert 0,"Lower q-limit not in experimental q-range. Re-enter a better value"
479//                      //DoWindow/K FitWindow
480//                      //Abort
481//              endif
482//              Cursor/P A, yAxisWave,trunc(V_LevelX)+1
483//              ylow = V_LevelX
484//              FindLevel/P/Q xAxisWave, xhigh
485//              if(V_flag == 1)
486//                      DoAlert 0,"Upper q-limit not in experimental q-range. Re-enter a better value"
487//                      //DoWindow/K FitWindow
488//                      //Abort
489//              endif
490//              Cursor/P B, yAxisWave,trunc(V_LevelX)
491//              yhigh = V_LevelX
492//      endif   //if(V_value)
493//      //SetAxis bottom,xlow,xhigh
494//      //SetAxis left,ylow,yhigh
495//      Label left ylabel
496//      Label bottom xlabel     //E denotes "scaling"  - may want to use "units" instead       
497//
498//End
499//
500//
501////button procedure that is activated to "DotheFit"
502////the panel is parsed for proper fitting limits
503//// the appropriate linearization is formed (in the Rescale_Data() function)
504//// and the fit is done,
505////and the results are plotted
506//// function works in root level data folder (where the loaded 1-d data will be)
507//Function DispatchModel(GoFit) : ButtonControl
508//      String GoFit
509//
510//      //check for the FitWindow - to make sure that there is data to fit
511//      If(WinType("FitWindow") == 0)           //if the window doesn't exist
512//              Abort "You must Load and Plot a File before fitting the data"
513//      endif
514//      // rescale the data, to make sure it's as selected on the panel
515//      Rescale_Data()
516//     
517//      // now go do the fit
518//     
519//// get the current low and high q values for fitting
520//      Variable low,high
521//     
522//      ControlInfo/W=FitPanel lolim
523//      low = V_value
524//      ControlInfo/W=FitPanel uplim
525//      high = V_value
526//      if ((high<low) || (high==low))
527//              DoAlert 0,"Unphysical fitting limits - re-enter better values"
528//              Abort
529//      endif
530//
531//      //try including residuals on the graph /R=residWave, explicitly place on new axis
532//      //if only /R used, residuals are automatically placed on graph
533//     
534//      CurveFit line yAxisWave(xcsr(A),xcsr(B)) /X=xAxisWave /W=yWtWave /D 
535//      //CurveFit line yAxisWave(xcsr(A),xcsr(B)) /X=xAxisWave /W=yWtWave  /R /D 
536//      ModifyGraph rgb(fit_yAxisWave)=(0,0,0)
537//      ModifyGraph lsize(fit_yAxisWave)=2
538//// annotate graph, filtering out special cases of Guinier fits
539//// Text Boxes must be used, since ControlBars on graphs DON'T print out
540//     
541//      // need access to Global wave, result of fit
542//      //ystr and xstr are the axis strings - filter with a do-loop
543//      String ystr="",xstr=""
544//      SVAR gLastFileName = root:Packages:NIST:gLastFileName
545//      SVAR aStr = root:myGlobals:gAngstStr
546//      String tmpStr = CleanupName(gLastFileName,0)
547//      //ControlInfo/W=FitPanel ywave
548//      Wave xw = $("root:"+tmpStr+":"+tmpStr+"_q")
549//      ControlInfo/W=FitPanel yModel
550//      ystr = S_Value
551//      ControlInfo/W=FitPanel xModel
552//      xstr = S_Value
553//     
554//      WAVE W_coef=W_coef
555//      WAVE W_sigma=W_sigma
556//      String textstr_1,textstr_2,textstr_3 = ""
557//      Variable rg,rgerr,minfit,maxfit
558//     
559//      textstr_1 = "Slope = " + num2str(W_coef[1]) + " ± " + num2str(W_sigma[1])
560//      textstr_1 += "\rIntercept = " + num2str(W_coef[0]) + " ± " + num2str(W_sigma[0])
561//      textstr_1 += "\rChi-Squared =  " + num2str(V_chisq/(V_npnts - 3))
562//     
563//      minfit = xw[xcsr(A)]
564//      maxfit = xw[xcsr(B)]
565//      textstr_2 = "Qmin =  " + num2str(minfit)
566//      textstr_2 += "\rQmax =  " + num2str(maxfit)
567//     
568//      //model-specific calculations - I(0), Rg, etc.
569//      //put these in textstr_3, at bottom
570//      do
571//              If (cmpstr("I",ystr) == 0)
572//                      textstr_3 = "I(q=0) =  "  + num2str(W_coef[0])
573//                      break   
574//              endif
575//              If (cmpstr("ln(I)",ystr) == 0)
576//                      textstr_3 = "I(q=0) =  "  + num2str(exp(W_coef[0]))
577//                      if(cmpstr("q^2",xstr) == 0)     //then a Guinier plot for a sphere (3-d)
578//                              rg = sqrt(-3*W_coef[1])
579//                              rgerr = 3*W_sigma[1]/(2*rg)
580//                              textstr_3 += "\rRg ("+aStr+") = " + num2str(rg) + " ± " + num2str(rgerr)
581//                              textstr_3 += "\r" + num2str(rg*minfit) + " < Rg*q < " + num2str(rg*maxfit)
582//                              break
583//                      endif
584//                      break   
585//              endif
586//              If (cmpstr("log(I)",ystr) == 0)
587//                      if(cmpstr("log(q)",xstr) !=0 )  //extrapolation is nonsense
588//                              textstr_3 = "I(q=0) =  "  + num2str(10^(W_coef[0]))
589//                      endif
590//                      break   
591//              endif
592//              If (cmpstr("1/I",ystr) == 0)
593//                      textstr_3 = "I(q=0) =  "  + num2str(1/W_coef[0])+ " ± " + num2str(1/(W_coef[0] - W_sigma[0])-1/W_coef[0])
594//                      break
595//              endif
596//              If (cmpstr("I^a",ystr) == 0)
597//                      //nothing
598//                      break
599//              endif
600//              If (cmpstr("Iq^a",ystr) == 0)
601//                      //nothing
602//                      break
603//              endif
604//              If (cmpstr("I^a q^b",ystr) == 0)
605//                      //nothing
606//                      break
607//              endif
608//              If (cmpstr("1/sqrt(I)",ystr) == 0)
609//                      textstr_3 = "I(q=0) =  "  + num2str((W_coef[0])^2)
610//                      break
611//              endif
612//              If (cmpstr("ln(Iq)",ystr) == 0)
613//                      //nothing
614//                      if(cmpstr("q^2",xstr) == 0)     //then a x-sect Guinier plot for a rod (2-d)
615//                              // rg now is NOT the radius of gyration, but the x-sect DIAMETER
616//                              rg = 4*sqrt(-W_coef[1])
617//                              rgerr = 8*W_sigma[1]/rg
618//                              textstr_3 = "Rod diameter ("+aStr+") = " + num2str(rg) + " ± " + num2str(rgerr)
619//                              textstr_3 += "\r" + num2str(rg*minfit) + " < Rg*q < " + num2str(rg*maxfit)
620//                              break
621//                      endif
622//                      break
623//              endif
624//              If (cmpstr("ln(Iq^2)",ystr) == 0)
625//                      //nothing
626//                      if(cmpstr("q^2",xstr) == 0)     //then a 1-d Guinier plot for a sheet
627//                              // rg now is NOT the radius of gyration, but the thickness
628//                              rg = sqrt(-12*W_coef[1])
629//                              rgerr = 6*W_sigma[1]/(2*rg)
630//                              textstr_3 = "Platelet thickness ("+aStr+") = " + num2str(rg) + " ± " + num2str(rgerr)
631//                              textstr_3 += "\r" + num2str(rg*minfit) + " < Rg*q < " + num2str(rg*maxfit)
632//                              break
633//                      endif
634//                      break
635//              endif
636//             
637//      while(0)
638//      //kill the old textboxes, if they exist
639//      TextBox/W=FitWindow/K/N=text_1
640//      TextBox/W=FitWindow/K/N=text_2
641//      TextBox/W=FitWindow/K/N=text_3
642//      // write the new text boxes
643//      TextBox/W=FitWindow/N=text_1/A=LT textstr_1
644//      TextBox/W=FitWindow/N=text_2/A=LC textstr_2
645//      If (cmpstr("",textstr_3) != 0)          //only display textstr_3 if it isn't null
646//              TextBox/W=FitWindow/N=text_3/A=LB textstr_3
647//      endif
648//     
649//      //adjust the plot range to reflect the actual fitted range
650//      //cursors are already on the graph, done by Rescale_Data()
651//      AdjustAxisToCursors()
652//     
653//End
654//
655//// adjusts both the x-axis scaling  and y-axis scaling to the cursor range
656//// **cursors are already on the graph, done by Rescale_Data()
657////
658//// will expand the scale to show an extra 5 points in each direction (if available)
659//Function AdjustAxisToCursors()
660//
661//      DoWindow/F FitWindow
662//      WAVE xAxisWave = root:xAxisWave
663//      WAVE yAxisWave = root:yAxisWave
664//      Variable xlow,xhigh,ylow,yhigh,yptlow,ypthigh
665//      Variable extraPts = 5, num=numpnts(xAxisWave)
666//     
667//      String csrA = CsrInfo(A ,"FitWindow")
668//      String csrB = CsrInfo(B ,"FitWindow")
669//     
670//      //x-levels, these are monotonic
671//      Variable ptLow,ptHigh,tmp
672//      ptLow = NumberByKey("POINT", csrA ,":" ,";")
673//      ptHigh = NumberByKey("POINT", csrB ,":" ,";")
674//      if(ptLow > ptHigh)
675//              tmp= ptLow
676//              ptLow=ptHigh
677//              ptHigh=tmp
678//      endif
679//
680//      // keep extended point range in bounds
681//      ptLow = (ptLow-extraPts) >= 0 ? ptLow-extraPts : 0
682//      ptHigh = (ptHigh+extraPts) <= (num-1) ? ptHigh + extraPts : num-1
683//     
684//      xlow = xAxisWave[ptLow]
685//      xhigh = xAxisWave[ptHigh]
686////old way
687////    xlow = xAxisWave[xcsr(A)]
688////    xhigh = xAxisWave[xcsr(B)]
689////    if(xlow > xhigh)
690////            xhigh = xlow
691////            xlow = xAxisWave[xcsr(B)]
692////    endif
693//     
694//      //y-levels (old way)
695////    FindLevel/P/Q xAxisWave, xlow
696////    if(V_flag == 1)                 //level NOT found
697////            DoAlert 0,"Lower q-limit not in experimental q-range. Re-enter a better value"
698////    endif
699////    yptlow = V_LevelX
700////    FindLevel/P/Q xAxisWave, xhigh
701////    if(V_flag == 1)
702////            DoAlert 0,"Upper q-limit not in experimental q-range. Re-enter a better value"
703////    endif
704////    ypthigh = V_LevelX
705//
706////    Print xlow,xhigh,yptlow,ypthigh
707////    Print yAxisWave[yptlow],yAxisWave[ypthigh]
708//     
709//
710//      // make sure ylow/high are in the correct order, since the slope could be + or -
711//      yhigh = max(yAxisWave[ptlow],yAxisWave[pthigh])
712//      ylow = min(yAxisWave[ptlow],yAxisWave[pthigh])
713//     
714////    Print ptLow,ptHigh
715////    print xlow,xhigh
716////    print ylow,yhigh
717//     
718//      SetAxis bottom,xlow,xhigh
719//      SetAxis left ylow,yhigh
720//     
721//End
722
723
Note: See TracBrowser for help on using the repository browser.