source: sans/Dev/trunk/NCNR_User_Procedures/Analysis/Models/Peak_Lorentz_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.5 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_Lorentz_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_Lorentz, ywave_Peak_Lorentz
14        xwave_Peak_Lorentz =  alog(log(qmin) + x*((log(qmax)-log(qmin))/num))
15        Make/O/D coef_Peak_Lorentz = {100.0, 0.05,0.005, 1.0}
16        make/o/t parameters_Peak_Lorentz = {"Scale Factor, I0 ", "Peak position (A^-1)", "Peak hwhm (A^-1)","Incoherent Bgd (cm-1)"}
17        Edit parameters_Peak_Lorentz, coef_Peak_Lorentz
18        Variable/G root:g_Peak_Lorentz
19        g_Peak_Lorentz  := Peak_Lorentz_Model(coef_Peak_Lorentz, ywave_Peak_Lorentz,xwave_Peak_Lorentz)
20//      ywave_Peak_Lorentz  := Peak_Lorentz_Model(coef_Peak_Lorentz, xwave_Peak_Lorentz)
21        Display ywave_Peak_Lorentz vs xwave_Peak_Lorentz
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 - Lorentzian (cm\\S-1\\M)"
26        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
27       
28        AddModelToStrings("Peak_Lorentz_Model","coef_Peak_Lorentz","parameters_Peak_Lorentz","Peak_Lorentz")
29//
30End
31
32////////////////////////////////////////////////////
33// - sets up a dependency to a wrapper, not the actual SmearedModelFunction
34Proc PlotSmearedPeak_Lorentz_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_Lorentz = {100.0, 0.05,0.005, 1.0}
47        make/o/t smear_parameters_Peak_Lorentz = {"Scale Factor, I0 ", "Peak position (A^-1)", "Peak hwhm (A^-1)","Incoherent Bgd (cm-1)"}
48        Edit smear_parameters_Peak_Lorentz,smear_coef_Peak_Lorentz                                      //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_Lorentz,smeared_qvals                              //
53        SetScale d,0,0,"1/cm",smeared_Peak_Lorentz                                                      //                                     
54               
55        Variable/G gs_Peak_Lorentz=0
56        gs_Peak_Lorentz := fSmearedPeak_Lorentz_Model(smear_coef_Peak_Lorentz,smeared_Peak_Lorentz,smeared_qvals)       //this wrapper fills the STRUCT
57
58        Display smeared_Peak_Lorentz 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_Lorentz Model (cm\\S-1\\M)"
62        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2) 
63       
64        AddModelToStrings("SmearedPeak_Lorentz_Model","smear_coef_Peak_Lorentz","smear_parameters_Peak_Lorentz","Peak_Lorentz")
65End
66
67
68//AAO version
69Function Peak_Lorentz_model(cw,yw,xw) : FitFunc
70        Wave cw,yw,xw
71
72#if exists("Peak_Lorentz_modelX")
73        yw = Peak_Lorentz_modelX(cw,xw)
74#else
75        yw = fPeak_Lorentz_model(cw,xw)
76#endif
77        return(0)
78End
79
80Function fPeak_Lorentz_model(w,x) : FitFunc
81        Wave w
82        Variable x
83//       Input (fitting) variables are:
84        //[0] scale factor
85        //[1] peak position
86        //[2] peak hwhm
87        //[3] incoherent background
88//      give them nice names
89        Variable I0, qpk, dq,bgd
90        I0 = w[0]
91        qpk = w[1]
92        dq = w[2]
93        bgd = w[3]
94       
95//      local variables
96        Variable inten, qval
97//      x is the q-value for the calculation
98        qval = x
99//      do the calculation and return the function value
100       
101        inten = I0/(1 + ((qval-qpk)/dq)^2) + bgd
102        Return (inten)
103End
104/////////////////////////////////////////////////////////////////////////////////
105
106// this is all there is to the smeared calculation!
107Function SmearedPeak_Lorentz_Model(s) :FitFunc
108        Struct ResSmearAAOStruct &s
109
110////the name of your unsmeared model is the first argument
111        Smear_Model_20(Peak_Lorentz_model,s.coefW,s.xW,s.yW,s.resW)
112
113        return(0)
114End
115
116//wrapper to calculate the smeared model as an AAO-Struct
117// fills the struct and calls the ususal function with the STRUCT parameter
118//
119// used only for the dependency, not for fitting
120//
121Function fSmearedPeak_Lorentz_Model(coefW,yW,xW)
122        Wave coefW,yW,xW
123       
124        String str = getWavesDataFolder(yW,0)
125        String DF="root:"+str+":"
126       
127        WAVE resW = $(DF+str+"_res")
128       
129        STRUCT ResSmearAAOStruct fs
130        WAVE fs.coefW = coefW   
131        WAVE fs.yW = yW
132        WAVE fs.xW = xW
133        WAVE fs.resW = resW
134       
135        Variable err
136        err = SmearedPeak_Lorentz_Model(fs)
137       
138        return (0)
139End
Note: See TracBrowser for help on using the repository browser.