1 | #pragma rtGlobals=1 // Use modern global access method. |
---|
2 | #pragma version=5.0 |
---|
3 | #pragma IgorVersion=6.1 |
---|
4 | |
---|
5 | /////////////////////// |
---|
6 | // |
---|
7 | // Procedures to manipulate 1-D datasets |
---|
8 | // specifically, to subtract 1-D data (sample - buffer) |
---|
9 | // as is typically done for biological samples in buffer solution |
---|
10 | // |
---|
11 | // This was written largely by Dobrin Bossev |
---|
12 | // - I simply adapted it to work cleanly with the SANS Reduction Macros |
---|
13 | // - 14MAY03 SRK |
---|
14 | // |
---|
15 | // |
---|
16 | // - could be expanded to do more manipulations, but could quickly |
---|
17 | // become cumbersome (like the Arithmetic Panel) |
---|
18 | // |
---|
19 | // - could allow for interpolation to match data sets, or only a partial |
---|
20 | // q-range for the "solvent" file |
---|
21 | // |
---|
22 | /////////////////////// |
---|
23 | |
---|
24 | // main entry procedure for subtraction panel |
---|
25 | // re-initializes necessary folders and waves |
---|
26 | Proc OpenSubtract1DPanel() |
---|
27 | DoWindow/F Subtract_1D_Panel |
---|
28 | if(V_Flag==0) |
---|
29 | Init_Subtract1D() |
---|
30 | Subtract_1D() //the panel |
---|
31 | Plot_Sub1D() //the graph |
---|
32 | endif |
---|
33 | End |
---|
34 | |
---|
35 | // initializes data folder and waves needed for the panel (contains a listbox) |
---|
36 | Proc Init_Subtract1D() |
---|
37 | //create the data folder |
---|
38 | NewDataFolder/O/S root:myGlobals:Subtract1D |
---|
39 | //create the waves and variables |
---|
40 | String/G gName1="<none>" |
---|
41 | String/G gName2="<none>" |
---|
42 | Variable/G gSolvnormal=0 |
---|
43 | Variable/G gPresetc=0 |
---|
44 | Variable/G gS1=0 |
---|
45 | Variable/G gS2=0 |
---|
46 | Variable/G gCorrection=1 |
---|
47 | Variable/G gPlotState=0 |
---|
48 | Variable/G gNullSolvent=0 |
---|
49 | |
---|
50 | Make/N=1/D/O w01,w11,w21,w31,w41,w51 |
---|
51 | Make/N=1/D/O w02,w12,w22,w32,w42,w52 |
---|
52 | Duplicate/O w01 xsample |
---|
53 | Duplicate/O w11 ysample |
---|
54 | Duplicate/O w21 ssample |
---|
55 | Duplicate/O w02 xsolvent |
---|
56 | Duplicate/O w12 ysolvent |
---|
57 | Duplicate/O w22 ssolvent |
---|
58 | Duplicate/O w01 xresult |
---|
59 | Duplicate/O w11 yresult |
---|
60 | Duplicate/O w21 sresult |
---|
61 | |
---|
62 | SetDataFolder root: |
---|
63 | End |
---|
64 | |
---|
65 | //draws the panel to control the subtraction |
---|
66 | Proc Subtract_1D() |
---|
67 | if(root:myGlobals:gIsMac==1) |
---|
68 | NewPanel /W=(467,139,821,423)/K=2 as "Solvent Subtraction" |
---|
69 | else |
---|
70 | NewPanel /W=(522,139,876,422)/K=2 as "Solvent Subtraction" |
---|
71 | endif |
---|
72 | DoWindow/C Subtract_1D_Panel |
---|
73 | SetDrawEnv fsize=10, fstyle= 5,textrgb=(65535,0,0) |
---|
74 | DrawText 10,20,"Sample Scattering File:" |
---|
75 | SetDrawEnv textrgb= (0,0,65280),fstyle=5,fsize=10 |
---|
76 | DrawText 10,90,"Solvent Scattering File:" |
---|
77 | SetDrawEnv fsize=10, fstyle= 5 |
---|
78 | DrawText 10,165,"Result:" |
---|
79 | //add the controls |
---|
80 | Button button_0,pos={150,36},size={90,20},proc=LoadSample, title="Load Sample" |
---|
81 | Button button_0,help={"This will load the 6 column Sample Scattering File"} |
---|
82 | Button button_1,pos={150,106},size={90,20},proc=LoadSolvent,title="Load Solvent" |
---|
83 | Button button_1,help={"This will load the 6 column Solvent Scattering File"} |
---|
84 | Button button_4,pos={18,248},size={90,20},proc=Calculate,title="Calculate" |
---|
85 | Button button_4,help={"This will subtract the intensities of the two files according to the shown expression"} |
---|
86 | Button button_5,pos={122,248},size={110,20},proc=SaveResult,title="Save Result" |
---|
87 | Button button_5,help={"This will save the result in a file"} |
---|
88 | Button button_6,pos={10,196},size={125,20},proc=MatchingRange,title="Matching Range" |
---|
89 | Button button_6,help={"This will capture the range between the two cursors to determine f"} |
---|
90 | Button button_2,pos={275,248},size={50,20},proc=Sub1D_DoneButton,title="Done" |
---|
91 | Button button_2,help={"Closes both the panel and the associated graph"} |
---|
92 | Button button_3,pos={300,36},size={25,20},proc=ShowSub1DHelp,title="?" |
---|
93 | Button button_3,help={"Shows help file for subtracting 1-D data sets"} |
---|
94 | CheckBox check_0,pos={14,40},size={117,14},proc=CheckCon,title="Rescale Sample file?" |
---|
95 | CheckBox check_0,value= root:myGlobals:Subtract1D:gSolvnormal |
---|
96 | CheckBox check_1,pos={235,187},size={134,14},proc=CheckCon,title="Preset manually?" |
---|
97 | CheckBox check_1,value= root:myGlobals:Subtract1D:gPresetc |
---|
98 | CheckBox check_2,pos={225,150},size={134,14},proc=NullSolventCheck,title="Solvent = 1?" |
---|
99 | CheckBox check_2,value= root:myGlobals:Subtract1D:gNullSolvent,disable=2 |
---|
100 | // |
---|
101 | ValDisplay valdisp_0,pos={145,187},size={70,18},title="Start ",Font="Arial",fsize=10 |
---|
102 | ValDisplay valdisp_0,limits={0,0,0},barmisc={0,1000},value= root:myGlobals:Subtract1D:gS1 |
---|
103 | ValDisplay valdisp_1,pos={145,207},size={70,18},title="End ",Font="Arial",fsize=10 |
---|
104 | ValDisplay valdisp_1,limits={0,0,0},barmisc={0,1000},value= root:myGlobals:Subtract1D:gS2 |
---|
105 | // |
---|
106 | SetVariable setvar_0,pos={250,207},size={70,19},title=":",font="Arial",fsize=10 |
---|
107 | SetVariable setvar_0,limits={-inf,inf,0},value=root:myGlobals:Subtract1D:gCorrection |
---|
108 | //sample name |
---|
109 | SetVariable setvar_1,pos={150,7},size={200,20},title=":",noEdit=1 |
---|
110 | SetVariable setvar_1,limits={1,1,0},value=root:myGlobals:Subtract1D:gName1 |
---|
111 | //solvent name |
---|
112 | SetVariable setvar_2,pos={150,77},size={200,20},title=":",noEdit=1 |
---|
113 | SetVariable setvar_2,limits={1,1,0},value=root:myGlobals:Subtract1D:gName2 |
---|
114 | // |
---|
115 | SetDrawEnv fname="Times", fsize=14, fstyle= 3 |
---|
116 | DrawText 289,202,"f" |
---|
117 | SetDrawEnv fname="Times", fsize=14, fstyle= 3 |
---|
118 | DrawText 241,223,"f" |
---|
119 | //draw the fancy text on the panel |
---|
120 | WriteExpression(0) |
---|
121 | |
---|
122 | EndMacro |
---|
123 | |
---|
124 | Function ShowSub1DHelp(ctrlName) : ButtonControl |
---|
125 | String ctrlName |
---|
126 | DisplayHelpTopic/Z/K=1 "SANS Data Reduction Tutorial[Subtract 1D Data]" |
---|
127 | if(V_flag !=0) |
---|
128 | DoAlert 0,"The SANS Data Reduction Tutorial Help file could not be found" |
---|
129 | endif |
---|
130 | End |
---|
131 | //kills both the panel and the graph, and then the data folder |
---|
132 | Function Sub1D_DoneButton(ctrlName) |
---|
133 | String ctrlName |
---|
134 | |
---|
135 | DoWindow/K Subtract_1D_Panel |
---|
136 | DoWindow/K Plot_Sub1D |
---|
137 | KillDataFolder root:myGlobals:Subtract1D |
---|
138 | return(0) |
---|
139 | End |
---|
140 | |
---|
141 | |
---|
142 | Function Calculate(ctrlName) : ButtonControl |
---|
143 | String ctrlName |
---|
144 | |
---|
145 | // SetDataFolder root:myGlobals:Subtract1D |
---|
146 | Variable p1,p2 |
---|
147 | SVAR gName1 = root:myGlobals:Subtract1D:gName1 |
---|
148 | SVAR gName2 = root:myGlobals:Subtract1D:gName2 |
---|
149 | //check for files |
---|
150 | if(cmpstr(gName2,"<none>") == 0) |
---|
151 | DoAlert 0, "Load Solvent file!" |
---|
152 | return(1) |
---|
153 | endif |
---|
154 | if(cmpstr(gName1,"<none>") == 0) |
---|
155 | DoAlert 0, "Load Sample file!" |
---|
156 | return(1) |
---|
157 | endif |
---|
158 | |
---|
159 | WAVE xsample=root:myGlobals:Subtract1D:xsample |
---|
160 | WAVE xsolvent=root:myGlobals:Subtract1D:xsolvent |
---|
161 | //WAVE w01=root:myGlobals:Subtract1D:w01 |
---|
162 | WAVE ysample=root:myGlobals:Subtract1D:ysample //w11 |
---|
163 | WAVE ssample=root:myGlobals:Subtract1D:ssample //w21 |
---|
164 | WAVE ysolvent=root:myGlobals:Subtract1D:ysolvent //w12 |
---|
165 | WAVE ssolvent=root:myGlobals:Subtract1D:ssolvent //w22 |
---|
166 | |
---|
167 | NVAR gPresetc = root:myGlobals:Subtract1D:gPresetc |
---|
168 | NVAR gSolvNormal = root:myGlobals:Subtract1D:gSolvNormal |
---|
169 | NVAR gCorrection = root:myGlobals:Subtract1D:gCorrection |
---|
170 | NVAR gNullSolvent = root:myGlobals:Subtract1D:gNullSolvent |
---|
171 | NVAR gS1 = root:myGlobals:Subtract1D:gS1 |
---|
172 | NVAR gS2 = root:myGlobals:Subtract1D:gS2 |
---|
173 | |
---|
174 | //no interpolation - exit if files are not EXACTLY the same length |
---|
175 | // and have EXACTLY the same q-values |
---|
176 | // |
---|
177 | ////////////// |
---|
178 | // Variable maxDiff |
---|
179 | // //check that both files are of the same length |
---|
180 | // if (numpnts(xsample)!=numpnts(xsolvent)) |
---|
181 | // DoAlert 0, "The lengths of Sample and Solvent files are NOT identical!" |
---|
182 | // return(1) |
---|
183 | // endif |
---|
184 | // |
---|
185 | // //check that both files have the same q-values |
---|
186 | // //currently, abort, but could offer to interpolate |
---|
187 | // Duplicate/O xsample helpwave |
---|
188 | // helpwave = 100*abs((xsample - xsolvent)/xsample) //% difference in q-values |
---|
189 | // WaveStats /Q helpwave |
---|
190 | // KillWaves /Z helpwave |
---|
191 | // maxDiff = V_max |
---|
192 | // if(maxDiff > 0.5) //each q-value must match to within 0.5% |
---|
193 | // DoAlert 0, "The q-values of Sample and Solvent files are NOT identical!" |
---|
194 | // return(1) |
---|
195 | // endif |
---|
196 | /////////////// |
---|
197 | |
---|
198 | //set up for interpolation |
---|
199 | Duplicate/O xsample root:myGlobals:Subtract1D:xsolv_interp //make the solvent x match the sample |
---|
200 | Duplicate/O xsample root:myGlobals:Subtract1D:ysolv_interp |
---|
201 | Duplicate/O xsample root:myGlobals:Subtract1D:ssolv_interp |
---|
202 | WAVE xsolv_interp = root:myGlobals:Subtract1D:xsolv_interp |
---|
203 | WAVE ysolv_interp = root:myGlobals:Subtract1D:ysolv_interp |
---|
204 | WAVE ssolv_interp = root:myGlobals:Subtract1D:ssolv_interp |
---|
205 | ysolv_interp = interp(xsolv_interp, xsolvent, ysolvent ) |
---|
206 | ssolv_interp = interp(xsolv_interp, xsolvent, ssolvent ) |
---|
207 | |
---|
208 | Duplicate/O xsample root:myGlobals:Subtract1D:xresult |
---|
209 | Duplicate/O ysample root:myGlobals:Subtract1D:yresult |
---|
210 | Duplicate/O ssample root:myGlobals:Subtract1D:sresult |
---|
211 | WAVE xresult = root:myGlobals:Subtract1D:xresult |
---|
212 | WAVE yresult = root:myGlobals:Subtract1D:yresult |
---|
213 | WAVE sresult = root:myGlobals:Subtract1D:sresult |
---|
214 | |
---|
215 | if (gPresetc==0) //find the constant from the cursor range |
---|
216 | Duplicate/O ysample helpwave |
---|
217 | if(gSolvNormal && gNullSolvent) |
---|
218 | helpWave = ysample //ysolvent == 0 under these conditions |
---|
219 | else |
---|
220 | helpwave = ysample/ysolv_interp //get the ratio = I(sample)/I(solvent) |
---|
221 | endif |
---|
222 | //gS1 and gS2 are qvalues now, convert them back to points |
---|
223 | //on the interpolated xsolv_interp |
---|
224 | p1 = BinarySearch(xsolv_interp, gS1 ) |
---|
225 | p2 = BinarySearch(xsolv_interp, gS2 ) |
---|
226 | //print p1,p2 |
---|
227 | WaveStats/Q/R=[p1,p2] helpwave //just in the selected range |
---|
228 | gCorrection = V_avg |
---|
229 | KillWaves /Z helpwave |
---|
230 | endif |
---|
231 | if (gSolvnormal==0) |
---|
232 | yresult = ysample - gCorrection*ysolv_interp |
---|
233 | sresult = sqrt(ssample^2+gCorrection*gCorrection*ssolv_interp^2) |
---|
234 | else |
---|
235 | yresult = ysample/gCorrection - ysolv_interp |
---|
236 | sresult = sqrt((ssample^2)/gCorrection/gCorrection+ssolv_interp^2) |
---|
237 | endif |
---|
238 | return(0) |
---|
239 | End |
---|
240 | |
---|
241 | Proc LoadSample(ctrlName) : ButtonControl |
---|
242 | String ctrlName |
---|
243 | |
---|
244 | LoadFile_Sub1D(1) |
---|
245 | SetDataFolder root:myGlobals:Subtract1D |
---|
246 | Duplicate/O w01 xsample |
---|
247 | Duplicate/O w11 ysample |
---|
248 | Duplicate/O w21 ssample |
---|
249 | SetDataFolder root: |
---|
250 | |
---|
251 | //allow user to set unity/null background, now that sample data exists |
---|
252 | CheckBox check_2 win=Subtract_1D_Panel,disable=0 |
---|
253 | //if solvent was set to one (or zero), toggle the box so the |
---|
254 | //"solvent" set is updated to reflect the q-values of the newly |
---|
255 | //loaded sample |
---|
256 | ControlInfo check_2 |
---|
257 | if(V_Value==1) |
---|
258 | NullSolventCheck("",1) //fakes as if the box was checked |
---|
259 | Endif |
---|
260 | |
---|
261 | End |
---|
262 | |
---|
263 | |
---|
264 | Proc LoadSolvent(ctrlName) : ButtonControl |
---|
265 | String ctrlName |
---|
266 | |
---|
267 | LoadFile_Sub1D(2) |
---|
268 | SetDataFolder root:myGlobals:Subtract1D |
---|
269 | Duplicate/O w02 xsolvent |
---|
270 | Duplicate/O w12 ysolvent |
---|
271 | Duplicate/O w22 ssolvent |
---|
272 | |
---|
273 | if (cmpstr(gName2,"<none>")!=0) |
---|
274 | Cursor A, ysolvent, leftx(xsolvent) |
---|
275 | Cursor/A=0 B, ysolvent, rightx(xsolvent) |
---|
276 | //make sure that the "solvent ==1" checkbox is not checked |
---|
277 | CheckBox check_2,value=0 |
---|
278 | //MatchingRange("none") |
---|
279 | endif |
---|
280 | SetDataFolder root: |
---|
281 | End |
---|
282 | |
---|
283 | //returns the Matching range to use in terms of q-values |
---|
284 | //rather than points, which will be incorrect if the |
---|
285 | //solvent data needs to be interpolated |
---|
286 | Function MatchingRange(ctrlName) : ButtonControl |
---|
287 | String ctrlName |
---|
288 | |
---|
289 | SVAR name2 = root:myGlobals:Subtract1D:gName2 |
---|
290 | NVAR s1 = root:myGlobals:Subtract1D:gS1 |
---|
291 | NVAR s2 = root:myGlobals:Subtract1D:gS2 |
---|
292 | if (cmpstr(name2,"<none>") != 0) |
---|
293 | s1=min(pcsr(A,"Plot_Sub1D" ),pcsr(B,"Plot_Sub1D")) |
---|
294 | s2=max(pcsr(A,"Plot_Sub1D" ),pcsr(B,"Plot_Sub1D")) |
---|
295 | Wave qval=root:myGlobals:Subtract1D:xsolvent //this will exist |
---|
296 | s1 = qval[s1] |
---|
297 | s2 = qval[s2] |
---|
298 | //print s1,s2 |
---|
299 | endif |
---|
300 | End |
---|
301 | |
---|
302 | Proc Plot_Sub1D() |
---|
303 | SetDataFolder root:myGlobals:Subtract1D |
---|
304 | if(root:myGlobals:gIsMac==1) |
---|
305 | Display/W=(14,44,454,484)/K=1 ysample vs xsample |
---|
306 | else |
---|
307 | Display/W=(14,44,350,380)/K=1 ysample vs xsample |
---|
308 | endif |
---|
309 | DoWindow/C Plot_Sub1D |
---|
310 | ModifyGraph rgb(ysample)=(65535,0,0) |
---|
311 | ErrorBars/T=0 ysample Y,wave=(ssample,ssample) |
---|
312 | AppendToGraph/L ysolvent vs xsolvent |
---|
313 | ModifyGraph rgb(ysolvent)=(0,0,65535) |
---|
314 | ErrorBars/T=0 ysolvent Y,wave=(ssolvent,ssolvent) |
---|
315 | //AppendToGraph/R yresult vs xresult |
---|
316 | AppendToGraph/L yresult vs xresult |
---|
317 | ModifyGraph rgb(yresult)=(0,65535,0) |
---|
318 | ErrorBars/T=0 yresult Y,wave=(sresult,sresult) |
---|
319 | ModifyGraph mode=3, msize=2, marker=19, mirror=1, tick=2, log(bottom)=1 |
---|
320 | Legend/C/N=text0/J/A=LT/X=2/Y=2 "\\s(ysample) Sample\r\\s(ysolvent) Solvent\r\\s(yresult) Result" |
---|
321 | ShowInfo |
---|
322 | Label left "Sample, Solvent I (cm\\S-1\M)" |
---|
323 | |
---|
324 | String angst = StrVarOrDefault("root:Packages:NIST:gAngstStr", "A" ) |
---|
325 | Label bottom "q ("+angst+"\\S-1\M)" |
---|
326 | // Label right "Result I/cm\\S-1" |
---|
327 | ControlBar 40 |
---|
328 | Button button_7,pos={10,10},size={125,20},proc=MatchingRange,title="Matching Range" |
---|
329 | Button button_7,help={"This will capture the range between the two cursors to determine f"} |
---|
330 | CheckBox check_0,pos={170,12},size={117,14},proc=PlotSub1DCheck,title="Log I(q)?" |
---|
331 | CheckBox check_0,value= root:myGlobals:Subtract1D:gPlotState |
---|
332 | SetDataFolder root: |
---|
333 | End |
---|
334 | |
---|
335 | //toggles the y-axis scaling of the graph between log and linear |
---|
336 | // the bottom axis is always log scale |
---|
337 | // |
---|
338 | Proc PlotSub1DCheck(ctrlName,checked) : CheckBoxControl |
---|
339 | String ctrlName |
---|
340 | Variable checked |
---|
341 | |
---|
342 | SetdataFolder root:myGlobals:Subtract1D |
---|
343 | if(checked) |
---|
344 | //make log scale |
---|
345 | ModifyGraph log=1 |
---|
346 | else |
---|
347 | //make linear scale on y-axis |
---|
348 | Modifygraph log=0,log(bottom)=1 |
---|
349 | endif |
---|
350 | gPlotState = checked |
---|
351 | SetDataFolder root: |
---|
352 | End |
---|
353 | |
---|
354 | // |
---|
355 | Proc NullSolventCheck(ctrlName,checked) : CheckBoxControl |
---|
356 | String ctrlName |
---|
357 | Variable checked |
---|
358 | |
---|
359 | SetDataFolder root:myGlobals:Subtract1D |
---|
360 | |
---|
361 | Variable solvValue |
---|
362 | String nameStr="" |
---|
363 | if(gSolvNormal) |
---|
364 | CheckBox check_2,title="Solvent = 0?" |
---|
365 | solvValue=0 |
---|
366 | nameStr="Solvent values set to zero" |
---|
367 | else |
---|
368 | CheckBox check_2,title="Solvent = 1?" |
---|
369 | solvValue=1 |
---|
370 | nameStr="Solvent value set to one" |
---|
371 | endif |
---|
372 | |
---|
373 | if(checked) |
---|
374 | //zero/one for the solvent |
---|
375 | Duplicate/O w01 xsolvent //duplicate the sample data |
---|
376 | Duplicate/O w11 ysolvent |
---|
377 | Duplicate/O w21 ssolvent |
---|
378 | ysolvent=solvValue |
---|
379 | ssolvent=0 |
---|
380 | if(gS1==0 && gS2 ==0) |
---|
381 | Cursor A, ysample, leftx(xsample) // put the cursors on the sample data |
---|
382 | Cursor/A=0 B, ysample, rightx(xsample) |
---|
383 | else |
---|
384 | Cursor A, ysample, BinarySearch(xsample, gS1 ) // put the cursors on the sample data |
---|
385 | Cursor/A=0 B, ysample, BinarySearch(xsample, gS2 ) |
---|
386 | endif |
---|
387 | gName2 = nameStr |
---|
388 | else |
---|
389 | gName2 = "<none>" |
---|
390 | Endif |
---|
391 | gNullSolvent=checked |
---|
392 | |
---|
393 | SetDataFolder root: |
---|
394 | End |
---|
395 | |
---|
396 | Proc CheckCon(ctrlName,checked) : CheckBoxControl |
---|
397 | String ctrlName |
---|
398 | Variable checked |
---|
399 | |
---|
400 | SetdataFolder root:myGlobals:Subtract1D |
---|
401 | if (cmpstr(ctrlName,"check_0") == 0) //box to set the normalization |
---|
402 | gSolvnormal =checked |
---|
403 | WriteExpression(checked) //draw the text of the expression being calculated |
---|
404 | ControlInfo check_2 |
---|
405 | NullSolventCheck("",V_Value) |
---|
406 | else |
---|
407 | //check_1, box to manually set the preset |
---|
408 | gPresetc = checked |
---|
409 | endif |
---|
410 | SetDataFolder root: |
---|
411 | End |
---|
412 | |
---|
413 | //type = 1 specifies sample data |
---|
414 | //type = 2 specifies solvent data |
---|
415 | // |
---|
416 | // any existing data will be overwritten |
---|
417 | // |
---|
418 | // need to retain header information for later save |
---|
419 | // will need a more sophisticated open/close to get the header |
---|
420 | // |
---|
421 | //don't try to re-write as a function - not worth the effort |
---|
422 | // |
---|
423 | Proc LoadFile_Sub1D(type) |
---|
424 | Variable type |
---|
425 | |
---|
426 | String n0,n1,n2,n3,n4,n5,help |
---|
427 | |
---|
428 | Variable refnum,numLines,numData,numHdr,ii |
---|
429 | String fileStr="",junkStr="" |
---|
430 | |
---|
431 | //junkStr = PadString(junkStr, 100, 0 ) |
---|
432 | fileStr=DoOpenFileDialog("pick a 1D data set") |
---|
433 | if(cmpstr(fileStr,"")==0) |
---|
434 | return //no file selected, exit |
---|
435 | endif |
---|
436 | |
---|
437 | SetDataFolder root:myGlobals:Subtract1D |
---|
438 | LoadWave/G/D/A fileStr |
---|
439 | If (V_flag==6) |
---|
440 | n0 = StringFromList(0, S_waveNames ,";" ) |
---|
441 | n1 = StringFromList(1, S_waveNames ,";" ) |
---|
442 | n2 = StringFromList(2, S_waveNames ,";" ) |
---|
443 | n3 = StringFromList(3, S_waveNames ,";" ) |
---|
444 | n4 = StringFromList(4, S_waveNames ,";" ) |
---|
445 | n5 = StringFromList(5, S_waveNames ,";" ) |
---|
446 | Duplicate/O $n0, $("w0" + num2istr(type)) |
---|
447 | Duplicate/O $n1, $("w1" + num2istr(type)) |
---|
448 | Duplicate/O $n2, $("w2" + num2istr(type)) |
---|
449 | Duplicate/O $n3, $("w3" + num2istr(type)) |
---|
450 | Duplicate/O $n4, $("w4" + num2istr(type)) |
---|
451 | Duplicate/O $n5, $("w5" + num2istr(type)) |
---|
452 | if (type==1) |
---|
453 | gName1 = S_fileName |
---|
454 | //read in the header of the sample file |
---|
455 | // not yet implemented |
---|
456 | numLines = CountNumLines(fileStr) |
---|
457 | numData = numpnts($n0) |
---|
458 | numHdr = numLines - numData |
---|
459 | Make/T/O/N=(numHdr) SampleHeader |
---|
460 | Open/R refNum as fileStr |
---|
461 | ii=0 |
---|
462 | do |
---|
463 | FReadLine refnum, junkStr |
---|
464 | SampleHeader[ii] = junkStr |
---|
465 | ii+=1 |
---|
466 | while(ii<numHdr) |
---|
467 | Close refnum |
---|
468 | else |
---|
469 | gName2 = S_fileName |
---|
470 | endif |
---|
471 | |
---|
472 | elseif (V_flag == 4) |
---|
473 | n0 = StringFromList(0, S_waveNames ,";" ) |
---|
474 | n1 = StringFromList(1, S_waveNames ,";" ) |
---|
475 | n2 = StringFromList(2, S_waveNames ,";" ) |
---|
476 | n3 = StringFromList(3, S_waveNames ,";" ) |
---|
477 | Duplicate/O $n0, $("w0" + num2istr(type)) |
---|
478 | Duplicate/O $n1, $("w1" + num2istr(type)) |
---|
479 | Duplicate/O $n2, $("w2" + num2istr(type)) |
---|
480 | Duplicate/O $n3, $("w3" + num2istr(type)) |
---|
481 | if (type==1) |
---|
482 | gName1 = S_fileName |
---|
483 | //read in the header of the sample file |
---|
484 | // not yet implemented |
---|
485 | numLines = CountNumLines(fileStr) |
---|
486 | numData = numpnts($n0) |
---|
487 | numHdr = numLines - numData |
---|
488 | Make/T/O/N=(numHdr) SampleHeader |
---|
489 | Open/R refNum as fileStr |
---|
490 | ii=0 |
---|
491 | do |
---|
492 | FReadLine refnum, junkStr |
---|
493 | SampleHeader[ii] = junkStr |
---|
494 | ii+=1 |
---|
495 | while(ii<numHdr) |
---|
496 | Close refnum |
---|
497 | else |
---|
498 | gName2 = S_fileName |
---|
499 | endif |
---|
500 | |
---|
501 | elseif (V_flag == 3) |
---|
502 | n0 = StringFromList(0, S_waveNames ,";" ) |
---|
503 | n1 = StringFromList(1, S_waveNames ,";" ) |
---|
504 | n2 = StringFromList(2, S_waveNames ,";" ) |
---|
505 | Duplicate/O $n0, $("w0" + num2istr(type)) |
---|
506 | Duplicate/O $n1, $("w1" + num2istr(type)) |
---|
507 | Duplicate/O $n2, $("w2" + num2istr(type)) |
---|
508 | if (type==1) |
---|
509 | gName1 = S_fileName |
---|
510 | //read in the header of the sample file |
---|
511 | // not yet implemented |
---|
512 | numLines = CountNumLines(fileStr) |
---|
513 | numData = numpnts($n0) |
---|
514 | numHdr = numLines - numData |
---|
515 | Make/T/O/N=(numHdr) SampleHeader |
---|
516 | Open/R refNum as fileStr |
---|
517 | ii=0 |
---|
518 | do |
---|
519 | FReadLine refnum, junkStr |
---|
520 | SampleHeader[ii] = junkStr |
---|
521 | ii+=1 |
---|
522 | while(ii<numHdr) |
---|
523 | Close refnum |
---|
524 | else |
---|
525 | gName2 = S_fileName |
---|
526 | endif |
---|
527 | else |
---|
528 | if (V_flag>0) |
---|
529 | DoAlert 0, "This is NOT a 3-, 4- or 6-column file !" |
---|
530 | endif |
---|
531 | endif |
---|
532 | //do some cleanup |
---|
533 | |
---|
534 | KillWaves/Z wave0,wave1,wave2,wave3,wave4,wave5,wave6,wave7,wave8,wave9,wave10 |
---|
535 | |
---|
536 | setDataFolder root: |
---|
537 | end |
---|
538 | |
---|
539 | Function CountNumLines(fileStr) |
---|
540 | String fileStr |
---|
541 | |
---|
542 | Variable num,refnum |
---|
543 | num=0 |
---|
544 | Open/R refNum as fileStr |
---|
545 | do |
---|
546 | FReadLine refnum, junkStr |
---|
547 | FStatus refnum |
---|
548 | // Print junkStr |
---|
549 | num+=1 |
---|
550 | while(V_FilePos<V_logEOF) |
---|
551 | // print "numlines = ",num |
---|
552 | Close refnum |
---|
553 | return(num) |
---|
554 | End |
---|
555 | |
---|
556 | |
---|
557 | Function SaveResult(ctrlName) : ButtonControl |
---|
558 | String ctrlName |
---|
559 | |
---|
560 | WAVE xresult = root:myGlobals:Subtract1D:xresult |
---|
561 | WAVE yresult = root:myGlobals:Subtract1D:yresult |
---|
562 | WAVE sresult = root:myGlobals:Subtract1D:sresult |
---|
563 | WAVE w31 = root:myGlobals:Subtract1D:w31 |
---|
564 | WAVE w41 = root:myGlobals:Subtract1D:w41 |
---|
565 | WAVE w51 = root:myGlobals:Subtract1D:w51 |
---|
566 | WAVE/T hdr = root:myGlobals:Subtract1D:SampleHeader |
---|
567 | |
---|
568 | //check each wave for existence |
---|
569 | Variable err=0,refnum |
---|
570 | String fileName="" |
---|
571 | String formatStr = "" |
---|
572 | if (WaveExists(w41) && WaveExists(w51)) |
---|
573 | //6-column |
---|
574 | formatStr = "%15.4g %15.4g %15.4g %15.4g %15.4g %15.4g\r\n" |
---|
575 | elseif(WaveExists(w31)) |
---|
576 | //4-column (ILL) |
---|
577 | formatStr = "%15.4g %15.4g %15.4g %15.4g\r\n" |
---|
578 | else |
---|
579 | //3-column |
---|
580 | formatStr = "%15.4g %15.4g %15.4g\r\n" |
---|
581 | endif |
---|
582 | err += 1 - WaveExists(xresult) |
---|
583 | err += 1 - WaveExists(yresult) |
---|
584 | err += 1 - WaveExists(sresult) |
---|
585 | //err += 1 - WaveExists(w31) |
---|
586 | //err += 1 - WaveExists(w41) |
---|
587 | //err += 1 - WaveExists(w51) |
---|
588 | err += 1 - WaveExists(hdr) |
---|
589 | |
---|
590 | if(err>0) |
---|
591 | DoAlert 0,"We need at least 3 column data - I can't write out the file" |
---|
592 | return(1) |
---|
593 | endif |
---|
594 | |
---|
595 | SVAR loadedFile=root:myGlobals:Subtract1D:gName1 |
---|
596 | fileName = DoSaveFileDialog("Save Data as",fname=loadedFile,suffix="b") |
---|
597 | if(cmpstr(fileName,"")==0) |
---|
598 | return(1) |
---|
599 | endif |
---|
600 | Open refNum as fileName |
---|
601 | wfprintf refnum,"%s\n",hdr //strings already have \r? |
---|
602 | if (WaveExists(w41) && WaveExists(w51)) |
---|
603 | wfprintf refnum, formatStr, xresult,yresult,sresult,w31,w41,w51 |
---|
604 | elseif (WaveExists(w31)) |
---|
605 | wfprintf refnum, formatStr, xresult,yresult,sresult,w31 |
---|
606 | else |
---|
607 | wfprintf refnum,formatStr, xresult,yresult,sresult |
---|
608 | endif |
---|
609 | Close refnum |
---|
610 | |
---|
611 | return(0) |
---|
612 | End |
---|
613 | |
---|
614 | Proc WriteExpression(choice) |
---|
615 | Variable choice |
---|
616 | |
---|
617 | SetDrawEnv /W=Subtract_1D_Panel linefgc= (65535,65535,65535) |
---|
618 | DrawRect 90,140,207,174 |
---|
619 | SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,65535,0) |
---|
620 | DrawText 100,168,"I" |
---|
621 | SetDrawEnv fname="Times", fsize=22, fstyle= 1,textrgb= (0,0,0) |
---|
622 | DrawText 100,168," =" |
---|
623 | SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (65535,0,0) |
---|
624 | DrawText 100,168," I" |
---|
625 | SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,0,65535) |
---|
626 | DrawText 100,168," I" |
---|
627 | if (choice==0) |
---|
628 | SetDrawEnv fname="Symbol", fsize=22, fstyle= 1,textrgb= (0,0,0) |
---|
629 | DrawText 100,168," -" |
---|
630 | SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,0,0) |
---|
631 | DrawText 100,168," f " |
---|
632 | SetDrawEnv fname="Times", fsize=22, fstyle= 1,textrgb= (0,0,0) |
---|
633 | DrawText 100,168," *" |
---|
634 | else |
---|
635 | SetDrawEnv fname="Times", fsize=22, fstyle= 1,textrgb= (0,0,0) |
---|
636 | DrawText 100,168," /" |
---|
637 | SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,0,0) |
---|
638 | DrawText 100,168," f " |
---|
639 | SetDrawEnv fname="Symbol", fsize=22, fstyle= 1,textrgb= (0,0,0) |
---|
640 | DrawText 100,168," -" |
---|
641 | endif |
---|
642 | End |
---|