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