source: sans/Release/trunk/NCNR_User_Procedures/SANS/Analysis/Models/Lorentz_model_v40.ipf @ 338

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

merging structural changes from Dev/trunk into Release/trunk

File size: 4.1 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 PlotLorentz_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_Lorentz, ywave_Lorentz
14        xwave_Lorentz =  alog(log(qmin) + x*((log(qmax)-log(qmin))/num))
15        Make/O/D coef_Lorentz = {100.0, 50.0, 1.0}
16        make/o/t parameters_Lorentz = {"Scale Factor, I0 ", "Screening Length ()","Incoherent Bgd (cm-1)"}
17        Edit parameters_Lorentz, coef_Lorentz
18        Variable/G root:g_Lorentz
19        g_Lorentz  := Lorentz_Model(coef_Lorentz,ywave_Lorentz, xwave_Lorentz)
20//      ywave_Lorentz  := Lorentz_Model(coef_Lorentz, xwave_Lorentz)
21        Display ywave_Lorentz vs xwave_Lorentz
22        ModifyGraph marker=29, msize=2, mode=4
23        ModifyGraph log(left)=1
24        Label bottom "q (\\S-1\\M) "
25        Label left "Lorentzian (cm\\S-1\\M)"
26        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
27       
28        AddModelToStrings("Lorentz_Model","coef_Lorentz","Lorentz")
29End
30
31////////////////////////////////////////////////////
32// - sets up a dependency to a wrapper, not the actual SmearedModelFunction
33Proc PlotSmearedLorentz_Model(str)                                                             
34        String str
35        Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4)
36       
37        // if any of the resolution waves are missing => abort
38        if(ResolutionWavesMissingDF(str))               //updated to NOT use global strings (in GaussUtils)
39                Abort
40        endif
41       
42        SetDataFolder $("root:"+str)
43       
44        // Setup parameter table for model function
45        Make/O/D smear_coef_Lorentz = {100.0, 50.0, 1.0}
46        make/o/t smear_parameters_Lorentz = {"Scale Factor, I0 ", "Screening Length ()","Incoherent Bgd (cm-1)"}
47        Edit smear_parameters_Lorentz,smear_coef_Lorentz                                        //display parameters in a table
48       
49        // output smeared intensity wave, dimensions are identical to experimental QSIG values
50        // make extra copy of experimental q-values for easy plotting
51        Duplicate/O $(str+"_q") smeared_Lorentz,smeared_qvals                           //
52        SetScale d,0,0,"1/cm",smeared_Lorentz                                                   //                                     
53               
54        Variable/G gs_Lorentz=0
55        gs_Lorentz := fSmearedLorentz_Model(smear_coef_Lorentz,smeared_Lorentz,smeared_qvals)   //this wrapper fills the STRUCT
56       
57        Display smeared_Lorentz vs smeared_qvals                                                                        //
58        ModifyGraph log=1,marker=29,msize=2,mode=4
59        Label bottom "q (\\S-1\\M)"
60        Label left "Lorentz Model (cm\\S-1\\M)"
61        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
62               
63        SetDataFolder root:
64        AddModelToStrings("SmearedLorentz_Model","smear_coef_Lorentz","Lorentz")
65End
66
67
68//AAO version
69Function Lorentz_model(cw,yw,xw) : FitFunc
70        Wave cw,yw,xw
71
72#if exists("Lorentz_modelX")
73        yw = Lorentz_modelX(cw,xw)
74#else
75        yw = fLorentz_model(cw,xw)
76#endif
77        return(0)
78End
79
80Function fLorentz_model(w,x) : FitFunc
81        Wave w
82        Variable x
83//       Input (fitting) variables are:
84        //[0] scale factor
85        //[1] screening length
86        //[2] incoherent background
87//      give them nice names
88        Variable I0, L,bgd
89        I0 = w[0]
90        L = w[1]
91        bgd = w[2]
92       
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 = I0/(1 + (qval*L)^2) + bgd
100        Return (inten)
101End
102/////////////////////////////////////////////////////////////////////////////////
103
104
105// this is all there is to the smeared calculation!
106Function SmearedLorentz_Model(s) :FitFunc
107        Struct ResSmearAAOStruct &s
108
109////the name of your unsmeared model is the first argument
110        Smear_Model_20(Lorentz_model,s.coefW,s.xW,s.yW,s.resW)
111
112        return(0)
113End
114       
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 fSmearedLorentz_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 = SmearedLorentz_Model(fs)
137       
138        return (0)
139End
Note: See TracBrowser for help on using the repository browser.