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