source: sans/Analysis/branches/ajj_23APR07/IGOR_Package_Files/Put in User Procedures/SANS_Models_v3.00/ProlateForm.ipf @ 166

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

Modified all procedure files to add to the keyword=value strings to identify the function, coefficients, and suffix once the model is plotted (and the objects will exist)

a one-liner in the Plot and PlotSmeared? macros.

  • necessary for smoother functioning of the wrapper panel.
File size: 7.7 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma IgorVersion = 6.0
3
4////////////////////////////////////////////////
5// GaussUtils.proc and PlotUtils.proc MUST be included for the smearing calculation to compile
6// Adopting these into the experiment will insure that they are always present
7////////////////////////////////////////////////
8// this function is for the form factor of a prolate ellipsoid
9//
10// 06 NOV 98 SRK
11////////////////////////////////////////////////
12
13Proc PlotProlateForm(num,qmin,qmax)
14        Variable num=128,qmin=0.001,qmax=0.7
15        Prompt num "Enter number of data points for model: "
16        Prompt qmin "Enter minimum q-value (^-1) for model: "
17        Prompt qmax "Enter maximum q-value (^-1) for model: "
18       
19        Make/O/D/n=(num) xwave_pef,ywave_pef
20        xwave_pef =  alog(log(qmin) + x*((log(qmax)-log(qmin))/num))
21        Make/O/D coef_pef = {1.,100,50,110,60,1e-6,2e-6,0.001}
22        make/o/t parameters_pef = {"scale","major core radius (A)","minor core radius (A)","major shell radius (A)","minor shell radius (A)","Contrast (core-shell) (A-2)","Constrast (shell-solvent) (A-2)","bkg (cm-1)"}
23        Edit parameters_pef,coef_pef
24        Variable/G root:g_pef
25        g_pef := ProlateForm(coef_pef,ywave_pef,xwave_pef)
26//      ywave_pef := ProlateForm(coef_pef,xwave_pef)
27        Display ywave_pef vs xwave_pef
28        ModifyGraph log=1,marker=29,msize=2,mode=4
29        Label bottom "q (\\S-1\\M)"
30        Label left "Intensity (cm\\S-1\\M)"
31        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
32       
33        AddModelToStrings("ProlateForm","coef_pef","pef")
34End
35
36///////////////////////////////////////////////////////////
37// - sets up a dependency to a wrapper, not the actual SmearedModelFunction
38Proc PlotSmearedProlateForm(str)                                                               
39        String str
40        Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4)
41       
42        // if any of the resolution waves are missing => abort
43        if(ResolutionWavesMissingDF(str))               //updated to NOT use global strings (in GaussUtils)
44                Abort
45        endif
46       
47        SetDataFolder $("root:"+str)
48       
49        // Setup parameter table for model function
50        Make/O/D smear_coef_pef = {1.,100,50,110,60,1e-6,2e-6,0.001}
51        make/o/t smear_parameters_pef = {"scale","major core radius (A)","minor core radius (A)","major shell radius (A)","minor shell radius (A)","Contrast (core-shell) (A-2)","Contrast (shell-solvent) (A-2)","bkg (cm-1)"}
52        Edit smear_parameters_pef,smear_coef_pef
53       
54        // output smeared intensity wave, dimensions are identical to experimental QSIG values
55        // make extra copy of experimental q-values for easy plotting
56        Duplicate/O $(str+"_q") smeared_pef,smeared_qvals                               //**** mod
57        SetScale d,0,0,"1/cm",smeared_pef                                               
58               
59        Variable/G gs_pef=0
60        gs_pef := fSmearedProlateForm(smear_coef_pef,smeared_pef,smeared_qvals) //this wrapper fills the STRUCT
61
62        Display smeared_pef vs smeared_qvals
63        ModifyGraph log=1,marker=29,msize=2,mode=4
64        Label bottom "q (\\S-1\\M)"
65        Label left "Intensity (cm\\S-1\\M)"
66        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2) 
67       
68        SetDataFolder root:
69        AddModelToStrings("SmearedProlateForm","smear_coef_pef","pef")
70End
71
72//AAO version
73Function ProlateForm(cw,yw,xw) : FitFunc
74        Wave cw,yw,xw
75
76#if exists("ProlateFormX")
77        yw = ProlateFormX(cw,xw)
78#else
79        yw = fProlateForm(cw,xw)
80#endif
81        return(0)
82End
83
84///////////////////////////////////////////////////////////////
85// unsmeared model calculation
86///////////////////////////
87Function fProlateForm(w,x) : FitFunc
88        Wave w
89        Variable x
90
91//The input variables are (and output)
92        //[0] scale
93        //[1] crmaj, major radius of core       []
94        //[2] crmin, minor radius of core
95        //[3] trmaj, overall major radius
96        //[4] trmin, overall minor radius
97        //[5] delpc, SLD difference (core-shell)        [-2]
98        //[6] delps, SLD difference (shell-solvent)
99        //[7] bkg [cm-1]
100        Variable scale,crmaj,crmin,trmaj,trmin,delpc,delps,bkg
101        scale = w[0]
102        crmaj = w[1]
103        crmin = w[2]
104        trmaj = w[3]
105        trmin = w[4]
106        delpc = w[5]
107        delps = w[6]
108        bkg = w[7]
109
110// local variables
111        Variable yyy,va,vb,ii,nord,zi,qq,summ,nfn,npro,answer,prolatevol
112        String weightStr,zStr
113       
114        weightStr = "gauss76wt"
115        zStr = "gauss76z"
116
117//      if wt,z waves don't exist, create them
118
119        if (WaveExists($weightStr) == 0) // wave reference is not valid,
120                Make/D/N=76 $weightStr,$zStr
121                Wave w76 = $weightStr
122                Wave z76 = $zStr                // wave references to pass
123                Make76GaussPoints(w76,z76)     
124        else
125                if(exists(weightStr) > 1)
126                         Abort "wave name is already in use"    // execute if condition is false
127                endif
128                Wave w76 = $weightStr
129                Wave z76 = $zStr
130        endif
131
132// set up the integration
133        // end points and weights
134        nord = 76
135        nfn = 2         //only <f^2> is calculated
136        npro = 1        // PROLATE ELLIPSOIDS
137        va =0
138        vb =1
139//move this zi(i) evaluation inside other nord loop, since I don't have an array
140//      i=0
141//      do
142//       zi[i] = ( z76[i]*(vb-va) + vb + va )/2.0
143 //       i +=1
144 //     while (i<nord)
145//
146// evaluate at Gauss points
147        // remember to index from 0,size-1
148
149        qq = x          //current x point is the q-value for evaluation
150        summ = 0.0
151        ii=0
152        do
153                //printf "top of nord loop, i = %g\r",i
154                if(nfn ==1) //then              // "f1" required for beta factor
155                        if(npro ==1) //then     // prolate
156                                zi = ( z76[ii]*(vb-va) + vb + va )/2.0 
157//           yyy = w76[ii]*gfn1(zi,crmaj,crmin,trmaj,trmin,delpc,delps,qq)
158                        Endif
159//
160                        if(npro ==0) //then     // oblate 
161                                zi = ( z76[ii]*(vb-va) + vb + va )/2.0
162//            yyy = w76[i]*gfn3(zi,crmaj,crmin,trmaj,trmin,delpc,delps,qq)
163                        Endif
164                Endif           //nfn = 1
165          //
166                if(nfn !=1) //then              //calculate"f2" = <f^2> = averaged form factor
167                        if(npro ==1) //then     //prolate
168                                zi = ( z76[ii]*(vb-va) + vb + va )/2.0
169                                yyy = w76[ii]*gfn2(zi,crmaj,crmin,trmaj,trmin,delpc,delps,qq)
170                                //printf "yyy = %g\r",yyy
171                        Endif
172//
173                        if(npro ==0) //then     //oblate
174                                zi = ( z76[ii]*(vb-va) + vb + va )/2.0
175//              yyy = w76[ii]*gfn4(zi,crmaj,crmin,trmaj,trmin,delpc,delps,qq)
176                        Endif
177                Endif           //nfn <>1
178         
179                summ = yyy + summ               // get running total of integral
180                ii+=1
181        while (ii<nord)                         // end of loop over quadrature points
182//   
183// calculate value of integral to return
184
185        answer = (vb-va)/2.0*summ
186       
187        //normailze by particle volume
188        prolatevol = 4*Pi/3*trmaj*trmin*trmin
189        answer /= prolatevol
190       
191        // rescale from 1/ to 1/cm
192        answer *= 1.0e8
193        //scale (arb)
194        answer *= scale
195        ////then add in background
196        answer += bkg
197
198        Return (answer)
199End     //prolate form factor
200
201//
202//     FUNCTION gfn2:    CONTAINS F(Q,A,B,mu)**2  AS GIVEN
203//                       BY (53) AND (56,57) IN CHEN AND
204//                       KOTLARCHYK REFERENCE
205//
206//     <PROLATE ELLIPSOIDS>
207//
208Function gfn2(xx,crmaj,crmin,trmaj,trmin,delpc,delps,qq)
209        Variable xx,crmaj,crmin,trmaj,trmin,delpc,delps,qq
210        // local variables
211        Variable aa,bb,u2,ut2,uq,ut,vc,vt,gfnc,gfnt,tgfn,gfn2,pi43,gfn
212
213        PI43=4.0/3.0*PI
214        aa = crmaj
215        bb = crmin
216        u2 = (aa*aa*xx*xx + bb*bb*(1.0-xx*xx))
217        ut2 = (trmaj*trmaj*xx*xx + trmin*trmin*(1.0-xx*xx))
218        uq = sqrt(u2)*qq
219        ut= sqrt(ut2)*qq
220        vc = PI43*aa*bb*bb
221        vt = PI43*trmaj*trmin*trmin
222        gfnc = 3.0*(sin(uq)/uq/uq - cos(uq)/uq)/uq*vc*delpc
223        gfnt = 3.0*(sin(ut)/ut/ut - cos(ut)/ut)/ut*vt*delps
224        gfn = gfnc+gfnt
225        gfn2 = gfn*gfn
226       
227        return gfn2
228End             //function gfn2 for prolate ellipsoids
229
230
231// this is all there is to the smeared calculation!
232Function SmearedProlateForm(s) :FitFunc
233        Struct ResSmearAAOStruct &s
234
235////the name of your unsmeared model is the first argument
236        Smear_Model_20(ProlateForm,s.coefW,s.xW,s.yW,s.resW)
237
238        return(0)
239End
240
241//wrapper to calculate the smeared model as an AAO-Struct
242// fills the struct and calls the ususal function with the STRUCT parameter
243//
244// used only for the dependency, not for fitting
245//
246Function fSmearedProlateForm(coefW,yW,xW)
247        Wave coefW,yW,xW
248       
249        String str = getWavesDataFolder(yW,0)
250        String DF="root:"+str+":"
251       
252        WAVE resW = $(DF+str+"_res")
253       
254        STRUCT ResSmearAAOStruct fs
255        WAVE fs.coefW = coefW   
256        WAVE fs.yW = yW
257        WAVE fs.xW = xW
258        WAVE fs.resW = resW
259       
260        Variable err
261        err = SmearedProlateForm(fs)
262       
263        return (0)
264End
Note: See TracBrowser for help on using the repository browser.