source: sans/Analysis/branches/ajj_23APR07/IGOR_Package_Files/Put in User Procedures/SANS_Models_v3.00/NewModels_2006/Debye.ipf @ 151

Last change on this file since 151 was 151, checked in by srkline, 15 years ago

(1) - cursors can now be used to select a subrange of USANS data to fit. This is done by th fit wrapper, assigning a subrange of resW to the struct

(2) all of the smeared model functions are now in the latest form of Smear_Model_N() that is NOT a pointwise calculation anymore, since the USANS matrix smearing in inherently not so.

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