1 | #pragma rtGlobals=1 // Use modern global access method. |
---|
2 | #pragma IgorVersion=6.1 |
---|
3 | |
---|
4 | // 07 JAN 05 SRK |
---|
5 | // updated procedures (from SS 2002) to be used as a package |
---|
6 | // with the SANS analysis routines |
---|
7 | // |
---|
8 | // need to: |
---|
9 | // - verify accuracy (see John) |
---|
10 | |
---|
11 | // this is the main entry point for the panel |
---|
12 | Proc Make_Invariant_Panel() |
---|
13 | DoWindow/F Invariant_Panel |
---|
14 | if(V_flag==0) |
---|
15 | //create global variables in root:myGlobals:invariant |
---|
16 | Init_Invariant() |
---|
17 | Invariant_Panel() |
---|
18 | endif |
---|
19 | //pop the file menu |
---|
20 | Inv_FilePopMenuProc("",1,"") |
---|
21 | End |
---|
22 | |
---|
23 | //create the globals |
---|
24 | Proc Init_Invariant() |
---|
25 | NewDataFolder/O root:Packages |
---|
26 | NewDataFolder/O root:Packages:NIST |
---|
27 | NewDataFolder/O/S root:Packages:NIST:invariant |
---|
28 | Variable/G gNumLow=10 |
---|
29 | Variable/G gNumHigh=10 |
---|
30 | |
---|
31 | Variable/G gInvMeas=0 |
---|
32 | Variable/G gInvLowQ=0 |
---|
33 | Variable/G gInvHighQ=0 |
---|
34 | Variable/G gInvTotal=0 |
---|
35 | String/G gDataPopList = "none" |
---|
36 | Variable/G gIsSlitSmeared=0 |
---|
37 | Variable/G gDqv = 0.117 //default value for USANS slit height (re-read from file) |
---|
38 | |
---|
39 | // new July 2008 |
---|
40 | Variable/G gSlopeVal = -4 |
---|
41 | |
---|
42 | SetDataFolder root: |
---|
43 | End |
---|
44 | |
---|
45 | // for testing - compare to the "perfect" value. This macro |
---|
46 | // calculates the invariant based on the contrast and volume fraction |
---|
47 | // - the extrapolated/integrated value should match this... |
---|
48 | Macro PrintModelInvariant(delta_rho,phi) |
---|
49 | Variable delta_rho=3e-6,phi=0.1 |
---|
50 | Prompt delta_rho,"Contrast (1/A^2)" |
---|
51 | Prompt phi,"Volume fraction" |
---|
52 | |
---|
53 | // delta_rho [=] 1/A^2 |
---|
54 | Variable inv |
---|
55 | |
---|
56 | inv = 2*pi*pi*delta_rho*delta_rho*phi*(1-phi)*1e8 |
---|
57 | |
---|
58 | Printf "The model invariant is %g A^-3 cm^-1\r\r",inv |
---|
59 | End |
---|
60 | |
---|
61 | // for testing - compare to the "perfect" value. This macro |
---|
62 | // calculates the invariant based on the contrast and volume fraction |
---|
63 | // - the extrapolated/integrated value should match this... |
---|
64 | Macro SolveForVolumeFraction(invariant,delta_rho) |
---|
65 | Variable invariant,delta_rho=6e-6 |
---|
66 | Prompt invariant,"Invariant [=] cm^-1 A^-3" |
---|
67 | Prompt delta_rho,"Contrast (1/A^2)" |
---|
68 | |
---|
69 | // delta_rho [=] 1/A^2 |
---|
70 | Variable phi1,phi2,arg |
---|
71 | arg = 1 - 4*invariant*(1e-8)/2/pi/pi/delta_rho/delta_rho |
---|
72 | phi1 = (1 - sqrt(arg))/2 |
---|
73 | phi2 = (1 + sqrt(arg))/2 |
---|
74 | Printf "The two solutions for phi are: %8.6f\t and %8.6f\r\r",phi1,phi2 |
---|
75 | |
---|
76 | |
---|
77 | End |
---|
78 | |
---|
79 | |
---|
80 | //integrates only over the given q-range, does no interpolation |
---|
81 | Function Invariant(qw,iw) |
---|
82 | Wave qw,iw |
---|
83 | |
---|
84 | Variable num,invar |
---|
85 | Duplicate/O qw integrand |
---|
86 | integrand = qw*qw*iw |
---|
87 | // integrand /= 1e8 //convert 1/cm to 1/A |
---|
88 | |
---|
89 | num = numpnts(qw) |
---|
90 | invar = areaXY(qw,integrand,qw[0],qw[num-1]) |
---|
91 | |
---|
92 | return(invar) //units of A^-3 cm^-1 |
---|
93 | End |
---|
94 | |
---|
95 | //integrates only over the given q-range, does no interpolation |
---|
96 | // function is for slit smeared data |
---|
97 | Function Invariant_SlitSmeared(qw,iw) |
---|
98 | Wave qw,iw |
---|
99 | |
---|
100 | Variable num,invar |
---|
101 | NVAR dQv = root:Packages:NIST:invariant:gDqv |
---|
102 | |
---|
103 | Duplicate/O qw integrand |
---|
104 | integrand = qw*iw |
---|
105 | // integrand /= 1e8 //convert 1/cm to 1/A |
---|
106 | |
---|
107 | num = numpnts(qw) |
---|
108 | invar = areaXY(qw,integrand,qw[0],qw[num-1]) |
---|
109 | |
---|
110 | invar *= dQv //correct for the effects of slit-smearing |
---|
111 | |
---|
112 | return(invar) //units of A^-3 cm^-1 |
---|
113 | End |
---|
114 | |
---|
115 | Function Guinier_Fit(w,x) : FitFunc |
---|
116 | Wave w |
---|
117 | Variable x |
---|
118 | |
---|
119 | //fit data to I(q) = A*exp(B*q^2) |
---|
120 | // (B will be negative) |
---|
121 | //two parameters |
---|
122 | Variable a,b,ans |
---|
123 | a=w[0] |
---|
124 | b=w[1] |
---|
125 | ans = a*exp(b*x*x) |
---|
126 | return(ans) |
---|
127 | End |
---|
128 | |
---|
129 | |
---|
130 | //pass the wave with the q-values |
---|
131 | Function SetExtrWaves(w) |
---|
132 | Wave w |
---|
133 | |
---|
134 | Variable num_extr=100 |
---|
135 | |
---|
136 | Make/O/D/N=(num_extr) extr_hqq,extr_hqi,extr_lqq,extr_lqi |
---|
137 | extr_lqi=1 |
---|
138 | extr_hqi=1 //default values |
---|
139 | //set the q-range |
---|
140 | Variable qmax,qmin,num |
---|
141 | qmax=10 |
---|
142 | qmin=1e-5 |
---|
143 | num=numpnts(w) |
---|
144 | |
---|
145 | extr_hqq = w[num-1] + x * (qmax-w[num-1])/num_extr |
---|
146 | extr_lqq = qmin + x * (w[0]-qmin)/num_extr |
---|
147 | |
---|
148 | return(0) |
---|
149 | End |
---|
150 | |
---|
151 | Function DoExtrapolate(qw,iw,sw,nbeg,nend) |
---|
152 | Wave qw,iw,sw |
---|
153 | Variable nbeg,nend |
---|
154 | |
---|
155 | Wave extr_lqi=extr_lqi |
---|
156 | Wave extr_lqq=extr_lqq |
---|
157 | Wave extr_hqi=extr_hqi |
---|
158 | Wave extr_hqq=extr_hqq |
---|
159 | Variable/G V_FitMaxIters=300 |
---|
160 | Variable num=numpnts(iw) |
---|
161 | |
---|
162 | Make/O/D G_coef={100,-100} //input |
---|
163 | FuncFit Guinier_Fit G_coef iw[0,(nbeg-1)] /I=1 /X=qw /W=sw /D |
---|
164 | extr_lqi= Guinier_Fit(G_coef,extr_lqq) |
---|
165 | |
---|
166 | Printf "I(q=0) = %g (1/cm)\r",G_coef[0] |
---|
167 | Printf "Rg = %g (A)\r",sqrt(-3*G_coef[1]) |
---|
168 | |
---|
169 | Make/O/D P_coef={0,1,-4} //input |
---|
170 | //(set background to zero and hold fixed) |
---|
171 | CurveFit/H="100" Power kwCWave=P_coef iw[(num-1-nend),(num-1)] /I=1 /X=qw /W=sw /D |
---|
172 | extr_hqi=P_coef[0]+P_coef[1]*extr_hqq^P_coef[2] |
---|
173 | |
---|
174 | Printf "Power law exponent = %g\r",P_coef[2] |
---|
175 | Printf "Pre-exponential = %g\r",P_coef[1] |
---|
176 | |
---|
177 | return(0) |
---|
178 | End |
---|
179 | |
---|
180 | //plot based on the wave selelctions |
---|
181 | Function Plot_Inv_Data(ctrlName) : ButtonControl |
---|
182 | String ctrlName |
---|
183 | |
---|
184 | //access the global strings representing the last data file read in |
---|
185 | SVAR QWave = root:Packages:NIST:invariant:QWave |
---|
186 | SVAR IWave = root:Packages:NIST:invariant:IWave |
---|
187 | SVAR SWave = root:Packages:NIST:invariant:SWave |
---|
188 | |
---|
189 | Wave qw=$QWave |
---|
190 | Wave iw=$IWave |
---|
191 | Wave sw=$SWave |
---|
192 | |
---|
193 | String str="",item="" |
---|
194 | Variable num=0,ii |
---|
195 | |
---|
196 | //not used - just kill and re-draw |
---|
197 | //remove everything from the graph and graph it again |
---|
198 | // str = TraceNameList("",";",1) |
---|
199 | // num=ItemsInList(str) |
---|
200 | // for(ii=0;ii<num;ii+=1) |
---|
201 | // item=StringFromList(ii, str ,";") |
---|
202 | // Print item |
---|
203 | // RemoveFromGraph $item |
---|
204 | // endfor |
---|
205 | |
---|
206 | DoWindow/F invariant_graph |
---|
207 | if(V_flag==1) |
---|
208 | DoWindow/K invariant_graph |
---|
209 | endif |
---|
210 | Display /W=(5,44,375,321)/K=1 iw vs qw |
---|
211 | DoWindow/C invariant_graph |
---|
212 | ModifyGraph mode=3,marker=8 |
---|
213 | ModifyGraph grid=1 |
---|
214 | ModifyGraph log=1 |
---|
215 | ModifyGraph mirror=2 |
---|
216 | ModifyGraph standoff=0 |
---|
217 | ModifyGraph tickUnit=1 |
---|
218 | Label left "Intensity (1/cm)" |
---|
219 | Label bottom "q (1/A)" |
---|
220 | ModifyGraph rgb($NameofWave(iw))=(0,0,0) |
---|
221 | ModifyGraph opaque($NameofWave(iw))=1 |
---|
222 | ErrorBars/T=0 $NameofWave(iw) Y,wave=(sw,sw) |
---|
223 | Legend |
---|
224 | |
---|
225 | // Print TraceNameList("",";",1) |
---|
226 | |
---|
227 | //create the extra waves now, and add to plot |
---|
228 | SetExtrWaves(qw) |
---|
229 | Wave extr_lqi=extr_lqi |
---|
230 | Wave extr_lqq=extr_lqq |
---|
231 | Wave extr_hqi=extr_hqi |
---|
232 | Wave extr_hqq=extr_hqq |
---|
233 | AppendtoGraph extr_lqi vs extr_lqq |
---|
234 | AppendtoGraph extr_hqi vs extr_hqq |
---|
235 | ModifyGraph lSize(extr_lqi)=2,lSize(extr_hqi)=2 |
---|
236 | ModifyGraph rgb($NameofWave(iw))=(0,0,0),rgb(extr_hqi)=(2,39321,1) |
---|
237 | |
---|
238 | //reset the invariant values to zero |
---|
239 | NVAR meas = root:Packages:NIST:invariant:gInvMeas |
---|
240 | NVAR lo = root:Packages:NIST:invariant:gInvLowQ |
---|
241 | NVAR hi = root:Packages:NIST:invariant:gInvHighQ |
---|
242 | NVAR total = root:Packages:NIST:invariant:gInvTotal |
---|
243 | meas=0 |
---|
244 | lo=0 |
---|
245 | hi=0 |
---|
246 | total=0 |
---|
247 | |
---|
248 | return(0) |
---|
249 | End |
---|
250 | |
---|
251 | |
---|
252 | Function LowCheckProc(ctrlName,checked) : CheckBoxControl |
---|
253 | String ctrlName |
---|
254 | Variable checked |
---|
255 | |
---|
256 | Variable val=0 |
---|
257 | // print "checked = ",checked |
---|
258 | if(cmpstr(ctrlName,"check_0")==0) |
---|
259 | if(checked) |
---|
260 | val=1 |
---|
261 | endif |
---|
262 | endif |
---|
263 | CheckBox check_0,value= Val==1 |
---|
264 | CheckBox check_1,value= Val==0 |
---|
265 | End |
---|
266 | |
---|
267 | |
---|
268 | Proc Invariant_Panel() |
---|
269 | SetDataFolder root: //use absolute paths? |
---|
270 | PauseUpdate; Silent 1 // building window... |
---|
271 | NewPanel /W=(510,44,796,529) /K=2 |
---|
272 | DoWindow/C Invariant_Panel |
---|
273 | ModifyPanel cbRGB=(65535,43690,0) |
---|
274 | SetDrawLayer UserBack |
---|
275 | DrawText 23,196,"Extrapolation" |
---|
276 | DrawText 158,195,"Power-Law" |
---|
277 | DrawText 158,211,"Extrapolation" |
---|
278 | SetDrawEnv fstyle= 1 |
---|
279 | DrawText 58,349,"Units are [A^-3 cm^-1]" |
---|
280 | SetDrawEnv fstyle= 1 |
---|
281 | DrawText 61,16,"Calculate the Invariant" |
---|
282 | DrawLine 16,135,264,135 |
---|
283 | DrawLine 16,19,264,19 |
---|
284 | PopupMenu ywave,pos={10,60},size={231,20},proc=Inv_FilePopMenuProc,title="Data File" |
---|
285 | PopupMenu ywave,help={"Select the experimental intensity values"} |
---|
286 | PopupMenu ywave,mode=1,value= #"root:Packages:NIST:invariant:gDataPopList" |
---|
287 | Button loadButton,pos={10,90},size={130,20},proc=Inv_Load_Proc,title="Load and Plot File" |
---|
288 | Button loadButton,help={"After choosing a file, load it into memory and plot it with this button."} |
---|
289 | Button Inv_PathButton,pos={10,29},size={80,20},proc=Inv_PickPathButtonProc,title="Pick Path" |
---|
290 | Button DoneButton,pos={215,453},size={50,20},proc=InvDoneButton,title="Done" |
---|
291 | Button DoneButton,help={"This button will close the panel and the associated graph"} |
---|
292 | SetVariable setvar_0,pos={27,255},size={80,15},title="# points" |
---|
293 | SetVariable setvar_0,limits={5,50,0},value= root:Packages:NIST:invariant:gNumLow |
---|
294 | SetVariable setvar_1,pos={164,255},size={80,15},title="# points" |
---|
295 | SetVariable setvar_1,limits={5,200,0},value= root:Packages:NIST:invariant:gNumHigh |
---|
296 | CheckBox check_0,pos={23,202},size={48,14},proc=LowCheckProc,title="Guinier" |
---|
297 | CheckBox check_0,value= 1 |
---|
298 | CheckBox check_1,pos={23,223},size={65,14},proc=LowCheckProc,title="Power Law" |
---|
299 | CheckBox check_1,value= 0 |
---|
300 | Button button_0,pos={29,279},size={90,20},proc=InvLowQ,title="Calc Low Q" |
---|
301 | Button button_1,pos={56,141},size={170,20},proc=InvMeasQ,title="Calculate Measured Q" |
---|
302 | Button button_2,pos={159,279},size={90,20},proc=InvHighQ,title="Calc High Q" |
---|
303 | Button button_4,pos={230,29},size={25,20},proc=Inv_HelpButtonProc,title="?" |
---|
304 | GroupBox group0,pos={14,165},size={123,144},title="Low Q" |
---|
305 | GroupBox group0_1,pos={147,165},size={123,144},title="High Q" |
---|
306 | GroupBox group1,pos={23,318},size={239,124},title="INVARIANT" |
---|
307 | ValDisplay valdisp0,pos={51,354},size={180,14},title="In measured Q-range " |
---|
308 | ValDisplay valdisp0,limits={0,0,0},barmisc={0,1000} |
---|
309 | ValDisplay valdisp0,value= #"root:Packages:NIST:invariant:gInvMeas" |
---|
310 | ValDisplay valdisp0_1,pos={51,371},size={180,14},title="In low Q extrapolation " |
---|
311 | ValDisplay valdisp0_1,limits={0,0,0},barmisc={0,1000} |
---|
312 | ValDisplay valdisp0_1,value= #"root:Packages:NIST:invariant:gInvLowQ" |
---|
313 | ValDisplay valdisp0_2,pos={51,388},size={180,14},title="In high Q extrapolation " |
---|
314 | ValDisplay valdisp0_2,limits={0,0,0},barmisc={0,1000} |
---|
315 | ValDisplay valdisp0_2,value= #"root:Packages:NIST:invariant:gInvHighQ" |
---|
316 | ValDisplay valdisp0_3,pos={51,411},size={180,14},title="TOTAL " |
---|
317 | ValDisplay valdisp0_3,limits={0,0,0},barmisc={0,1000} |
---|
318 | ValDisplay valdisp0_3,value= #"root:Packages:NIST:invariant:gInvTotal" |
---|
319 | CheckBox check0,pos={10,116},size={97,14},proc=SlitSmearedCheckProc,title="Slit-Smeared Data" |
---|
320 | CheckBox check0,value= 0 |
---|
321 | SetVariable setvar0,pos={136,116},size={130,15},title="Slit Height (1/A)" |
---|
322 | SetVariable setvar0,limits={-inf,inf,0},value= root:Packages:NIST:invariant:gDqv |
---|
323 | CheckBox check2,pos={168,217},size={73,14},title="Fixed Slope?",value= 1 |
---|
324 | SetVariable setvar2,pos={164,235},size={80,15},title="Slope" |
---|
325 | SetVariable setvar2,limits={-100,0,0},value= root:Packages:NIST:invariant:gSlopeVal |
---|
326 | |
---|
327 | |
---|
328 | //set up a dependency to calculate the total invariant |
---|
329 | root:Packages:NIST:invariant:gInvTotal := root:Packages:NIST:invariant:gInvLowQ + root:Packages:NIST:invariant:gInvMeas + root:Packages:NIST:invariant:gInvHighQ |
---|
330 | EndMacro |
---|
331 | |
---|
332 | |
---|
333 | Function InvMeasQ(ctrlName) : ButtonControl |
---|
334 | String ctrlName |
---|
335 | |
---|
336 | //no graph, get out |
---|
337 | DoWindow/F Invariant_Graph |
---|
338 | if(V_flag==0) |
---|
339 | return(0) |
---|
340 | endif |
---|
341 | |
---|
342 | //do the straight calculation of the invariant of the specified data |
---|
343 | Variable inv,num |
---|
344 | |
---|
345 | SVAR QWave = root:Packages:NIST:invariant:QWave |
---|
346 | Wave qw=$QWave |
---|
347 | SVAR IWave = root:Packages:NIST:invariant:IWave |
---|
348 | Wave iw=$IWave |
---|
349 | |
---|
350 | NVAR isSlitSmeared=root:Packages:NIST:invariant:gIsSlitSmeared |
---|
351 | if(isSlitSmeared) |
---|
352 | inv = Invariant_SlitSmeared(qw,iw) |
---|
353 | else |
---|
354 | inv = Invariant(qw,iw) |
---|
355 | endif |
---|
356 | |
---|
357 | num=numpnts(qw) |
---|
358 | Printf "The invariant over the measured q-range %g to %g is %g A^-3 cm^-1\r\r",qw[0],qw[(num-1)],inv |
---|
359 | |
---|
360 | // update the global display on the panel (there is a dependency for the total) |
---|
361 | NVAR val = root:Packages:NIST:invariant:gInvMeas |
---|
362 | val = inv |
---|
363 | |
---|
364 | return(0) |
---|
365 | End |
---|
366 | |
---|
367 | Function InvLowQ(ctrlName) : ButtonControl |
---|
368 | String ctrlName |
---|
369 | |
---|
370 | //no graph, get out |
---|
371 | DoWindow/F Invariant_Graph |
---|
372 | if(V_flag==0) |
---|
373 | return(0) |
---|
374 | endif |
---|
375 | |
---|
376 | Variable yesGuinier=0,nume,inv,scale |
---|
377 | // do the extrapolation of the correct type |
---|
378 | ControlInfo/W=Invariant_Panel check_0 //the Guinier box |
---|
379 | yesGuinier = V_Value |
---|
380 | // print "yesGuinier = ",yesGuinier |
---|
381 | //number of points to use for fit |
---|
382 | NVAR nbeg=root:Packages:NIST:invariant:gNumLow |
---|
383 | //define the waves |
---|
384 | Wave extr_lqi=extr_lqi |
---|
385 | Wave extr_lqq=extr_lqq |
---|
386 | |
---|
387 | SVAR QWave = root:Packages:NIST:invariant:QWave |
---|
388 | Wave qw=$QWave |
---|
389 | SVAR IWave = root:Packages:NIST:invariant:IWave |
---|
390 | Wave iw=$IWave |
---|
391 | SVAR SWave = root:Packages:NIST:invariant:SWave |
---|
392 | Wave sw=$SWave |
---|
393 | |
---|
394 | Wave/Z W_coef=W_coef |
---|
395 | Variable/G V_FitMaxIters=300 |
---|
396 | // Variable numi=numpnts(iw) |
---|
397 | |
---|
398 | if(yesGuinier) |
---|
399 | // Make/O/D G_coef={1000,-1000} //input |
---|
400 | WaveStats/M=1/Q/R=[0,(nbeg-1)] iw |
---|
401 | scale = V_avg |
---|
402 | Make/O/D G_coef={(scale),-1000} //input -- with a better guess for the overall scale factor, |
---|
403 | FuncFit Guinier_Fit G_coef iw[0,(nbeg-1)] /I=1 /X=qw /W=sw /D |
---|
404 | extr_lqi= Guinier_Fit(G_coef,extr_lqq) |
---|
405 | |
---|
406 | Printf "I(q=0) = %g (1/cm)\r",G_coef[0] |
---|
407 | Printf "Rg = %g (A)\r",sqrt(-3*G_coef[1]) |
---|
408 | else |
---|
409 | //do a power-law fit instead |
---|
410 | Make/O/D P_coef={0,1,-1} //input |
---|
411 | //(set background to zero and hold fixed) |
---|
412 | CurveFit/H="100" Power kwCWave=P_coef iw[0,(nbeg-1)] /I=1 /X=qw /W=sw /D |
---|
413 | extr_lqi=P_coef[0]+P_coef[1]*extr_lqq^P_coef[2] |
---|
414 | // |
---|
415 | Printf "Pre-exponential = %g\r",P_coef[1] |
---|
416 | Printf "Power law exponent = %g\r",P_coef[2] |
---|
417 | // |
---|
418 | endif |
---|
419 | |
---|
420 | //calculate the invariant |
---|
421 | NVAR isSlitSmeared=root:Packages:NIST:invariant:gIsSlitSmeared |
---|
422 | if(isSlitSmeared) |
---|
423 | inv = Invariant_SlitSmeared(extr_lqq,extr_lqi) |
---|
424 | else |
---|
425 | inv = Invariant(extr_lqq,extr_lqi) |
---|
426 | endif |
---|
427 | |
---|
428 | nume=numpnts(extr_lqq) |
---|
429 | Printf "The invariant over the q-range %g to %g is %g A^-3 cm^-1\r\r",extr_lqq[0],extr_lqq[(nume-1)],inv |
---|
430 | |
---|
431 | // update the global display on the panel (there is a dependency for the total) |
---|
432 | NVAR val = root:Packages:NIST:invariant:gInvLowQ |
---|
433 | val = inv |
---|
434 | |
---|
435 | return(0) |
---|
436 | End |
---|
437 | |
---|
438 | Function InvHighQ(ctrlName) : ButtonControl |
---|
439 | String ctrlName |
---|
440 | |
---|
441 | //no graph, get out |
---|
442 | DoWindow/F Invariant_Graph |
---|
443 | if(V_flag==0) |
---|
444 | return(0) |
---|
445 | endif |
---|
446 | |
---|
447 | // do the power-law extrapolation |
---|
448 | |
---|
449 | Wave extr_hqi=extr_hqi |
---|
450 | Wave extr_hqq=extr_hqq |
---|
451 | SVAR QWave = root:Packages:NIST:invariant:QWave |
---|
452 | Wave qw=$QWave |
---|
453 | SVAR IWave = root:Packages:NIST:invariant:IWave |
---|
454 | Wave iw=$IWave |
---|
455 | SVAR SWave = root:Packages:NIST:invariant:SWave |
---|
456 | Wave sw=$SWave |
---|
457 | |
---|
458 | Variable/G V_FitMaxIters=300 |
---|
459 | Variable num=numpnts(iw),nume,inv |
---|
460 | NVAR nend=root:Packages:NIST:invariant:gNumHigh //number of points for the fit |
---|
461 | NVAR fixedSlope = root:Packages:NIST:invariant:gSlopeVal //fixed slope value at high q |
---|
462 | |
---|
463 | if(fixedSlope == 0) |
---|
464 | fixedSlope = -4 |
---|
465 | endif |
---|
466 | |
---|
467 | Make/O/D P_coef={0,1,-4} //input |
---|
468 | P_coef[2] = fixedSlope |
---|
469 | |
---|
470 | ControlInfo/W=Invariant_Panel check2 |
---|
471 | if(V_Value == 1) |
---|
472 | //hold the slope fixed, and the background |
---|
473 | CurveFit/H="101" Power kwCWave=P_coef iw[(num-1-nend),(num-1)] /I=1 /X=qw /W=sw /D |
---|
474 | else |
---|
475 | //(set background to zero and hold fixed) |
---|
476 | CurveFit/H="100" Power kwCWave=P_coef iw[(num-1-nend),(num-1)] /I=1 /X=qw /W=sw /D |
---|
477 | endif |
---|
478 | |
---|
479 | extr_hqi=P_coef[0]+P_coef[1]*extr_hqq^P_coef[2] |
---|
480 | |
---|
481 | Printf "Pre-exponential = %g\r",P_coef[1] |
---|
482 | Printf "Power law exponent = %g\r",P_coef[2] |
---|
483 | |
---|
484 | //calculate the invariant |
---|
485 | NVAR isSlitSmeared=root:Packages:NIST:invariant:gIsSlitSmeared |
---|
486 | if(isSlitSmeared) |
---|
487 | inv = Invariant_SlitSmeared(extr_hqq,extr_hqi) |
---|
488 | else |
---|
489 | inv = Invariant(extr_hqq,extr_hqi) |
---|
490 | endif |
---|
491 | |
---|
492 | nume=numpnts(extr_hqq) |
---|
493 | Printf "The invariant over the q-range %g to %g is %g A^-3 cm^-1\r\r",extr_hqq[0],extr_hqq[(nume-1)],inv |
---|
494 | |
---|
495 | // update the global display on the panel (there is a dependency for the total) |
---|
496 | NVAR val = root:Packages:NIST:invariant:gInvHighQ |
---|
497 | val = inv |
---|
498 | |
---|
499 | return(0) |
---|
500 | End |
---|
501 | |
---|
502 | Function UnloadInvariant() |
---|
503 | if (WinType("Invariant_Panel") == 7) |
---|
504 | DoWindow/K Invariant_Panel |
---|
505 | endif |
---|
506 | if (WinType("Invariant_Graph") != 0) |
---|
507 | DoWindow/K $"Invariant_Graph" |
---|
508 | endif |
---|
509 | if (DatafolderExists("root:Packages:NIST:invariant")) |
---|
510 | KillDatafolder root:Packages:NIST:invariant |
---|
511 | endif |
---|
512 | SetDataFolder root: |
---|
513 | Killwaves/Z integrand,G_coef,P_coef,extr_hqq,extr_hqi,extr_lqq,extr_lqi |
---|
514 | |
---|
515 | SVAR fileVerExt=root:Packages:NIST:SANS_ANA_EXTENSION |
---|
516 | String fname="Invariant" |
---|
517 | Execute/P "DELETEINCLUDE \""+fname+fileVerExt+"\"" |
---|
518 | Execute/P "COMPILEPROCEDURES " |
---|
519 | end |
---|
520 | |
---|
521 | Menu "SANS Models" |
---|
522 | Submenu "Packages" |
---|
523 | "Unload Invariant", UnloadInvariant() |
---|
524 | End |
---|
525 | end |
---|
526 | |
---|
527 | Function Inv_HelpButtonProc(ctrlName) : ButtonControl |
---|
528 | String ctrlName |
---|
529 | |
---|
530 | DisplayHelpTopic/Z/K=1 "Calculate Scattering Invariant" |
---|
531 | if(V_flag != 0) |
---|
532 | DoAlert 0, "The Scattering Invariant Help file can not be found" |
---|
533 | endif |
---|
534 | End |
---|
535 | |
---|
536 | Function Inv_PickPathButtonProc(ctrlName) : ButtonControl |
---|
537 | String ctrlName |
---|
538 | |
---|
539 | A_PickPath() |
---|
540 | //pop the file menu |
---|
541 | Inv_FilePopMenuProc("",1,"") |
---|
542 | End |
---|
543 | |
---|
544 | //gets a valid file list (simply not the files with ".SAn" in the name) |
---|
545 | // |
---|
546 | Function Inv_FilePopMenuProc(ctrlName,popNum,popStr) : PopupMenuControl |
---|
547 | String ctrlName |
---|
548 | Variable popNum |
---|
549 | String popStr |
---|
550 | |
---|
551 | String tempStr=Inv_filterButtonProc(ctrlName) |
---|
552 | if(strlen(tempStr)==0) |
---|
553 | tempStr = "Pick the data path" |
---|
554 | Endif |
---|
555 | String/G root:Packages:NIST:invariant:gDataPopList =tempStr |
---|
556 | ControlUpdate/W=Invariant_Panel ywave |
---|
557 | |
---|
558 | End |
---|
559 | |
---|
560 | //function called byt the popups to get a file list of data that can be sorted |
---|
561 | // this procedure simply removes the raw data files from the string - there |
---|
562 | //can be lots of other junk present, but this is very fast... |
---|
563 | // |
---|
564 | // could also use the alternate procedure of keeping only file with the proper extension |
---|
565 | // |
---|
566 | Function/S Inv_filterButtonProc(ctrlName) |
---|
567 | String ctrlName |
---|
568 | |
---|
569 | String list="",newList="",item="" |
---|
570 | Variable num,ii |
---|
571 | |
---|
572 | //check for the path |
---|
573 | PathInfo catPathName |
---|
574 | if(V_Flag==0) |
---|
575 | DoAlert 0, "Data path does not exist - pick the data path from the button on the invariant panel" |
---|
576 | Return("") |
---|
577 | Endif |
---|
578 | |
---|
579 | list = IndexedFile(catpathName,-1,"????") |
---|
580 | num=ItemsInList(list,";") |
---|
581 | //print "num = ",num |
---|
582 | for(ii=(num-1);ii>=0;ii-=1) |
---|
583 | item = StringFromList(ii, list ,";") |
---|
584 | //simply remove all that are not raw data files (SA1 SA2 SA3) |
---|
585 | if( !stringmatch(item,"*.SA1*") && !stringmatch(item,"*.SA2*") && !stringmatch(item,"*.SA3*") ) |
---|
586 | if( !stringmatch(item,".*") && !stringmatch(item,"*.pxp") && !stringmatch(item,"*.DIV")) //eliminate mac "hidden" files, pxp, and div files |
---|
587 | newlist += item + ";" |
---|
588 | endif |
---|
589 | endif |
---|
590 | endfor |
---|
591 | //remove VAX version numbers |
---|
592 | newList = A_RemoveVersNumsFromList(newList) |
---|
593 | //sort |
---|
594 | newList = SortList(newList,";",0) |
---|
595 | |
---|
596 | return newlist |
---|
597 | End |
---|
598 | |
---|
599 | // Loads the selected file for fitting |
---|
600 | // and graphs the data as needed |
---|
601 | Proc Inv_Load_Proc(ctrlName): ButtonControl |
---|
602 | String ctrlName |
---|
603 | |
---|
604 | //Load the data |
---|
605 | String tempName="",partialName="" |
---|
606 | Variable err |
---|
607 | ControlInfo/W=Invariant_Panel ywave |
---|
608 | //find the file from the partial filename |
---|
609 | If( (cmpstr(S_value,"")==0) || (cmpstr(S_value,"none")==0) ) |
---|
610 | //null selection, or "none" from any popup |
---|
611 | Abort "no file selected in popup menu" |
---|
612 | else |
---|
613 | //selection not null |
---|
614 | partialName = S_value |
---|
615 | //Print partialName |
---|
616 | Endif |
---|
617 | //get a valid file based on this partialName and catPathName |
---|
618 | tempName = A_FindValidFilename(partialName) |
---|
619 | |
---|
620 | //prepend path to tempName for read routine |
---|
621 | PathInfo catPathName |
---|
622 | |
---|
623 | tempName = S_path + tempName |
---|
624 | |
---|
625 | //load in the data (into the root directory) |
---|
626 | A_LoadOneDDataWithName(tempName,0) |
---|
627 | //Print S_fileName |
---|
628 | //Print tempName |
---|
629 | |
---|
630 | String cleanLastFileName = CleanupName(root:Packages:NIST:gLastFileName,0) |
---|
631 | String dataStr = "root:"+cleanLastFileName+":" |
---|
632 | |
---|
633 | // keep global copies of the names rather than reading from the popup |
---|
634 | tempName=dataStr + cleanLastFileName+"_q" |
---|
635 | String/G root:Packages:NIST:invariant:QWave=tempName |
---|
636 | tempName=dataStr + cleanLastFileName+"_i" |
---|
637 | String/G root:Packages:NIST:invariant:IWave=tempName |
---|
638 | tempName=dataStr + cleanLastFileName+"_s" |
---|
639 | String/G root:Packages:NIST:invariant:SWave=tempName |
---|
640 | |
---|
641 | //Plot, and adjust the scaling to match the axis scaling set by the popups |
---|
642 | Plot_Inv_Data("") |
---|
643 | |
---|
644 | //if the slit-smeared box is checked, try to read the slit height |
---|
645 | // - if can't find it, maybe not really smeared data, so put up the Alert |
---|
646 | ControlInfo/W=Invariant_Panel check0 |
---|
647 | if(V_Value==1) |
---|
648 | SlitSmearedCheckProc("",1) |
---|
649 | endif |
---|
650 | End |
---|
651 | |
---|
652 | Proc InvDoneButton(ctrlName): ButtonControl |
---|
653 | String ctrlName |
---|
654 | DoWindow/K Invariant_Graph |
---|
655 | DoWindow/K Invariant_Panel |
---|
656 | end |
---|
657 | |
---|
658 | //get the slit height if the data is slit-smeared |
---|
659 | //set the globals as needed |
---|
660 | Function SlitSmearedCheckProc(ctrlName,checked) : CheckBoxControl |
---|
661 | String ctrlName |
---|
662 | Variable checked |
---|
663 | |
---|
664 | NVAR isSlitSmeared=root:Packages:NIST:invariant:gIsSlitSmeared |
---|
665 | // SVAR fileStr=root:Packages:NIST:gLastFileName |
---|
666 | |
---|
667 | //reset the global to the checkbox state |
---|
668 | isSlitSmeared = checked //==0 if the data is not slit smeared |
---|
669 | |
---|
670 | if(checked) //get the smearing info |
---|
671 | ControlInfo/W=Invariant_Panel ywave |
---|
672 | String folderStr=CleanupName(S_value,0) |
---|
673 | NVAR dQv=root:Packages:NIST:invariant:gDqv |
---|
674 | NVAR/Z loaded_dQv = $("root:"+folderStr+":USANS_dQv") |
---|
675 | if(NVAR_Exists(loaded_dQv)) |
---|
676 | dQv = loaded_dQv |
---|
677 | Print "Data is slit-smeared, dqv = ",dQv |
---|
678 | else |
---|
679 | DoAlert 0,"Can't find the slit height from the data. Enter the value manually if the data is truly slit-smeared, or uncheck the box." |
---|
680 | endif |
---|
681 | endif |
---|
682 | |
---|
683 | return(0) |
---|
684 | End |
---|