source: sans/Analysis/branches/ajj_23APR07/IGOR_Package_Files/Put in User Procedures/SANS_Models_v3.00/USANS_SlitSmearing.ipf @ 219

Last change on this file since 219 was 219, checked in by ajj, 15 years ago

Adding choice of number of fit points to USANS loader.

File size: 5.2 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma version=3.00
3#pragma IgorVersion=6.0
4
5//Functions for doing USANS Slit smearing by method of weight matrix
6//Routines originally from J Barker fortran code
7//Translated to IGOR by M-H Kim
8//Updated to use IGOR features and integrated into SANS Macros by A J Jackson
9//
10// AJJ
11// July 26 2007 - Modified functions to work with new SANS Analysis Macros
12//     - pass basestr to functions to determine wave names and avoid globals
13//     - pass dQv to functions to  avoid globals
14//     - pass N to CalcR to avoid globals
15
16//
17
18Function USANS_CalcWeights(basestr, dQv)
19        String basestr
20        Variable dQv
21
22        Variable/G USANS_N=numpnts($(basestr+"_q"))
23        Variable/G USANS_dQv = dQv
24        String/G USANS_basestr = basestr
25
26        Make/D/O/N=(USANS_N,USANS_N) $(basestr+"_res")
27        Make/D/O/N=(USANS_N,USANS_N) W1mat
28        Make/D/O/N=(USANS_N,USANS_N) W2mat
29        Make/D/O/N=(USANS_N,USANS_N) Rmat
30        Wave weights = $(basestr+"_res")
31
32        //Variable/G USANS_m = EnterSlope(baseStr)
33        Variable/G USANS_m = -4
34        Variable/G USANS_slope_numpnts = 10
35       
36        EnterSlope(basestr)
37
38        print USANS_m
39
40        if (USANS_m == 999)
41                KillWaves/Z  $(basestr+"_res"),W1Mat,W2mat,Rmat
42                return(1)
43        endif
44       
45        Variable tref = startMSTimer
46        print "Calculating W1..."
47        W1mat = (p <= q ) && (q <= USANS_N-2) ? CalcW1(p,q)  : 0
48        print "Calculating W2..."
49        W2mat = (p+1 <= q ) && (q <= USANS_N-1) ?  CalcW2(p,q) : 0
50        print "Calculating Remainders..."
51        Rmat = (q == USANS_N-1) ? CalcR(p) : 0
52//      print "Summing weights..."
53        weights = W1mat + W2mat + Rmat
54        print "Done"
55        Variable ms = stopMSTimer(tref)
56        print "Time elapsed = ", ms/1e6, "s"
57        //return Weights
58End
59
60Function EnterSlope(baseStr)
61        String baseStr
62       
63//      Variable slope=-4
64
65//      Prompt slope "Enter a slope for the file \""+ baseStr + "\""
66//      DoPrompt "Enter Slope", slope
67//              If (V_Flag)
68//                      return (999)                    //return a bogus slope if the user canceled
69//              Endif
70//      print "slope=", slope
71//      return slope
72
73        NewPanel /K=1/W=(1141,543,1548,910)/N=USANS_Slope as "USANS Slope Extrapolation"
74        SetDrawLayer UserBack
75        Button button_OK,pos={294,317},size={100,20},title="Accept Slope",font="Geneva"
76        Button button_OK,proc=USANS_Slope_ButtonProc
77        Button button_Cancel,pos={233,317},size={55,20},title="Cancel",font="Geneva"
78        Button button_Cancel,proc=USANS_Slope_ButtonProc
79        SetVariable setvar_numpnts, pos={43,350}, size={150,19}, title="# Points",fSize=13
80        SetVariable setvar_numpnts, value= USANS_slope_numpnts
81        SetVariable setvar_Slope,pos={43,321},size={100,19},title="Slope",fSize=13
82        SetVariable setvar_Slope,limits={-inf,inf,0},value= USANS_m
83        Display/W=(9,6,402,305)/HOST=USANS_Slope $(basestr+"_i") vs $(basestr+"_q")
84        RenameWindow #,SlopePlot
85        ModifyGraph log=1
86        SetActiveSubwindow ##
87       
88
89        PauseForUser  USANS_Slope       
90//      return slope
91       
92End
93
94Function USANS_Slope_ButtonProc(ctrlName) : ButtonControl
95        String ctrlName
96       
97        NVAR USANS_m
98       
99        strswitch (ctrlName)
100                case "button_OK":
101                        ControlUpdate/W=USANS_Slope setvar_Slope
102                        DoWindow/K USANS_Slope
103                        break
104                case "button_Cancel":
105                        DoWindow/K USANS_Slope
106                        USANS_m = 999
107                        break
108        endswitch
109         
110
111End
112
113Function CalcW1(i,j)
114
115        Variable i,j
116        SVAR USANS_basestr
117        NVAR dQv = USANS_dQv
118       
119        Variable UU,UL,dqj,rU,rL,wU,wL,dqw
120        Wave Qval = $(USANS_basestr+"_q")
121       
122        UU =sqrt(Qval[j+1]^2-Qval[i]^2)
123        UL = sqrt(Qval[j]^2-Qval[i]^2)
124        dqw = Qval[j+1]-Qval[j]
125        rU = sqrt(UU^2+Qval[i]^2)
126        rL = sqrt(UL^2+Qval[i]^2)
127       
128        wU = (1.0/dQv)*(Qval[j+1]*UU/dqw - 0.5*UU*rU/dqw - 0.5*Qval[i]^2*ln(UU+rU)/dqw )
129        wL = (1.0/dQv)*(Qval[j+1]*UL/dqw - 0.5*UL*rL/dqw - 0.5*Qval[i]^2*ln(UL+rL)/dqw )
130       
131        Return wU-wL
132
133End
134
135Function CalcW2(i,j)
136
137        Variable i,j
138       
139        SVAR USANS_basestr
140        NVAR dQv = USANS_dQv
141       
142        variable UU,UL,dqw,rU,rL,wU,wL
143       
144        Wave Qval = $(USANS_basestr+"_q")
145
146        UU = sqrt(Qval[j]^2-Qval[i]^2)                 
147        UL = sqrt(Qval[j-1]^2-Qval[i]^2)               
148        dqw = Qval[j]-Qval[j-1]                 
149        rU = sqrt(UU^2+Qval[i]^2)
150        rL = sqrt(UL^2+Qval[i]^2)
151        wU = (1.0/dQv)*( -Qval[j-1]*UU/dqw + 0.5*UU*rU/dqw + 0.5*Qval[i]^2*ln(UU+rU)/dqw )
152        wL = (1.0/dQv)*( -Qval[j-1]*UL/dqw + 0.5*UL*rL/dqw + 0.5*Qval[i]^2*ln(UL+rL)/dqw )
153
154        Return wU-wL
155
156End
157
158Function CalcR(i)
159
160        Variable i
161
162        SVAR USANS_basestr
163        NVAR m = USANS_m
164        NVAR N = USANS_N
165        NVAR dQv = USANS_dQv
166       
167        Variable retval
168        Wave Qval = $(USANS_basestr+"_q")
169        Wave Ival = $(USANS_basestr+"_i")
170        Variable/G USANS_intQpt = Qval[i]
171       
172        Variable lower = sqrt(qval[N-1]^2-qval[i]^2)
173        Variable upper = dQv
174
175        if (i == N)
176                lower = 0
177        endif
178       
179        retval = Integrate1D(Remainder,lower,upper)
180       
181        retval *= 1/dQv
182       
183        Return retval
184
185End
186
187Function Remainder(i)
188       
189        Variable i
190       
191        SVAR USANS_basestr
192        NVAR m = USANS_m
193        NVAR qi = USANS_intQpt
194        NVAR N = USANS_N
195        WAVE Qval = $(USANS_basestr+"_q")       
196        Variable retVal
197       
198        retVal=Qval[N-1]^(-m)*(i^2+qi^2)^(m/2)
199
200        return retval
201
202End
203
204Window USANS_Slope() : Panel
205        PauseUpdate; Silent 1           // building window...
206        NewPanel /K=1/W=(1141,543,1548,910) as "USANS Slope Extrapolation"
207        SetDrawLayer UserBack
208        Button button_OK,pos={294,317},size={100,20},title="Accept Slope",font="Geneva"
209        Button button_Cancel,pos={233,317},size={55,20},title="Cancel",font="Geneva"
210        SetVariable setvar_Slope,pos={43,321},size={100,19},title="Slope",fSize=13
211        SetVariable setvar_Slope,limits={-inf,inf,0},value= USANS_m
212        Display/W=(9,6,402,305)/HOST=#
213        RenameWindow #,G0
214        SetActiveSubwindow ##
215EndMacro
Note: See TracBrowser for help on using the repository browser.