source: sans/Dev/trunk/NCNR_User_Procedures/Analysis/Models/DAB_model_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: 4.1 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 (A^1) for model: "
16         Prompt qmax "Enter maximum q-value (A^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 (A)", "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 (A\\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)
32       
33        AddModelToStrings("DAB_Model","coef_DAB","parameters_DAB","DAB")
34End
35
36////////////////////////////////////////////////////
37// - sets up a dependency to a wrapper, not the actual SmearedModelFunction
38Proc PlotSmearedDAB_Model(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_DAB = {10.0, 40, 1.0}                                       //model  coef values to match unsmeared model above
51        make/o/t smear_parameters_DAB = {"Scale Factor, A ", "Correlation Length (A)", "Incoherent Bgd (cm-1)"}// parameter names
52        Edit smear_parameters_DAB,smear_coef_DAB                                        //display parameters in a table
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_DAB,smeared_qvals                               //
57        SetScale d,0,0,"1/cm",smeared_DAB                                                       //
58                                       
59        Variable/G gs_DAB=0
60        gs_DAB := fSmearedDAB_Model(smear_coef_DAB,smeared_DAB,smeared_qvals)   //this wrapper fills the STRUCT
61       
62        Display smeared_DAB vs smeared_qvals                                                                    //
63        ModifyGraph log=1,marker=29,msize=2,mode=4
64        Label bottom "q (A\\S-1\\M)"
65        Label left "Debye-Anderson-Brumberger Model (cm\\S-1\\M)"
66        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
67       
68        SetDataFolder root:
69        AddModelToStrings("SmearedDAB_Model","smear_coef_DAB","smear_parameters_DAB","DAB")
70End
71
72//AAO version
73Function DAB_model(cw,yw,xw) : FitFunc
74        Wave cw,yw,xw
75
76#if exists("DAB_modelX")
77        yw = DAB_modelX(cw,xw)
78#else
79        yw = fDAB_model(cw,xw)
80#endif
81        return(0)
82End
83
84Function fDAB_model(w,x) : FitFunc
85        Wave w
86        Variable x
87//       Input (fitting) variables are:
88        //[0] scale factor
89        //[1] correlation range
90        //[2] incoherent background
91//      give them nice names
92        Variable Izero, range, incoh
93        Izero = w[0]
94        range = w[1]
95        incoh = w[2]
96//      local variables
97        Variable inten, qval
98//      x is the q-value for the calculation
99        qval = x
100//      do the calculation and return the function value
101       
102        inten = Izero/(1 + (qval*range)^2)^2 + incoh
103        Return (inten)
104End
105/////////////////////////////////////////////////////////////////////////////////
106
107// this is all there is to the smeared calculation!
108Function SmearedDAB_Model(s) :FitFunc
109        Struct ResSmearAAOStruct &s
110
111////the name of your unsmeared model is the first argument
112        Smear_Model_20(DAB_Model,s.coefW,s.xW,s.yW,s.resW)
113
114        return(0)
115End
116
117//wrapper to calculate the smeared model as an AAO-Struct
118// fills the struct and calls the ususal function with the STRUCT parameter
119//
120// used only for the dependency, not for fitting
121//
122Function fSmearedDAB_Model(coefW,yW,xW)
123        Wave coefW,yW,xW
124       
125        String str = getWavesDataFolder(yW,0)
126        String DF="root:"+str+":"
127       
128        WAVE resW = $(DF+str+"_res")
129       
130        STRUCT ResSmearAAOStruct fs
131        WAVE fs.coefW = coefW   
132        WAVE fs.yW = yW
133        WAVE fs.xW = xW
134        WAVE fs.resW = resW
135       
136        Variable err
137        err = SmearedDAB_Model(fs)
138       
139        return (0)
140End
Note: See TracBrowser for help on using the repository browser.