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