source: sans/Analysis/branches/ajj_23APR07/IGOR_Package_Files/Put in User Procedures/SANS_Models_v3.00/Power_Law_model.ipf @ 153

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

Changed Plot* and PlotSmeared?* naming schemes to be all consistent prefixes for the actual function name, so that the macros can be constructed from the function name, or vice versa.

also some tweaks to the wrapper to make sure that plot and append really work

File size: 4.1 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma IgorVersion = 6.0
3
4////////////////////////////////////////////////////
5//      J. Barker, 2-10-99
6//////////////////////////////////
7Proc PlotPower_Law_Model(num,qmin,qmax)
8        Variable num=512, qmin=.001, qmax=.2
9        Prompt num "Enter number of data points for model: "
10        Prompt qmin "Enter minimum q-value (^1) for model: "
11         Prompt qmax "Enter maximum q-value (^1) for model: "
12//
13        Make/O/D/n=(num) xwave_Power_Law, ywave_Power_Law
14        xwave_Power_Law =  alog(log(qmin) + x*((log(qmax)-log(qmin))/num))
15        Make/O/D coef_Power_Law = {1e-6, 4.0, 1.0}
16        make/o/t parameters_Power_Law = {"Coefficient, A ", "(-)Power","Incoherent Bgd (cm-1)"}
17        Edit parameters_Power_Law, coef_Power_Law
18        Variable/G root:g_Power_Law
19        g_Power_Law  := Power_Law_Model(coef_Power_Law, ywave_Power_Law, xwave_Power_Law)
20//      ywave_Power_Law  := Power_Law_Model(coef_Power_Law, xwave_Power_Law)
21        Display ywave_Power_Law vs xwave_Power_Law
22        ModifyGraph marker=29, msize=2, mode=4
23        ModifyGraph log(left)=1
24        ModifyGraph log(bottom)=1
25        Label bottom "q (\\S-1\\M) "
26        Label left "Power-Law (cm\\S-1\\M)"
27        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
28//
29End
30
31////////////////////////////////////////////////////
32// - sets up a dependency to a wrapper, not the actual SmearedModelFunction
33Proc PlotSmearedPower_Law_Model(str)                                                           
34        String str
35        Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4)
36       
37        // if any of the resolution waves are missing => abort
38        if(ResolutionWavesMissingDF(str))               //updated to NOT use global strings (in GaussUtils)
39                Abort
40        endif
41       
42        SetDataFolder $("root:"+str)
43       
44        // Setup parameter table for model function
45        Make/O/D smear_coef_Power_Law = {1e-6, 4.0, 1.0}
46        make/o/t smear_parameters_Power_Law = {"Coefficient, A ", "(-)Power","Incoherent Bgd (cm-1)"}
47        Edit smear_parameters_Power_Law,smear_coef_Power_Law                                    //display parameters in a table
48       
49        // output smeared intensity wave, dimensions are identical to experimental QSIG values
50        // make extra copy of experimental q-values for easy plotting
51        Duplicate/O $(str+"_q") smeared_Power_Law,smeared_qvals                         //
52        SetScale d,0,0,"1/cm",smeared_Power_Law                                                 //
53                                       
54               
55        Variable/G gs_Power_Law=0
56        gs_Power_Law := fSmearedPower_Law_Model(smear_coef_Power_Law,smeared_Power_Law,smeared_qvals)   //this wrapper fills the STRUCT
57       
58        Display smeared_Power_Law vs smeared_qvals                                                                      //
59        ModifyGraph log=1,marker=29,msize=2,mode=4
60        Label bottom "q (\\S-1\\M)"
61        Label left "Power_Law (cm\\S-1\\M)"
62        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
63       
64        SetDataFolder root:
65End     // end macro PlotSmearedPower_Law
66
67//AAO version
68Function Power_Law_Model(cw,yw,xw) : FitFunc
69        Wave cw,yw,xw
70
71#if exists("Power_Law_ModelX")
72        yw = Power_Law_ModelX(cw,xw)
73#else
74        yw = fPower_Law_Model(cw,xw)
75#endif
76        return(0)
77End
78
79Function fPower_Law_Model(w,x) : FitFunc
80        Wave w
81        Variable x
82//       Input (fitting) variables are:
83        //[0] Coefficient
84        //[1] (-) Power
85        //[2] incoherent background
86//      give them nice names
87        Variable A, m,bgd
88        A = w[0]
89        m = w[1]
90        bgd = w[2]
91       
92//      local variables
93        Variable inten, qval
94//      x is the q-value for the calculation
95        qval = x
96//      do the calculation and return the function value
97       
98        inten = A*qval^-m + bgd
99        Return (inten)
100End
101/////////////////////////////////////////////////////////////////////////////////
102
103
104// this is all there is to the smeared calculation!
105Function SmearedPower_Law_Model(s) :FitFunc
106        Struct ResSmearAAOStruct &s
107
108////the name of your unsmeared model is the first argument
109        Smear_Model_20(Power_Law_model,s.coefW,s.xW,s.yW,s.resW)
110
111        return(0)
112End
113
114//wrapper to calculate the smeared model as an AAO-Struct
115// fills the struct and calls the ususal function with the STRUCT parameter
116//
117// used only for the dependency, not for fitting
118//
119Function fSmearedPower_Law_Model(coefW,yW,xW)
120        Wave coefW,yW,xW
121       
122        String str = getWavesDataFolder(yW,0)
123        String DF="root:"+str+":"
124       
125        WAVE resW = $(DF+str+"_res")
126       
127        STRUCT ResSmearAAOStruct fs
128        WAVE fs.coefW = coefW   
129        WAVE fs.yW = yW
130        WAVE fs.xW = xW
131        WAVE fs.resW = resW
132       
133        Variable err
134        err = SmearedPower_Law_Model(fs)
135       
136        return (0)
137End
Note: See TracBrowser for help on using the repository browser.