source: sans/Dev/trunk/NCNR_User_Procedures/Analysis/Models/NewModels_2006/Debye_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: 3.7 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma IgorVersion = 6.0
3
4// plots the Debye function for polymer scattering
5//
6Proc PlotDebye(num,qmin,qmax)
7        Variable num=256,qmin=0.001,qmax=0.7
8        Prompt num "Enter number of data points for model: "
9        Prompt qmin "Enter minimum q-value (A^-1) for model: "
10        Prompt qmax "Enter maximum q-value (A^-1) for model: "
11       
12        make/O/D/N=(num) xwave_deb,ywave_deb
13        xwave_deb = alog( log(qmin) + x*((log(qmax)-log(qmin))/num) )
14        make/O/D coef_deb = {1.,50,0.001}
15        make/O/T parameters_deb = {"scale","Rg (A)","bkg (cm-1)"}
16        Edit parameters_deb,coef_deb
17       
18        Variable/G root:g_deb
19        g_deb := Debye(coef_deb,ywave_deb,xwave_deb)
20        Display ywave_deb vs xwave_deb
21        ModifyGraph marker=29,msize=2,mode=4,log=1
22        Label bottom "q (A\\S-1\\M)"
23        Label left "Intensity (cm\\S-1\\M)"
24        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
25       
26        AddModelToStrings("Debye","coef_deb","parameters_deb","deb")
27End
28
29///////////////////////////////////////////////////////////
30// - sets up a dependency to a wrapper, not the actual SmearedModelFunction
31Proc PlotSmearedDebye(str)                                                             
32        String str
33        Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4)
34       
35        // if any of the resolution waves are missing => abort
36        if(ResolutionWavesMissingDF(str))               //updated to NOT use global strings (in GaussUtils)
37                Abort
38        endif
39       
40        SetDataFolder $("root:"+str)
41       
42        // Setup parameter table for model function
43        make/O/D smear_coef_deb = {1.,50,0.001}
44        make/O/T smear_parameters_deb = {"scale","Rg (A)","bkg (cm-1)"}
45        Edit smear_parameters_deb,smear_coef_deb
46       
47        // output smeared intensity wave
48        Duplicate/O $(str+"_q") smeared_deb,smeared_qvals
49        SetScale d,0,0,"1/cm",smeared_deb
50                                       
51        Variable/G gs_deb=0
52        gs_deb := fSmearedDebye(smear_coef_deb,smeared_deb,smeared_qvals)       //this wrapper fills the STRUCT
53       
54        Display smeared_deb vs smeared_qvals
55        ModifyGraph log=1,marker=29,msize=2,mode=4
56        Label bottom "q (A\\S-1\\M)"
57        Label left "Intensity (cm\\S-1\\M)"
58        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
59       
60        SetDataFolder root:
61        AddModelToStrings("SmearedDebye","smear_coef_deb","smear_parameters_deb","deb")
62End
63       
64
65///////////////////////////////////////////////////////////////
66
67
68//AAO version, uses XOP if available
69// simply calls the original single point calculation with
70// a wave assignment (this will behave nicely if given point ranges)
71Function Debye(cw,yw,xw) : FitFunc
72        Wave cw,yw,xw
73       
74#if exists("DebyeX")
75        yw = DebyeX(cw,xw)
76#else
77        yw = fDebye(cw,xw)
78#endif
79        return(0)
80End
81
82Function fDebye(w,x) : FitFunc
83        Wave w
84        Variable x
85       
86        // variables are:
87        //[0] scale factor
88        //[1] radius of gyration [A]
89        //[2] background        [cm-1]
90       
91        Variable scale,rg,bkg
92        scale = w[0]
93        rg = w[1]
94        bkg = w[2]
95       
96        // calculates (scale*debye)+bkg
97        Variable Pq,qr2
98       
99        if(x*Rg < 1e-3)         //added Oct 2008 to avoid numerical errors at low arg values
100                return(scale+bkg)
101        endif
102       
103        qr2=(x*rg)^2
104        Pq = 2*(exp(-(qr2))-1+qr2)/qr2^2
105       
106        //scale
107        Pq *= scale
108        // then add in the background
109        return (Pq+bkg)
110End
111
112//wrapper to calculate the smeared model as an AAO-Struct
113// fills the struct and calls the ususal function with the STRUCT parameter
114//
115// used only for the dependency, not for fitting
116//
117Function fSmearedDebye(coefW,yW,xW)
118        Wave coefW,yW,xW
119       
120        String str = getWavesDataFolder(yW,0)
121        String DF="root:"+str+":"
122       
123        WAVE resW = $(DF+str+"_res")
124       
125        STRUCT ResSmearAAOStruct fs
126        WAVE fs.coefW = coefW   
127        WAVE fs.yW = yW
128        WAVE fs.xW = xW
129        WAVE fs.resW = resW
130       
131        Variable err
132        err = SmearedDebye(fs)
133       
134        return (0)
135End
136
137// this is all there is to the smeared calculation!
138Function SmearedDebye(s) :FitFunc
139        Struct ResSmearAAOStruct &s
140
141//      the name of your unsmeared model (AAO) is the first argument
142        Smear_Model_20(Debye,s.coefW,s.xW,s.yW,s.resW)
143
144        return(0)
145End
146       
Note: See TracBrowser for help on using the repository browser.