# source:sans/Dev/trunk/NCNR_User_Procedures/SANS/Analysis/Models/Teubner_v40.ipf@379

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

Removed Angstrom symbol (Mac code) and replaced it with simply a capital "A" so strange symbols won't appear anymore on Win.

File size: 4.3 KB
Line
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma IgorVersion = 6.0
3
4
5////////////////////////////////////////////////
6// this procedure is for the Teubner-Strey Model
7//
8// 06 NOV 98 SRK
9////////////////////////////////////////////////
10
11Proc PlotTeubnerStreyModel(num,qmin,qmax)
12        Variable num=128,qmin=0.001,qmax=0.7
13        Prompt num "Enter number of data points for model: "
14        Prompt qmin "Enter minimum q-value (A^-1) for model: "
15        Prompt qmax "Enter maximum q-value (A^-1) for model: "
16
17        Make/O/D/n=(num) xwave_ts,ywave_ts
18        xwave_ts =  alog(log(qmin) + x*((log(qmax)-log(qmin))/num))
19        Make/O/D coef_ts = {0.1,-30,5000,0.1}
20        make/o/t parameters_ts = {"scale (a2)","c1","c2","bkg"}
21        Edit parameters_ts,coef_ts
22        Variable/G root:g_ts
23        g_ts := TeubnerStreyModel(coef_ts,ywave_ts,xwave_ts)
24//      ywave_ts := TeubnerStreyModel(coef_ts,xwave_ts)
25        Display ywave_ts vs xwave_ts
26        ModifyGraph log=1,marker=29,msize=2,mode=4
27        Label bottom "q (A\\S-1\\M)"
28        Label left "Intensity (cm\\S-1\\M)"
29        AutoPositionWindow/M=1/R=\$(WinName(0,1)) \$WinName(0,2)
30
32End
33
34///////////////////////////////////////////////////////////
35
36// - sets up a dependency to a wrapper, not the actual SmearedModelFunction
37Proc PlotSmearedTeubnerStreyModel(str)
38        String str
39        Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4)
40
41        // if any of the resolution waves are missing => abort
42        if(ResolutionWavesMissingDF(str))               //updated to NOT use global strings (in GaussUtils)
43                Abort
44        endif
45
46        SetDataFolder \$("root:"+str)
47
48        // Setup parameter table for model function
49        Make/O/D smear_coef_ts = {0.1,-30,5000,0.1}
50        make/o/t smear_parameters_ts = {"scale (a2)","c1","c2","bkg"}
51        Edit smear_parameters_ts,smear_coef_ts
52
53        // output smeared intensity wave, dimensions are identical to experimental QSIG values
54        // make extra copy of experimental q-values for easy plotting
55        Duplicate/O \$(str+"_q") smeared_ts,smeared_qvals
56        SetScale d,0,0,"1/cm",smeared_ts
57
58        Variable/G gs_ts=0
59        gs_ts := fSmearedTeubnerStreyModel(smear_coef_ts,smeared_ts,smeared_qvals)      //this wrapper fills the STRUCT
60
61        Display smeared_ts vs smeared_qvals
62        ModifyGraph log=1,marker=29,msize=2,mode=4
63        Label bottom "q (A\\S-1\\M)"
64        Label left "Intensity (cm\\S-1\\M)"
65        AutoPositionWindow/M=1/R=\$(WinName(0,1)) \$WinName(0,2)
66
67        SetDataFolder root:
69End
70
71//AAO version
72Function TeubnerStreyModel(cw,yw,xw) : FitFunc
73        Wave cw,yw,xw
74
75#if exists("TeubnerStreyModelX")
76        yw = TeubnerStreyModelX(cw,xw)
77#else
78        yw = fTeubnerStreyModel(cw,xw)
79#endif
80        return(0)
81End
82
83///////////////////////////////////////////////////////////////
84// unsmeared model calculation
85///////////////////////////
86Function fTeubnerStreyModel(w,x) : FitFunc
87        Wave w;Variable x
88
89        //Varialbes are:
90        //[0]   scale factor a2
91        //[1]   coeff c1
92        //[2]   coeff c2
93        //[3]   incoh. background
94
95        Variable inten,q2,q4
96
97        q2 = x*x
98        q4 = q2*q2
99        inten = 1.0/(w[0]+w[1]*q2+w[2]*q4)
100        inten += w[3]
101
102        return (inten)
103
104End
105
106Macro TeubnerStreyLengths()
107        If(exists("coef_ts")!=1)                //coefficients don't exist
108                Abort "You must plot the Teubner-Strey model before calculating the lengths"
109        Endif
110        // calculate the correlation length and the repeat distance
111        Variable a2,c1,c2,xi,dd
112        a2 = coef_ts[0]
113        c1 = coef_ts[1]
114        c2 = coef_ts[2]
115
116        xi = 0.5*sqrt(a2/c2) + c1/4/c2
117        xi = 1/sqrt(xi)
118
119        dd = 0.5*sqrt(a2/c2) - c1/4/c2
120        dd = 1/sqrt(dd)
121        dd *=2*Pi
122
123        Printf "The correlation length (the dispersion of d) xi = %g A\r",xi
124        Printf "The quasi-periodic repeat distance, d = %g A\r",dd
125
126End
127
128// this is all there is to the smeared calculation!
129Function SmearedTeubnerStreyModel(s) :FitFunc
130        Struct ResSmearAAOStruct &s
131
132////the name of your unsmeared model is the first argument
133        Smear_Model_20(TeubnerStreyModel,s.coefW,s.xW,s.yW,s.resW)
134
135        return(0)
136End
137
138//wrapper to calculate the smeared model as an AAO-Struct
139// fills the struct and calls the ususal function with the STRUCT parameter
140//
141// used only for the dependency, not for fitting
142//
143Function fSmearedTeubnerStreyModel(coefW,yW,xW)
144        Wave coefW,yW,xW
145
146        String str = getWavesDataFolder(yW,0)
147        String DF="root:"+str+":"
148
149        WAVE resW = \$(DF+str+"_res")
150
151        STRUCT ResSmearAAOStruct fs
152        WAVE fs.coefW = coefW
153        WAVE fs.yW = yW
154        WAVE fs.xW = xW
155        WAVE fs.resW = resW
156
157        Variable err
158        err = SmearedTeubnerStreyModel(fs)
159
160        return (0)
161End
Note: See TracBrowser for help on using the repository browser.