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

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

Updates to USANS loading

File size: 5.1 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       
35        EnterSlope(basestr)
36
37        print USANS_m
38
39        if (USANS_m == 999)
40                KillWaves/Z  $(basestr+"_res"),W1Mat,W2mat,Rmat
41                return(1)
42        endif
43       
44        Variable tref = startMSTimer
45        print "Calculating W1..."
46        W1mat = (p <= q ) && (q <= USANS_N-2) ? CalcW1(p,q)  : 0
47        print "Calculating W2..."
48        W2mat = (p+1 <= q ) && (q <= USANS_N-1) ?  CalcW2(p,q) : 0
49        print "Calculating Remainders..."
50        Rmat = (q == USANS_N-1) ? CalcR(p) : 0
51//      print "Summing weights..."
52        weights = W1mat + W2mat + Rmat
53        print "Done"
54        Variable ms = stopMSTimer(tref)
55        print "Time elapsed = ", ms/1e6, "s"
56        //return Weights
57End
58
59// This is far from satisfactory!
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,330}, size={100,19}, title="# Points",fSize=13
80        SetVariable setvar_Slope
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        SetActiveSubwindow ##
86       
87
88        PauseForUser  USANS_Slope       
89//      return slope
90       
91End
92
93Function USANS_Slope_ButtonProc(ctrlName) : ButtonControl
94        String ctrlName
95       
96        NVAR USANS_m
97       
98        strswitch (ctrlName)
99                case "button_OK":
100                        ControlUpdate/W=USANS_Slope setvar_Slope
101                        DoWindow/K USANS_Slope
102                        break
103                case "button_Cancel":
104                        DoWindow/K USANS_Slope
105                        USANS_m = 999
106                        break
107        endswitch
108         
109
110End
111
112Function CalcW1(i,j)
113
114        Variable i,j
115        SVAR USANS_basestr
116        NVAR dQv = USANS_dQv
117       
118        Variable UU,UL,dqj,rU,rL,wU,wL,dqw
119        Wave Qval = $(USANS_basestr+"_q")
120       
121        UU =sqrt(Qval[j+1]^2-Qval[i]^2)
122        UL = sqrt(Qval[j]^2-Qval[i]^2)
123        dqw = Qval[j+1]-Qval[j]
124        rU = sqrt(UU^2+Qval[i]^2)
125        rL = sqrt(UL^2+Qval[i]^2)
126       
127        wU = (1.0/dQv)*(Qval[j+1]*UU/dqw - 0.5*UU*rU/dqw - 0.5*Qval[i]^2*ln(UU+rU)/dqw )
128        wL = (1.0/dQv)*(Qval[j+1]*UL/dqw - 0.5*UL*rL/dqw - 0.5*Qval[i]^2*ln(UL+rL)/dqw )
129       
130        Return wU-wL
131
132End
133
134Function CalcW2(i,j)
135
136        Variable i,j
137       
138        SVAR USANS_basestr
139        NVAR dQv = USANS_dQv
140       
141        variable UU,UL,dqw,rU,rL,wU,wL
142       
143        Wave Qval = $(USANS_basestr+"_q")
144
145        UU = sqrt(Qval[j]^2-Qval[i]^2)                 
146        UL = sqrt(Qval[j-1]^2-Qval[i]^2)               
147        dqw = Qval[j]-Qval[j-1]                 
148        rU = sqrt(UU^2+Qval[i]^2)
149        rL = sqrt(UL^2+Qval[i]^2)
150        wU = (1.0/dQv)*( -Qval[j-1]*UU/dqw + 0.5*UU*rU/dqw + 0.5*Qval[i]^2*ln(UU+rU)/dqw )
151        wL = (1.0/dQv)*( -Qval[j-1]*UL/dqw + 0.5*UL*rL/dqw + 0.5*Qval[i]^2*ln(UL+rL)/dqw )
152
153        Return wU-wL
154
155End
156
157Function CalcR(i)
158
159        Variable i
160
161        SVAR USANS_basestr
162        NVAR m = USANS_m
163        NVAR N = USANS_N
164        NVAR dQv = USANS_dQv
165       
166        Variable retval
167        Wave Qval = $(USANS_basestr+"_q")
168        Wave Ival = $(USANS_basestr+"_i")
169        Variable/G USANS_intQpt = Qval[i]
170       
171        Variable lower = sqrt(qval[N-1]^2-qval[i]^2)
172        Variable upper = dQv
173
174        if (i == N)
175                lower = 0
176        endif
177       
178        retval = Integrate1D(Remainder,lower,upper)
179       
180        retval *= 1/dQv
181       
182        Return retval
183
184End
185
186Function Remainder(i)
187       
188        Variable i
189       
190        SVAR USANS_basestr
191        NVAR m = USANS_m
192        NVAR qi = USANS_intQpt
193        NVAR N = USANS_N
194        WAVE Qval = $(USANS_basestr+"_q")       
195        Variable retVal
196       
197        retVal=Qval[N-1]^(-m)*(i^2+qi^2)^(m/2)
198
199        return retval
200
201End
202
203Window USANS_Slope() : Panel
204        PauseUpdate; Silent 1           // building window...
205        NewPanel /K=1/W=(1141,543,1548,910) as "USANS Slope Extrapolation"
206        SetDrawLayer UserBack
207        Button button_OK,pos={294,317},size={100,20},title="Accept Slope",font="Geneva"
208        Button button_Cancel,pos={233,317},size={55,20},title="Cancel",font="Geneva"
209        SetVariable setvar_Slope,pos={43,321},size={100,19},title="Slope",fSize=13
210        SetVariable setvar_Slope,limits={-inf,inf,0},value= USANS_m
211        Display/W=(9,6,402,305)/HOST=#
212        RenameWindow #,G0
213        SetActiveSubwindow ##
214EndMacro
Note: See TracBrowser for help on using the repository browser.