# source:sans/Dev/trunk/NCNR_User_Procedures/Analysis/Models/NewModels_2008/CorrelationLengthModel_v40.ipf@445

Last change on this file since 445 was 445, checked in by srkline, 14 years ago

Adding a pile of new model functions. Some are from Boualem, some old code from Danilo, some from me.

As far as I can tell, these replicate the original references (not the empirical models).

Help file and XOPs have net been done yet.

File size: 5.0 KB
Line
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma IgorVersion=6.0
3
4////////////////////////////////////////////////////
5//
6// an empirical model containing low Q power law scattering + a lorentzian at higher Q
7//
8// B. Hammouda OCT 2008
9//
10//
11// updated for use with latest macros SRK Nov 2008
12//
13////////////////////////////////////////////////////
14
15//
16Proc PlotCorrLength(num,qmin,qmax)
17        Variable num=200, qmin=0.001, qmax=0.7
18        Prompt num "Enter number of data points for model: "
19        Prompt qmin "Enter minimum q-value (^-1) for model: "
20        Prompt qmax "Enter maximum q-value (^-1) for model: "
21//
22        Make/O/D/n=(num) xwave_CorrLength, ywave_CorrLength
23        xwave_CorrLength =  alog(log(qmin) + x*((log(qmax)-log(qmin))/num))
24        Make/O/D coef_CorrLength = {1e-6, 3, 10, 50.0,2,0.1}
25        make/o/t parameters_CorrLength = {"Porod Scale", "Porod Exponent","Lorentzian Scale","Lor Screening Length [A]","Lorentzian Exponent","Bgd [1/cm]"}     //CH#2
26        Edit parameters_CorrLength, coef_CorrLength
27
28        Variable/G root:g_CorrLength
29        g_CorrLength := CorrLength(coef_CorrLength, ywave_CorrLength, xwave_CorrLength)
30        Display ywave_CorrLength vs xwave_CorrLength
31        ModifyGraph marker=29, msize=2, mode=4
32        ModifyGraph log=1,grid=1,mirror=2
33        Label bottom "q (\\S-1\\M) "
34        Label left "I(q) (cm\\S-1\\M)"
35        AutoPositionWindow/M=1/R=\$(WinName(0,1)) \$WinName(0,2)
36
38//
39End
40
41
42//
43//no input parameters are necessary, it MUST use the experimental q-values
44// from the experimental data read in from an AVE/QSIG data file
45////////////////////////////////////////////////////
46// - sets up a dependency to a wrapper, not the actual SmearedModelFunction
47Proc PlotSmearedCorrLength(str)
48        String str
49        Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4)
50
51        // if any of the resolution waves are missing => abort
52        if(ResolutionWavesMissingDF(str))               //updated to NOT use global strings (in GaussUtils)
53                Abort
54        endif
55
56        SetDataFolder \$("root:"+str)
57
58        // Setup parameter table for model function
59        Make/O/D smear_coef_CorrLength = {1e-6, 3, 10, 50.0,2,0.1}
60        make/o/t smear_parameters_CorrLength = {"Porod Scale", "Porod Exponent","Lorentzian Scale","Lor Screening Length [A]","Lorentzian Exponent","Bgd [1/cm]"}
61        Edit smear_parameters_CorrLength,smear_coef_CorrLength                                  //display parameters in a table
62
63        // output smeared intensity wave, dimensions are identical to experimental QSIG values
64        // make extra copy of experimental q-values for easy plotting
65        Duplicate/O \$(str+"_q") smeared_CorrLength,smeared_qvals
66        SetScale d,0,0,"1/cm",smeared_CorrLength
67
68        Variable/G gs_CorrLength=0
69        gs_CorrLength := fSmearedCorrLength(smear_coef_CorrLength,smeared_CorrLength,smeared_qvals)     //this wrapper fills the STRUCT
70
71        Display smeared_CorrLength vs smeared_qvals
72        ModifyGraph log=1,marker=29,msize=2,mode=4
73        Label bottom "q (\\S-1\\M)"
74        Label left "I(q) (cm\\S-1\\M)"
75        AutoPositionWindow/M=1/R=\$(WinName(0,1)) \$WinName(0,2)
76
77        SetDataFolder root:
79End
80
81
82//
83//AAO version, uses XOP if available
84// simply calls the original single point calculation with
85// a wave assignment (this will behave nicely if given point ranges)
86Function CorrLength(cw,yw,xw) : FitFunc
87        Wave cw,yw,xw
88
89#if exists("CorrLengthX")
90        yw = CorrLengthX(cw,xw)
91#else
92        yw = fCorrLength(cw,xw)
93#endif
94        return(0)
95End
96
97//
98// unsmeared model calculation
99//
100Function fCorrLength(w,x) : FitFunc
101        Wave w
102        Variable x
103
104        // variables are:
105        //[0] Porod term scaling
106        //[1] Porod exponent
107        //[2] Lorentzian term scaling
108        //[3] Lorentzian screening length [A]
109        //[4] Lorentzian exponent
110        //[5] background
111
112        Variable aa,nn,cc,LL,mm,bgd
113        aa = w[0]
114        nn = w[1]
115        cc = w[2]
116        LL=w[3]
117        mm=w[4]
118        bgd=w[5]
119//      local variables
120        Variable inten, qval
121//      x is the q-value for the calculation
122        qval = x
123//      do the calculation and return the function value
124
125        inten = aa/(qval)^nn + cc/(1 + (qval*LL)^mm) + bgd
126
127        Return (inten)
128
129End
130
131
132///////////////////////////////////////////////////////////////
133// smeared model calculation
134//
135// you don't need to do anything with this function, as long as
136// your CorrLength works correctly, you get the resolution-smeared
138//
139// this is all there is to the smeared model calculation!
140Function SmearedCorrLength(s) : FitFunc
141        Struct ResSmearAAOStruct &s
142
143//      the name of your unsmeared model (AAO) is the first argument
144        Smear_Model_20(CorrLength,s.coefW,s.xW,s.yW,s.resW)
145
146        return(0)
147End
148
149
150///////////////////////////////////////////////////////////////
151
152
153// nothing to change here
154//
155//wrapper to calculate the smeared model as an AAO-Struct
156// fills the struct and calls the ususal function with the STRUCT parameter
157//
158// used only for the dependency, not for fitting
159//
160Function fSmearedCorrLength(coefW,yW,xW)
161        Wave coefW,yW,xW
162
163        String str = getWavesDataFolder(yW,0)
164        String DF="root:"+str+":"
165
166        WAVE resW = \$(DF+str+"_res")
167
168        STRUCT ResSmearAAOStruct fs
169        WAVE fs.coefW = coefW
170        WAVE fs.yW = yW
171        WAVE fs.xW = xW
172        WAVE fs.resW = resW
173
174        Variable err
175        err = SmearedCorrLength(fs)
176
177        return (0)
178End
Note: See TracBrowser for help on using the repository browser.