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

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

Debug statements in USANS_SlitSmearing.ipf.

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        Print GetDataFolder(1)
89        PauseForUser  USANS_Slope       
90        Print GetDataFolder(1)
91//      return slope
92       
93End
94
95Function USANS_Slope_ButtonProc(ctrlName) : ButtonControl
96        String ctrlName
97       
98        NVAR USANS_m
99       
100        strswitch (ctrlName)
101                case "button_OK":
102                        ControlUpdate/W=USANS_Slope setvar_Slope
103                        DoWindow/K USANS_Slope
104                        break
105                case "button_Cancel":
106                        DoWindow/K USANS_Slope
107                        USANS_m = 999
108                        break
109        endswitch
110         
111
112End
113
114Function CalcW1(i,j)
115
116        Variable i,j
117        SVAR USANS_basestr
118        NVAR dQv = USANS_dQv
119       
120        Variable UU,UL,dqj,rU,rL,wU,wL,dqw
121        Wave Qval = $(USANS_basestr+"_q")
122       
123        UU =sqrt(Qval[j+1]^2-Qval[i]^2)
124        UL = sqrt(Qval[j]^2-Qval[i]^2)
125        dqw = Qval[j+1]-Qval[j]
126        rU = sqrt(UU^2+Qval[i]^2)
127        rL = sqrt(UL^2+Qval[i]^2)
128       
129        wU = (1.0/dQv)*(Qval[j+1]*UU/dqw - 0.5*UU*rU/dqw - 0.5*Qval[i]^2*ln(UU+rU)/dqw )
130        wL = (1.0/dQv)*(Qval[j+1]*UL/dqw - 0.5*UL*rL/dqw - 0.5*Qval[i]^2*ln(UL+rL)/dqw )
131       
132        Return wU-wL
133
134End
135
136Function CalcW2(i,j)
137
138        Variable i,j
139       
140        SVAR USANS_basestr
141        NVAR dQv = USANS_dQv
142       
143        variable UU,UL,dqw,rU,rL,wU,wL
144       
145        Wave Qval = $(USANS_basestr+"_q")
146
147        UU = sqrt(Qval[j]^2-Qval[i]^2)                 
148        UL = sqrt(Qval[j-1]^2-Qval[i]^2)               
149        dqw = Qval[j]-Qval[j-1]                 
150        rU = sqrt(UU^2+Qval[i]^2)
151        rL = sqrt(UL^2+Qval[i]^2)
152        wU = (1.0/dQv)*( -Qval[j-1]*UU/dqw + 0.5*UU*rU/dqw + 0.5*Qval[i]^2*ln(UU+rU)/dqw )
153        wL = (1.0/dQv)*( -Qval[j-1]*UL/dqw + 0.5*UL*rL/dqw + 0.5*Qval[i]^2*ln(UL+rL)/dqw )
154
155        Return wU-wL
156
157End
158
159Function CalcR(i)
160
161        Variable i
162
163        SVAR USANS_basestr
164        NVAR m = USANS_m
165        NVAR N = USANS_N
166        NVAR dQv = USANS_dQv
167       
168        Variable retval
169        Wave Qval = $(USANS_basestr+"_q")
170        Wave Ival = $(USANS_basestr+"_i")
171        Variable/G USANS_intQpt = Qval[i]
172       
173        Variable lower = sqrt(qval[N-1]^2-qval[i]^2)
174        Variable upper = dQv
175
176        if (i == N)
177                lower = 0
178        endif
179       
180        retval = Integrate1D(Remainder,lower,upper)
181       
182        retval *= 1/dQv
183       
184        Return retval
185
186End
187
188Function Remainder(i)
189       
190        Variable i
191       
192        SVAR USANS_basestr
193        NVAR m = USANS_m
194        NVAR qi = USANS_intQpt
195        NVAR N = USANS_N
196        WAVE Qval = $(USANS_basestr+"_q")       
197        Variable retVal
198       
199        retVal=Qval[N-1]^(-m)*(i^2+qi^2)^(m/2)
200
201        return retval
202
203End
204
205Window USANS_Slope() : Panel
206        PauseUpdate; Silent 1           // building window...
207        NewPanel /K=1/W=(1141,543,1548,910) as "USANS Slope Extrapolation"
208        SetDrawLayer UserBack
209        Button button_OK,pos={294,317},size={100,20},title="Accept Slope",font="Geneva"
210        Button button_Cancel,pos={233,317},size={55,20},title="Cancel",font="Geneva"
211        SetVariable setvar_Slope,pos={43,321},size={100,19},title="Slope",fSize=13
212        SetVariable setvar_Slope,limits={-inf,inf,0},value= USANS_m
213        Display/W=(9,6,402,305)/HOST=#
214        RenameWindow #,G0
215        SetActiveSubwindow ##
216EndMacro
Note: See TracBrowser for help on using the repository browser.