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

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

Changed Plot* and PlotSmeared?* naming schemes to be all consistent prefixes for the actual function name, so that the macros can be constructed from the function name, or vice versa.

also some tweaks to the wrapper to make sure that plot and append really work

File size: 4.0 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma IgorVersion = 6.0
3
4////////////////////////////////////////////////////
5//      C. Glinka, 11-22-98
6////////////////
7
8
9                                                                //Debye-Anderson-Brumberger
10
11
12Proc PlotDAB_Model(num,qmin,qmax)
13        Variable num=512, qmin=.001, qmax=.7
14        Prompt num "Enter number of data points for model: "
15        Prompt qmin "Enter minimum q-value (^1) for model: "
16         Prompt qmax "Enter maximum q-value (^1) for model: "
17//
18        Make/O/D/n=(num) xwave_DAB, ywave_DAB
19        xwave_DAB =  alog(log(qmin) + x*((log(qmax)-log(qmin))/num))
20        Make/O/D coef_DAB = {10.0, 40, 1.0}
21        make/o/t parameters_DAB = {"Scale Factor, A ", "Correlation Length ()", "Incoherent Bgd (cm-1)"}
22        Edit parameters_DAB, coef_DAB
23        Variable/G root:g_DAB
24        g_DAB  := DAB_Model(coef_DAB, ywave_DAB, xwave_DAB)
25//      ywave_DAB  := DAB_Model(coef_DAB, xwave_DAB)
26        Display ywave_DAB vs xwave_DAB
27        ModifyGraph marker=29, msize=2, mode=4
28        ModifyGraph log(left)=1
29        Label bottom "q (\\S-1\\M) "
30        Label left "Debye-Anderson-Brumberger Model (cm\\S-1\\M)"
31        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
32End
33
34////////////////////////////////////////////////////
35// - sets up a dependency to a wrapper, not the actual SmearedModelFunction
36Proc PlotSmearedDAB_Model(str)                                                         
37        String str
38        Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4)
39       
40        // if any of the resolution waves are missing => abort
41        if(ResolutionWavesMissingDF(str))               //updated to NOT use global strings (in GaussUtils)
42                Abort
43        endif
44       
45        SetDataFolder $("root:"+str)
46       
47        // Setup parameter table for model function
48        Make/O/D smear_coef_DAB = {10.0, 40, 1.0}                                       //model  coef values to match unsmeared model above
49        make/o/t smear_parameters_DAB = {"Scale Factor, A ", "Correlation Length ()", "Incoherent Bgd (cm-1)"}// parameter names
50        Edit smear_parameters_DAB,smear_coef_DAB                                        //display parameters in a table
51       
52        // output smeared intensity wave, dimensions are identical to experimental QSIG values
53        // make extra copy of experimental q-values for easy plotting
54        Duplicate/O $(str+"_q") smeared_DAB,smeared_qvals                               //
55        SetScale d,0,0,"1/cm",smeared_DAB                                                       //
56                                       
57        Variable/G gs_DAB=0
58        gs_DAB := fSmearedDAB_Model(smear_coef_DAB,smeared_DAB,smeared_qvals)   //this wrapper fills the STRUCT
59       
60        Display smeared_DAB vs smeared_qvals                                                                    //
61        ModifyGraph log=1,marker=29,msize=2,mode=4
62        Label bottom "q (\\S-1\\M)"
63        Label left "Debye-Anderson-Brumberger Model (cm\\S-1\\M)"
64        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
65       
66        SetDataFolder root:
67End
68
69//AAO version
70Function DAB_model(cw,yw,xw) : FitFunc
71        Wave cw,yw,xw
72
73#if exists("DAB_modelX")
74        yw = DAB_modelX(cw,xw)
75#else
76        yw = fDAB_model(cw,xw)
77#endif
78        return(0)
79End
80
81Function fDAB_model(w,x) : FitFunc
82        Wave w
83        Variable x
84//       Input (fitting) variables are:
85        //[0] scale factor
86        //[1] correlation range
87        //[2] incoherent background
88//      give them nice names
89        Variable Izero, range, incoh
90        Izero = w[0]
91        range = w[1]
92        incoh = w[2]
93//      local variables
94        Variable inten, qval
95//      x is the q-value for the calculation
96        qval = x
97//      do the calculation and return the function value
98       
99        inten = Izero/(1 + (qval*range)^2)^2 + incoh
100        Return (inten)
101End
102/////////////////////////////////////////////////////////////////////////////////
103
104// this is all there is to the smeared calculation!
105Function SmearedDAB_Model(s) :FitFunc
106        Struct ResSmearAAOStruct &s
107
108////the name of your unsmeared model is the first argument
109        Smear_Model_20(DAB_Model,s.coefW,s.xW,s.yW,s.resW)
110
111        return(0)
112End
113
114//wrapper to calculate the smeared model as an AAO-Struct
115// fills the struct and calls the ususal function with the STRUCT parameter
116//
117// used only for the dependency, not for fitting
118//
119Function fSmearedDAB_Model(coefW,yW,xW)
120        Wave coefW,yW,xW
121       
122        String str = getWavesDataFolder(yW,0)
123        String DF="root:"+str+":"
124       
125        WAVE resW = $(DF+str+"_res")
126       
127        STRUCT ResSmearAAOStruct fs
128        WAVE fs.coefW = coefW   
129        WAVE fs.yW = yW
130        WAVE fs.xW = xW
131        WAVE fs.resW = resW
132       
133        Variable err
134        err = SmearedDAB_Model(fs)
135       
136        return (0)
137End
Note: See TracBrowser for help on using the repository browser.