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