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(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 | End |
---|
30 | |
---|
31 | //////////////////////////////////////////////////// |
---|
32 | // - sets up a dependency to a wrapper, not the actual SmearedModelFunction |
---|
33 | Proc PlotSmearedPower_Law(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: |
---|
65 | End // end macro PlotSmearedPower_Law |
---|
66 | |
---|
67 | //AAO version |
---|
68 | Function 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) |
---|
77 | End |
---|
78 | |
---|
79 | Function 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) |
---|
100 | End |
---|
101 | ///////////////////////////////////////////////////////////////////////////////// |
---|
102 | |
---|
103 | |
---|
104 | // this is all there is to the smeared calculation! |
---|
105 | Function SmearedPower_Law_Model(s) :FitFunc |
---|
106 | Struct ResSmearAAOStruct &s |
---|
107 | |
---|
108 | ////the name of your unsmeared model is the first argument |
---|
109 | s.yW = Smear_Model_20(Power_Law_model,s.coefW,s.xW,s.resW) |
---|
110 | |
---|
111 | return(0) |
---|
112 | End |
---|
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 | // |
---|
119 | Function 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) |
---|
137 | End |
---|