# source:sans/Dev/trunk/NCNR_User_Procedures/Analysis/Models/NewModels_2008/GaussLorentzGel_v40.ipf@510

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

Simple change in all of the model function files to include the name of the parameter wave in the Keyword=list that is generated when a model is plotted. This is becoming an issue where the proper parameter wave can't be deduced from just the suffix, then there is nothing to put in the table.

I should have added this when I initially wrote the wrapper...

File size: 4.8 KB
Line
1#pragma rtGlobals=1             // Use modern global access method.
2////////////////////////////////////////////////////
3//
4// model to calculate the scattering from a gel
5//
6// Reference:G. Evmenenko, E. Theunissedn, K. Mortensen, H. Reynaers
7//                                      Polymer 42 (2001) 2907-2913.
8//
9//
10// Steve Kline 14 JUL 2004 (for Robert Knott)
11// updated 6/2008
12//
13////////////////////////////////////////////////////
14
15//this macro sets up all the necessary parameters and waves that are
16//needed to calculate the model function.
17//
18Proc PlotGaussLorentzGel(num,qmin,qmax)
19        Variable num=256, qmin=.001, qmax=.7
20        Prompt num "Enter number of data points for model: "
21        Prompt qmin "Enter minimum q-value (A^1) for model: "
22        Prompt qmax "Enter maximum q-value (A^1) for model: "
23//
24        Make/O/D/n=(num) xwave_GL_Gel, ywave_GL_Gel
25        xwave_GL_Gel =  alog(log(qmin) + x*((log(qmax)-log(qmin))/num))
26        Make/O/D coef_GL_Gel = {100,100,50,20,0}
27        make/o/t parameters_GL_Gel = {"Gauss Scale Factor, IG(0) ", "Static correlation Z (A)","Lorentzian Scale Factor IL(0)","Dynamic correlation z (A)","Incoherent Bgd (cm-1)"}
28        Edit parameters_GL_Gel, coef_GL_Gel
29        ModifyTable width(parameters_GL_Gel)=160
30
31        Variable/G root:g_GL_Gel
32        g_GL_gel  := GaussLorentzGel(coef_GL_Gel, ywave_GL_Gel, xwave_GL_Gel)
33        Display ywave_GL_Gel vs xwave_GL_Gel
34        ModifyGraph log=1,marker=29, msize=2, mode=4
35        Label bottom "q (A\\S-1\\M) "
36        Label left "I(q) (cm\\S-1\\M)"
37        AutoPositionWindow/M=1/R=\$(WinName(0,1)) \$WinName(0,2)
38
40//
41End
42
43
44// - sets up a dependency to a wrapper, not the actual SmearedModelFunction
45Proc PlotSmearedGaussLorentzGel(str)
46        String str
47        Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4)
48
49        // if any of the resolution waves are missing => abort
50        if(ResolutionWavesMissingDF(str))               //updated to NOT use global strings (in GaussUtils)
51                Abort
52        endif
53
54        SetDataFolder \$("root:"+str)
55
56        // Setup parameter table for model function
57        Make/O/D smear_coef_GL_Gel = {100,100,50,20,0}
58        make/o/t smear_parameters_GL_Gel = {"Gauss Scale Factor, IG(0) ", "Static correlation Z (A)","Lorentzian Scale Factor IL(0)","Dynamic correlation z (A)","Incoherent Bgd (cm-1)"}
59        Edit smear_parameters_GL_Gel,smear_coef_GL_Gel                                  //display parameters in a table
60        ModifyTable width(smear_parameters_GL_Gel)=160
61
62        Duplicate/O \$(str+"_q") smeared_GL_Gel,smeared_qvals
63        SetScale d,0,0,"1/cm",smeared_GL_Gel
64
65        Variable/G gs_GL_Gel=0
66        gs_GL_Gel := fSmearedGaussLorentzGel(smear_coef_GL_Gel,smeared_GL_Gel,smeared_qvals)    //this wrapper fills the STRUCT
67        Display smeared_GL_Gel vs smeared_qvals
68
69        ModifyGraph log=1,marker=29,msize=2,mode=4
70        Label bottom "q (\\S-1\\M)"
71        Label left "Intensity (cm\\S-1\\M)"
72        AutoPositionWindow/M=1/R=\$(WinName(0,1)) \$WinName(0,2)
73
74        SetDataFolder root:
76End
77
78//AAO version, uses XOP if available
79// simply calls the original single point calculation with
80// a wave assignment (this will behave nicely if given point ranges)
81Function GaussLorentzGel(cw,yw,xw) : FitFunc
82        Wave cw,yw,xw
83
84#if exists("GaussLorentzGelX")
85        yw = GaussLorentzGelX(cw,xw)
86#else
87        yw = fGaussLorentzGel(cw,xw)
88#endif
89        return(0)
90End
91
92//
93Function fGaussLorentzGel(w,x) : FitFunc
94        Wave w
95        Variable x
96//       Input (fitting) variables are:
97        //[0] Gaussian scale factor
98        //[1] Gaussian (static) screening length
99        //[2] Lorentzian (fluctuation) scale factor
100        //[3] Lorentzian screening length
101        //[4] incoherent background
102//      give them nice names
103        Variable Ig0,gg,Il0,ll,bgd
104        Ig0 = w[0]
105        gg = w[1]
106        Il0 = w[2]
107        ll = w[3]
108        bgd = w[4]
109
110//      local variables
111        Variable inten
112
113        inten = Ig0*exp(-x*x*gg*gg/2) + Il0/(1 + (x*ll)^2) + bgd
114        Return (inten)
115End
116
117//
118Function fSmearedGaussLorentzGel(coefW,yW,xW)
119        Wave coefW,yW,xW
120
121        String str = getWavesDataFolder(yW,0)
122        String DF="root:"+str+":"
123
124        WAVE resW = \$(DF+str+"_res")
125
126        STRUCT ResSmearAAOStruct fs
127        WAVE fs.coefW = coefW           //is this the proper way to populate? seems redundant...
128        WAVE fs.yW = yW
129        WAVE fs.xW = xW
130        WAVE fs.resW = resW
131
132        Variable err
133        err = SmearedGaussLorentzGel(fs)
134
135        return (0)
136End
137
138// smeared calculation, AAO and using a structure...
139// defined as as STRUCT, there can never be a dependency linked directly to this function
140// - so set a dependency to the wrapper
141//
142// like the unsmeared function, AAO is equivalent to a wave assignment to the point calculation
143// - but now the function passed is an AAO function
144//
145// Smear_Model_20() takes care of what calculation is done, depending on the resolution information
146//
147//
148Function SmearedGaussLorentzGel(s) : FitFunc
149        Struct ResSmearAAOStruct &s
150
151////the name of your unsmeared model is the first argument
152        Smear_Model_20(GaussLorentzGel,s.coefW,s.xW,s.yW,s.resW)
153
154        return(0)
155End
Note: See TracBrowser for help on using the repository browser.