source: sans/Analysis/branches/ajj_23APR07/IGOR_Package_Files/Put in User Procedures/SANS_Models_v4.00/Packages/LinearizedFits/LinearizedFits_v40.ipf @ 273

Last change on this file since 273 was 273, checked in by srkline, 15 years ago

Lots of changes to filenames to bring them to "_v40"

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