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

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

LOTS of changes to the analysis ipf files:

-- see sphere.ipf for the simplest example of the changes --

  • #pragma Igor 6
  • #if directive to look for XOP
  • AAO unsmeared functions
  • STRUCT functions for smearing (also AAO)
  • new wrappers for dependencies to struct functions

(2006 models have NOT been completed yet, only the old models)

  • loading data files into data folders (PlotUtils?) + some streamlining of the loaders
  • Smear_Model_N is now AAO + some streamlining of the quadrature code

-- SHS and SW structure factor XOPs are crashing (need DP wave, I may have old XOP)
-- this breaks fitting of the smeared models until wrappers can be devised
-- all packages will be broken due to the new data folder structure
-- multiple instances of functions will now cause problems (MSA)
-- RPA model is a problem with its odd functional form (extra wave)

-- lots of other carnage to follow as the bugs and typos are shaken out

24 JUL 2007 SRK

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