1 | #pragma TextEncoding = "MacRoman" // For details execute DisplayHelpTopic "The TextEncoding Pragma" |
---|
2 | #pragma rtGlobals=3 // Use modern global access method and strict wave access. |
---|
3 | |
---|
4 | |
---|
5 | // |
---|
6 | // Operation does no scaling, only the basic (default) trim of the ends, concatenate, sort, and save |
---|
7 | // -- if data has been converted to WORK and the solid angle correction was done, then the data |
---|
8 | // is per unit solid angle, and matches up - at least the simulated data does... |
---|
9 | // It should match up in real VSANS data since the flux conditions are identical for |
---|
10 | // all panels, only the geometry is different. |
---|
11 | // |
---|
12 | // |
---|
13 | // V_DataPlotting.ipf is where the I(q) panel is drawn and the binning is set |
---|
14 | // |
---|
15 | // see the VCALC BinAllMiddlePanels() for an example of this |
---|
16 | // see the binning routines in VC_DetectorBinning_Utils.ipf for the details |
---|
17 | // |
---|
18 | |
---|
19 | // TODO |
---|
20 | // |
---|
21 | // -- verify the binning for slit mode. Looks correct, but verify |
---|
22 | // -- DOCUMENT |
---|
23 | // |
---|
24 | // x- detector "B" is currently skipped since the calibration waves are not faked |
---|
25 | // when the raw data is loaded. Then the qxqyqz waves are not generated. |
---|
26 | // |
---|
27 | // x- REDO the logic here. It's a mess, and will get the calculation wrong |
---|
28 | // |
---|
29 | // x- figure out the binning type (where is it set for VSANS?) |
---|
30 | // x- don't know, so currently VSANS binning type is HARD-WIRED |
---|
31 | // x- figure out when this needs to be called to (force) re-calculate I vs Q |
---|
32 | // |
---|
33 | |
---|
34 | |
---|
35 | |
---|
36 | Strconstant ksPanelBinTypeList = "B;FT;FB;FL;FR;MT;MB;ML;MR;FTB;FLR;MTB;MLR;FLRTB;MLRTB;" |
---|
37 | |
---|
38 | Strconstant ksBinTypeStr = "One;Two;Four;Slit Mode;" |
---|
39 | Strconstant ksBinType1 = "B;FT;FB;FL;FR;MT;MB;ML;MR;" //these are the "active" extensions |
---|
40 | Strconstant ksBinType2 = "B;FTB;FLR;MTB;MLR;" |
---|
41 | Strconstant ksBinType3 = "B;FLRTB;MLRTB;" |
---|
42 | Strconstant ksBinType4 = "B;FT;FB;FL;FR;MT;MB;ML;MR;" |
---|
43 | |
---|
44 | |
---|
45 | // NOTE |
---|
46 | // this is the master conversion function |
---|
47 | // ***Use no others |
---|
48 | // *** When other bin types are developed, DO NOT reassign these numbers. |
---|
49 | // instead, skip the old numbers and assign new ones. |
---|
50 | // old modes can be removed from the string constant ksBinTypeStr (above), but the |
---|
51 | // mode numbers are what many different binning, plotting, and reduction functions are |
---|
52 | // switching on. In the future, it may be necessary to change the key (everywhere) to a string |
---|
53 | // switch, but for now, stick with the numbers. |
---|
54 | Function V_BinTypeStr2Num(binStr) |
---|
55 | String binStr |
---|
56 | |
---|
57 | Variable binType |
---|
58 | strswitch(binStr) // string switch |
---|
59 | case "One": |
---|
60 | binType = 1 |
---|
61 | break // exit from switch |
---|
62 | case "Two": |
---|
63 | binType = 2 |
---|
64 | break // exit from switch |
---|
65 | case "Four": |
---|
66 | binType = 3 |
---|
67 | break // exit from switch |
---|
68 | case "Slit Mode": |
---|
69 | binType = 4 |
---|
70 | break // exit from switch |
---|
71 | |
---|
72 | default: // optional default expression executed |
---|
73 | binType = 0 |
---|
74 | Abort "Binning mode not found"// when no case matches |
---|
75 | endswitch |
---|
76 | return(binType) |
---|
77 | end |
---|
78 | |
---|
79 | Function V_QBinAllPanels(folderStr,binType) |
---|
80 | String folderStr |
---|
81 | Variable binType |
---|
82 | |
---|
83 | // do the back, middle, and front separately |
---|
84 | |
---|
85 | // figure out the binning type (where is it set?) |
---|
86 | Variable ii,delQ |
---|
87 | String detStr |
---|
88 | |
---|
89 | // binType = V_GetBinningPopMode() |
---|
90 | |
---|
91 | //// TODO: |
---|
92 | // |
---|
93 | // Back detector is handled spearately since there is nothing to combine |
---|
94 | // |
---|
95 | delQ = SetDeltaQ(folderStr,"B") |
---|
96 | |
---|
97 | // dispatch based on binning type |
---|
98 | if(binType == 1 || binType == 2 || binType == 3) |
---|
99 | VC_fDoBinning_QxQy2D(folderStr, "B") //normal binning, nothing to combine |
---|
100 | endif |
---|
101 | |
---|
102 | // TODO -- this is only a temporary fix for slit mode |
---|
103 | if(binType == 4) |
---|
104 | /// this is for a tall, narrow slit mode |
---|
105 | VC_fBinDetector_byRows(folderStr,"B") |
---|
106 | endif |
---|
107 | |
---|
108 | |
---|
109 | |
---|
110 | // these are the binning types where detectors are not combined |
---|
111 | // other combined binning is below the loop |
---|
112 | for(ii=0;ii<ItemsInList(ksDetectorListNoB);ii+=1) |
---|
113 | detStr = StringFromList(ii, ksDetectorListNoB, ";") |
---|
114 | |
---|
115 | // set delta Q for binning |
---|
116 | delQ = SetDeltaQ(folderStr,detStr) |
---|
117 | |
---|
118 | // dispatch based on binning type |
---|
119 | if(binType==1) |
---|
120 | VC_fDoBinning_QxQy2D(folderStr,detStr) |
---|
121 | endif |
---|
122 | |
---|
123 | // TODO -- this is only a temporary fix for slit mode |
---|
124 | if(binType == 4) |
---|
125 | /// this is for a tall, narrow slit mode |
---|
126 | VC_fBinDetector_byRows(folderStr,detStr) |
---|
127 | endif |
---|
128 | |
---|
129 | endfor |
---|
130 | |
---|
131 | // bin in pairs |
---|
132 | if(binType == 2) |
---|
133 | VC_fDoBinning_QxQy2D(folderStr,"MLR") |
---|
134 | VC_fDoBinning_QxQy2D(folderStr,"MTB") |
---|
135 | VC_fDoBinning_QxQy2D(folderStr,"FLR") |
---|
136 | VC_fDoBinning_QxQy2D(folderStr,"FTB") |
---|
137 | endif |
---|
138 | |
---|
139 | // bin everything on front or middle together |
---|
140 | if(binType == 3) |
---|
141 | VC_fDoBinning_QxQy2D(folderStr,"MLRTB") |
---|
142 | VC_fDoBinning_QxQy2D(folderStr,"FLRTB") |
---|
143 | endif |
---|
144 | |
---|
145 | return(0) |
---|
146 | End |
---|
147 | |
---|
148 | // concatenates and sorts the 1D data in "type" WORK folder |
---|
149 | // uses the current display if type=="" |
---|
150 | // |
---|
151 | Function V_ConcatenateForSave(type,binType) |
---|
152 | String type |
---|
153 | Variable binType |
---|
154 | |
---|
155 | // get the current display type, if null string passed in |
---|
156 | SVAR curtype = root:Packages:NIST:VSANS:Globals:gCurDispType |
---|
157 | |
---|
158 | if(strlen(type)==0) |
---|
159 | type = curType |
---|
160 | endif |
---|
161 | |
---|
162 | // trim the data if needed |
---|
163 | // remove the q=0 point from the back detector, if it's there |
---|
164 | // does not need to know binType |
---|
165 | V_RemoveQ0_B(type) |
---|
166 | |
---|
167 | // concatenate the data sets |
---|
168 | // TODO x- figure out which binning was used (this is done in V_1DConcatenate()) |
---|
169 | // clear the old tmp waves first, if they still exist |
---|
170 | SetDataFolder $("root:Packages:NIST:VSANS:"+type) |
---|
171 | Killwaves/Z tmp_q,tmp_i,tmp_s |
---|
172 | setDataFolder root: |
---|
173 | V_1DConcatenate(type,binType) |
---|
174 | |
---|
175 | // sort the data set |
---|
176 | V_TmpSort1D(type) |
---|
177 | |
---|
178 | return(0) |
---|
179 | End |
---|
180 | |
---|
181 | // |
---|
182 | // this is only called from the button on the data panel |
---|
183 | // so the type is the currently displayed type, and the binning is from the panel |
---|
184 | // |
---|
185 | Function V_SimpleSave1DData(type,saveName) |
---|
186 | String type,saveName |
---|
187 | |
---|
188 | // |
---|
189 | // get the current display type, if null string passed in |
---|
190 | SVAR curtype = root:Packages:NIST:VSANS:Globals:gCurDispType |
---|
191 | Variable binType = V_GetBinningPopMode() |
---|
192 | |
---|
193 | V_ConcatenateForSave(curType,binType) |
---|
194 | |
---|
195 | // write out the data set to a file |
---|
196 | if(strlen(saveName)==0) |
---|
197 | Execute "V_GetNameForSave()" |
---|
198 | SVAR newName = root:saveName |
---|
199 | saveName = newName |
---|
200 | endif |
---|
201 | |
---|
202 | V_Write1DData(curtype,saveName) |
---|
203 | |
---|
204 | End |
---|
205 | |
---|
206 | |
---|
207 | Proc V_GetNameForSave(str) |
---|
208 | String str |
---|
209 | String/G root:saveName=str |
---|
210 | End |
---|
211 | |
---|
212 | |
---|
213 | // blindly assumes that there is only one zero at the top of the wave |
---|
214 | // could be more sophisticated in the future... |
---|
215 | Function V_RemoveQ0_B(type) |
---|
216 | String type |
---|
217 | |
---|
218 | SetDataFolder $("root:Packages:NIST:VSANS:"+type) |
---|
219 | |
---|
220 | WAVE/Z qBin = qBin_qxqy_B |
---|
221 | WAVE/Z iBin = iBin_qxqy_B |
---|
222 | WAVE/Z eBin = eBin_qxqy_B |
---|
223 | WAVE/Z nBin = nBin_qxqy_B |
---|
224 | WAVE/Z iBin2 = iBin2_qxqy_B |
---|
225 | |
---|
226 | if(qBin[0] == 0) |
---|
227 | DeletePoints 0, 1, qBin,iBin,eBin,nBin,iBin2 |
---|
228 | endif |
---|
229 | |
---|
230 | SetDataFolder root: |
---|
231 | return(0) |
---|
232 | end |
---|
233 | |
---|
234 | |
---|
235 | // concatentate data in folderStr |
---|
236 | // |
---|
237 | // TODO: |
---|
238 | // x- this currently ignores the binning type (one, two, etc. ) |
---|
239 | // x- change the Concatenate call to use the waveList, to eliminate the need to declare all of the waves |
---|
240 | // -- this currently assumes that all of the waves exist |
---|
241 | // -- need robust error checking for wave existence |
---|
242 | // -- wave names are hard-wired and their name and location may be different in the future |
---|
243 | // x- if different averaging options were chosen (bin type of 2, 4 etc) then |
---|
244 | // although waves may exist, they may not be the right ones to use. There |
---|
245 | // will be a somewhat complex selection process |
---|
246 | // x- detector B is currently skipped |
---|
247 | // |
---|
248 | // this seems like a lot of extra work to do something so simple...but it's better than a loop |
---|
249 | // |
---|
250 | // root:Packages:NIST:VSANS:RAW:iBin_qxqy_FB |
---|
251 | // |
---|
252 | // binType = 1 = one |
---|
253 | // binType = 2 = two |
---|
254 | // binType = 3 = four |
---|
255 | // binType = 4 = Slit Mode |
---|
256 | // |
---|
257 | // if binType is passed in as -9999, get the binning mode from the popup |
---|
258 | // otherwise the value is assumed good (from a protocol) |
---|
259 | // |
---|
260 | // |
---|
261 | // |
---|
262 | Function V_1DConcatenate(folderStr,binType) |
---|
263 | String folderStr |
---|
264 | Variable binType |
---|
265 | |
---|
266 | if(binType==-9999) |
---|
267 | binType = V_GetBinningPopMode() |
---|
268 | endif |
---|
269 | |
---|
270 | SetDataFolder $("root:Packages:NIST:VSANS:"+folderStr) |
---|
271 | |
---|
272 | //kill these waves before starting, or the new concatenation will be added to the old |
---|
273 | KillWaves/Z tmp_q,tmp_i,tmp_s |
---|
274 | |
---|
275 | String waveListStr="" |
---|
276 | if(binType == 1) |
---|
277 | // q-values |
---|
278 | waveListStr = "qBin_qxqy_B;qBin_qxqy_MB;qBin_qxqy_MT;qBin_qxqy_ML;qBin_qxqy_MR;" |
---|
279 | waveListStr += "qBin_qxqy_FB;qBin_qxqy_FT;qBin_qxqy_FL;qBin_qxqy_FR;" |
---|
280 | |
---|
281 | Concatenate/NP/O waveListStr, tmp_q |
---|
282 | |
---|
283 | //intensity |
---|
284 | waveListStr = "iBin_qxqy_B;iBin_qxqy_MB;iBin_qxqy_MT;iBin_qxqy_ML;iBin_qxqy_MR;" |
---|
285 | waveListStr += "iBin_qxqy_FB;iBin_qxqy_FT;iBin_qxqy_FL;iBin_qxqy_FR;" |
---|
286 | |
---|
287 | Concatenate/NP/O waveListStr, tmp_i |
---|
288 | |
---|
289 | //error |
---|
290 | waveListStr = "eBin_qxqy_B;eBin_qxqy_MB;eBin_qxqy_MT;eBin_qxqy_ML;eBin_qxqy_MR;" |
---|
291 | waveListStr += "eBin_qxqy_FB;eBin_qxqy_FT;eBin_qxqy_FL;eBin_qxqy_FR;" |
---|
292 | |
---|
293 | Concatenate/NP/O waveListStr, tmp_s |
---|
294 | endif |
---|
295 | |
---|
296 | if(binType == 2) |
---|
297 | // q-values |
---|
298 | waveListStr = "qBin_qxqy_B;qBin_qxqy_MTB;qBin_qxqy_MLR;" |
---|
299 | waveListStr += "qBin_qxqy_FTB;qBin_qxqy_FLR;" |
---|
300 | |
---|
301 | Concatenate/NP/O waveListStr, tmp_q |
---|
302 | |
---|
303 | //intensity |
---|
304 | waveListStr = "iBin_qxqy_B;iBin_qxqy_MTB;iBin_qxqy_MLR;" |
---|
305 | waveListStr += "iBin_qxqy_FTB;iBin_qxqy_FLR;" |
---|
306 | |
---|
307 | Concatenate/NP/O waveListStr, tmp_i |
---|
308 | |
---|
309 | //error |
---|
310 | waveListStr = "eBin_qxqy_B;eBin_qxqy_MTB;eBin_qxqy_MLR;" |
---|
311 | waveListStr += "eBin_qxqy_FTB;eBin_qxqy_FLR;" |
---|
312 | |
---|
313 | Concatenate/NP/O waveListStr, tmp_s |
---|
314 | endif |
---|
315 | |
---|
316 | if(binType == 3) |
---|
317 | // q-values |
---|
318 | waveListStr = "qBin_qxqy_B;qBin_qxqy_MLRTB;qBin_qxqy_FLRTB;" |
---|
319 | |
---|
320 | Concatenate/NP/O waveListStr, tmp_q |
---|
321 | |
---|
322 | //intensity |
---|
323 | waveListStr = "iBin_qxqy_B;iBin_qxqy_MLRTB;iBin_qxqy_FLRTB;" |
---|
324 | |
---|
325 | Concatenate/NP/O waveListStr, tmp_i |
---|
326 | |
---|
327 | //error |
---|
328 | waveListStr = "eBin_qxqy_B;eBin_qxqy_MLRTB;eBin_qxqy_FLRTB;" |
---|
329 | |
---|
330 | Concatenate/NP/O waveListStr, tmp_s |
---|
331 | endif |
---|
332 | |
---|
333 | // TODO - This is the identical set of waves as for the case of binType = 1. |
---|
334 | // they have the same names, but are averaged differently since it's slit mode. |
---|
335 | // I have separated this, since in practice the TB panels are probably best to ignore |
---|
336 | // and NOT include in the averaging since the Qy range is so limited. |
---|
337 | if(binType == 4) |
---|
338 | // q-values |
---|
339 | waveListStr = "qBin_qxqy_B;qBin_qxqy_MB;qBin_qxqy_MT;qBin_qxqy_ML;qBin_qxqy_MR;" |
---|
340 | waveListStr += "qBin_qxqy_FB;qBin_qxqy_FT;qBin_qxqy_FL;qBin_qxqy_FR;" |
---|
341 | |
---|
342 | Concatenate/NP/O waveListStr, tmp_q |
---|
343 | |
---|
344 | //intensity |
---|
345 | waveListStr = "iBin_qxqy_B;iBin_qxqy_MB;iBin_qxqy_MT;iBin_qxqy_ML;iBin_qxqy_MR;" |
---|
346 | waveListStr += "iBin_qxqy_FB;iBin_qxqy_FT;iBin_qxqy_FL;iBin_qxqy_FR;" |
---|
347 | |
---|
348 | Concatenate/NP/O waveListStr, tmp_i |
---|
349 | |
---|
350 | //error |
---|
351 | waveListStr = "eBin_qxqy_B;eBin_qxqy_MB;eBin_qxqy_MT;eBin_qxqy_ML;eBin_qxqy_MR;" |
---|
352 | waveListStr += "eBin_qxqy_FB;eBin_qxqy_FT;eBin_qxqy_FL;eBin_qxqy_FR;" |
---|
353 | |
---|
354 | Concatenate/NP/O waveListStr, tmp_s |
---|
355 | endif |
---|
356 | |
---|
357 | // Can't kill here, since they are still needed to sort and write out! |
---|
358 | // KillWaves/Z tmp_q,tmp_i,tmp_s,tmp_res0,tmp_res1,tmp_res2,tmp_res3 |
---|
359 | |
---|
360 | SetDataFolder root: |
---|
361 | |
---|
362 | return(0) |
---|
363 | End |
---|
364 | |
---|
365 | // TODO: |
---|
366 | // -- resolution waves are ignored, since they don't exist (yet) |
---|
367 | // -- only a sort is done, no rescaling of data sets |
---|
368 | // (it's too late now anyways, since the data was concatenated) |
---|
369 | // |
---|
370 | // see Auto_Sort() in the SANS Automation ipf for the rest of the details of |
---|
371 | // how to combine the resolution waves (they also need to be concatenated, which is currently not done) |
---|
372 | // |
---|
373 | Function V_TmpSort1D(folderStr) |
---|
374 | String folderStr |
---|
375 | |
---|
376 | SetDataFolder $("root:Packages:NIST:VSANS:"+folderStr) |
---|
377 | |
---|
378 | Wave qw = tmp_q |
---|
379 | Wave iw = tmp_i |
---|
380 | Wave sw = tmp_s |
---|
381 | |
---|
382 | // Sort qw, qw,iw,sw,res0,res1,res2,res3 |
---|
383 | |
---|
384 | Sort qw, qw,iw,sw |
---|
385 | |
---|
386 | |
---|
387 | SetDataFolder root: |
---|
388 | return(0) |
---|
389 | End |
---|
390 | |
---|
391 | |
---|
392 | // TODO |
---|
393 | // needs: |
---|
394 | // -- trim the beamstop out (based on shadow?) |
---|
395 | // -- trim out zero q from the file (bad actor in analysis functions) |
---|
396 | // -- trim num from the highQ end or lowQ end? |
---|
397 | // -- splits the res wave into individual waves in anticipation of concatenation |
---|
398 | // -- or -- deal with the res wave after? |
---|
399 | // |
---|
400 | // -- make a copy of the waves? |
---|
401 | // -- then, what is the concatenate function looking for?? |
---|
402 | // |
---|
403 | Function V_Trim1DData(dataFolder,binType,nBeg,nEnd) |
---|
404 | String dataFolder |
---|
405 | Variable binType,nBeg,nEnd |
---|
406 | |
---|
407 | Variable npt,ii |
---|
408 | SetDataFolder $("root:Packages:NIST:VSANS:"+dataFolder) |
---|
409 | |
---|
410 | Printf "%d points removed from beginning, %d points from the end (of each set) before concatenating\r",nbeg,nend |
---|
411 | |
---|
412 | // for each binType block: |
---|
413 | // declare the waves |
---|
414 | // make a copy of the waves?? |
---|
415 | // //Break out resolution wave into separate waves |
---|
416 | // delete the beginning points from everything |
---|
417 | // trim off the last nEnd points from everything |
---|
418 | // DeletePoints num-nEnd,nEnd, qw,iw,sw |
---|
419 | // // delete all points where the shadow is < 0.98 |
---|
420 | ////Put resolution contents back??? |
---|
421 | |
---|
422 | if(binType == 1) |
---|
423 | Wave/Z q_fb = qBin_qxqy_FB |
---|
424 | Wave/Z q_ft = qBin_qxqy_FT |
---|
425 | Wave/Z q_fl = qBin_qxqy_FL |
---|
426 | Wave/Z q_fr = qBin_qxqy_FR |
---|
427 | Wave/Z q_mb = qBin_qxqy_MB |
---|
428 | Wave/Z q_mt = qBin_qxqy_MT |
---|
429 | Wave/Z q_ml = qBin_qxqy_ML |
---|
430 | Wave/Z q_mr = qBin_qxqy_MR |
---|
431 | Wave/Z q_b = qBin_qxqy_B |
---|
432 | |
---|
433 | Wave/Z i_fb = iBin_qxqy_FB |
---|
434 | Wave/Z i_ft = iBin_qxqy_FT |
---|
435 | Wave/Z i_fl = iBin_qxqy_FL |
---|
436 | Wave/Z i_fr = iBin_qxqy_FR |
---|
437 | Wave/Z i_mb = iBin_qxqy_MB |
---|
438 | Wave/Z i_mt = iBin_qxqy_MT |
---|
439 | Wave/Z i_ml = iBin_qxqy_ML |
---|
440 | Wave/Z i_mr = iBin_qxqy_MR |
---|
441 | Wave/Z i_b = iBin_qxqy_B |
---|
442 | |
---|
443 | Wave/Z s_fb = eBin_qxqy_FB |
---|
444 | Wave/Z s_ft = eBin_qxqy_FT |
---|
445 | Wave/Z s_fl = eBin_qxqy_FL |
---|
446 | Wave/Z s_fr = eBin_qxqy_FR |
---|
447 | Wave/Z s_mb = eBin_qxqy_MB |
---|
448 | Wave/Z s_mt = eBin_qxqy_MT |
---|
449 | Wave/Z s_ml = eBin_qxqy_ML |
---|
450 | Wave/Z s_mr = eBin_qxqy_MR |
---|
451 | Wave/Z s_b = eBin_qxqy_B |
---|
452 | |
---|
453 | DeletePoints 0,nBeg, q_fb,q_ft,q_fl,q_fr,q_mb,q_mt,q_ml,q_mr,q_b |
---|
454 | DeletePoints 0,nBeg, i_fb,i_ft,i_fl,i_fr,i_mb,i_mt,i_ml,i_mr,i_b |
---|
455 | DeletePoints 0,nBeg, s_fb,s_ft,s_fl,s_fr,s_mb,s_mt,s_ml,s_mr,s_b |
---|
456 | //since each set may have a different number of points |
---|
457 | npt = numpnts(q_fb) |
---|
458 | DeletePoints npt-nEnd,nEnd, q_fb,i_fb,s_fb |
---|
459 | |
---|
460 | npt = numpnts(q_ft) |
---|
461 | DeletePoints npt-nEnd,nEnd, q_ft,i_ft,s_ft |
---|
462 | |
---|
463 | npt = numpnts(q_fl) |
---|
464 | DeletePoints npt-nEnd,nEnd, q_fl,i_fl,s_fl |
---|
465 | |
---|
466 | npt = numpnts(q_fr) |
---|
467 | DeletePoints npt-nEnd,nEnd, q_fr,i_fr,s_fr |
---|
468 | |
---|
469 | npt = numpnts(q_mb) |
---|
470 | DeletePoints npt-nEnd,nEnd, q_mb,i_mb,s_mb |
---|
471 | |
---|
472 | npt = numpnts(q_mt) |
---|
473 | DeletePoints npt-nEnd,nEnd, q_mt,i_mt,s_mt |
---|
474 | |
---|
475 | npt = numpnts(q_ml) |
---|
476 | DeletePoints npt-nEnd,nEnd, q_ml,i_ml,s_ml |
---|
477 | |
---|
478 | npt = numpnts(q_mr) |
---|
479 | DeletePoints npt-nEnd,nEnd, q_mr,i_mr,s_mr |
---|
480 | |
---|
481 | npt = numpnts(q_b) |
---|
482 | DeletePoints npt-nEnd,nEnd, q_b,i_b,s_b |
---|
483 | |
---|
484 | endif |
---|
485 | |
---|
486 | if(binType == 2) |
---|
487 | Wave/Z q_ftb = qBin_qxqy_FTB |
---|
488 | Wave/Z q_flr = qBin_qxqy_FLR |
---|
489 | Wave/Z q_mtb = qBin_qxqy_MTB |
---|
490 | Wave/Z q_mlr = qBin_qxqy_MLR |
---|
491 | Wave/Z q_b = qBin_qxqy_B |
---|
492 | |
---|
493 | Wave/Z i_ftb = iBin_qxqy_FTB |
---|
494 | Wave/Z i_flr = iBin_qxqy_FLR |
---|
495 | Wave/Z i_mtb = iBin_qxqy_MTB |
---|
496 | Wave/Z i_mlr = iBin_qxqy_MLR |
---|
497 | Wave/Z i_b = iBin_qxqy_B |
---|
498 | |
---|
499 | Wave/Z s_ftb = eBin_qxqy_FTB |
---|
500 | Wave/Z s_flr = eBin_qxqy_FLR |
---|
501 | Wave/Z s_mtb = eBin_qxqy_MTB |
---|
502 | Wave/Z s_mlr = eBin_qxqy_MLR |
---|
503 | Wave/Z s_b = eBin_qxqy_B |
---|
504 | |
---|
505 | |
---|
506 | DeletePoints 0,nBeg, q_ftb,q_flr,q_mtb,q_mlr,q_b |
---|
507 | DeletePoints 0,nBeg, i_ftb,i_flr,i_mtb,i_mlr,i_b |
---|
508 | DeletePoints 0,nBeg, s_ftb,s_flr,s_mtb,s_mlr,s_b |
---|
509 | //since each set may have a different number of points |
---|
510 | npt = numpnts(q_ftb) |
---|
511 | DeletePoints npt-nEnd,nEnd, q_ftb,i_ftb,s_ftb |
---|
512 | |
---|
513 | npt = numpnts(q_flr) |
---|
514 | DeletePoints npt-nEnd,nEnd, q_flr,i_flr,s_flr |
---|
515 | |
---|
516 | npt = numpnts(q_mtb) |
---|
517 | DeletePoints npt-nEnd,nEnd, q_mtb,i_mtb,s_mtb |
---|
518 | |
---|
519 | npt = numpnts(q_mlr) |
---|
520 | DeletePoints npt-nEnd,nEnd, q_mlr,i_mlr,s_mlr |
---|
521 | |
---|
522 | npt = numpnts(q_b) |
---|
523 | DeletePoints npt-nEnd,nEnd, q_b,i_b,s_b |
---|
524 | |
---|
525 | |
---|
526 | endif |
---|
527 | |
---|
528 | if(binType == 3) |
---|
529 | Wave/Z q_flrtb = qBin_qxqy_FLRTB |
---|
530 | Wave/Z q_mlrtb = qBin_qxqy_MLRTB |
---|
531 | Wave/Z q_b = qBin_qxqy_B |
---|
532 | |
---|
533 | Wave/Z i_flrtb = iBin_qxqy_FLRTB |
---|
534 | Wave/Z i_mlrtb = iBin_qxqy_MLRTB |
---|
535 | Wave/Z i_b = iBin_qxqy_B |
---|
536 | |
---|
537 | Wave/Z s_flrtb = eBin_qxqy_FLRTB |
---|
538 | Wave/Z s_mlrtb = eBin_qxqy_MLRTB |
---|
539 | Wave/Z s_b = eBin_qxqy_B |
---|
540 | |
---|
541 | DeletePoints 0,nBeg, q_flrtb,q_mlrtb,q_b |
---|
542 | DeletePoints 0,nBeg, i_flrtb,i_mlrtb,i_b |
---|
543 | DeletePoints 0,nBeg, s_flrtb,s_mlrtb,s_b |
---|
544 | //since each set may have a different number of points |
---|
545 | npt = numpnts(q_flrtb) |
---|
546 | DeletePoints npt-nEnd,nEnd, q_flrtb,i_flrtb,s_flrtb |
---|
547 | |
---|
548 | npt = numpnts(q_mlrtb) |
---|
549 | DeletePoints npt-nEnd,nEnd, q_mlrtb,i_mlrtb,s_mlrtb |
---|
550 | |
---|
551 | npt = numpnts(q_b) |
---|
552 | DeletePoints npt-nEnd,nEnd, q_b,i_b,s_b |
---|
553 | |
---|
554 | endif |
---|
555 | |
---|
556 | // TODO - This is the identical set of waves as for the case of binType = 1. |
---|
557 | // they have the same names, but are averaged differently since it's slit mode. |
---|
558 | // I have separated this, since in practice the TB panels are probably best to ignore |
---|
559 | // and NOT include in the averaging since the Qy range is so limited. |
---|
560 | if(binType == 4) |
---|
561 | Wave/Z q_fb = qBin_qxqy_FB |
---|
562 | Wave/Z q_ft = qBin_qxqy_FT |
---|
563 | Wave/Z q_fl = qBin_qxqy_FL |
---|
564 | Wave/Z q_fr = qBin_qxqy_FR |
---|
565 | Wave/Z q_mb = qBin_qxqy_MB |
---|
566 | Wave/Z q_mt = qBin_qxqy_MT |
---|
567 | Wave/Z q_ml = qBin_qxqy_ML |
---|
568 | Wave/Z q_mr = qBin_qxqy_MR |
---|
569 | Wave/Z q_b = qBin_qxqy_B |
---|
570 | |
---|
571 | Wave/Z i_fb = iBin_qxqy_FB |
---|
572 | Wave/Z i_ft = iBin_qxqy_FT |
---|
573 | Wave/Z i_fl = iBin_qxqy_FL |
---|
574 | Wave/Z i_fr = iBin_qxqy_FR |
---|
575 | Wave/Z i_mb = iBin_qxqy_MB |
---|
576 | Wave/Z i_mt = iBin_qxqy_MT |
---|
577 | Wave/Z i_ml = iBin_qxqy_ML |
---|
578 | Wave/Z i_mr = iBin_qxqy_MR |
---|
579 | Wave/Z i_b = iBin_qxqy_B |
---|
580 | |
---|
581 | Wave/Z s_fb = eBin_qxqy_FB |
---|
582 | Wave/Z s_ft = eBin_qxqy_FT |
---|
583 | Wave/Z s_fl = eBin_qxqy_FL |
---|
584 | Wave/Z s_fr = eBin_qxqy_FR |
---|
585 | Wave/Z s_mb = eBin_qxqy_MB |
---|
586 | Wave/Z s_mt = eBin_qxqy_MT |
---|
587 | Wave/Z s_ml = eBin_qxqy_ML |
---|
588 | Wave/Z s_mr = eBin_qxqy_MR |
---|
589 | Wave/Z s_b = eBin_qxqy_B |
---|
590 | |
---|
591 | DeletePoints 0,nBeg, q_fb,q_ft,q_fl,q_fr,q_mb,q_mt,q_ml,q_mr,q_b |
---|
592 | DeletePoints 0,nBeg, i_fb,i_ft,i_fl,i_fr,i_mb,i_mt,i_ml,i_mr,i_b |
---|
593 | DeletePoints 0,nBeg, s_fb,s_ft,s_fl,s_fr,s_mb,s_mt,s_ml,s_mr,s_b |
---|
594 | //since each set may have a different number of points |
---|
595 | npt = numpnts(q_fb) |
---|
596 | DeletePoints npt-nEnd,nEnd, q_fb,i_fb,s_fb |
---|
597 | |
---|
598 | npt = numpnts(q_ft) |
---|
599 | DeletePoints npt-nEnd,nEnd, q_ft,i_ft,s_ft |
---|
600 | |
---|
601 | npt = numpnts(q_fl) |
---|
602 | DeletePoints npt-nEnd,nEnd, q_fl,i_fl,s_fl |
---|
603 | |
---|
604 | npt = numpnts(q_fr) |
---|
605 | DeletePoints npt-nEnd,nEnd, q_fr,i_fr,s_fr |
---|
606 | |
---|
607 | npt = numpnts(q_mb) |
---|
608 | DeletePoints npt-nEnd,nEnd, q_mb,i_mb,s_mb |
---|
609 | |
---|
610 | npt = numpnts(q_mt) |
---|
611 | DeletePoints npt-nEnd,nEnd, q_mt,i_mt,s_mt |
---|
612 | |
---|
613 | npt = numpnts(q_ml) |
---|
614 | DeletePoints npt-nEnd,nEnd, q_ml,i_ml,s_ml |
---|
615 | |
---|
616 | npt = numpnts(q_mr) |
---|
617 | DeletePoints npt-nEnd,nEnd, q_mr,i_mr,s_mr |
---|
618 | |
---|
619 | npt = numpnts(q_b) |
---|
620 | DeletePoints npt-nEnd,nEnd, q_b,i_b,s_b |
---|
621 | |
---|
622 | endif |
---|
623 | |
---|
624 | SetDataFolder root: |
---|
625 | return(0) |
---|
626 | end |
---|
627 | |
---|
628 | |
---|
629 | |
---|
630 | // TODO: |
---|
631 | // -- this is a temporary solution before a real writer is created |
---|
632 | // -- resolution is not generated here (and it shouldn't be) since resolution is not known yet. |
---|
633 | // -- but a real writer will need to be aware of resolution, and there may be different forms |
---|
634 | // |
---|
635 | // this will bypass save dialogs |
---|
636 | // -- AND WILL OVERWITE DATA WITH THE SAME NAME |
---|
637 | // |
---|
638 | Function V_Write1DData(folderStr,saveName) |
---|
639 | String folderStr,saveName |
---|
640 | |
---|
641 | String formatStr="",fullpath="" |
---|
642 | Variable refnum,dialog=1 |
---|
643 | |
---|
644 | SetDataFolder $("root:Packages:NIST:VSANS:"+folderStr) |
---|
645 | |
---|
646 | Wave qw = tmp_q |
---|
647 | Wave iw = tmp_i |
---|
648 | Wave sw = tmp_s |
---|
649 | |
---|
650 | String dataSetFolderParent,basestr |
---|
651 | |
---|
652 | // ParseFilePath to get path without folder name |
---|
653 | // dataSetFolderParent = ParseFilePath(1,folderStr,":",1,0) |
---|
654 | // ParseFilePath to get basestr |
---|
655 | // basestr = ParseFilePath(0,folderStr,":",1,0) |
---|
656 | |
---|
657 | //make sure the waves exist |
---|
658 | |
---|
659 | if(WaveExists(qw) == 0) |
---|
660 | Abort "q is missing" |
---|
661 | endif |
---|
662 | if(WaveExists(iw) == 0) |
---|
663 | Abort "i is missing" |
---|
664 | endif |
---|
665 | if(WaveExists(sw) == 0) |
---|
666 | Abort "s is missing" |
---|
667 | endif |
---|
668 | // if(WaveExists(resw) == 0) |
---|
669 | // Abort "Resolution information is missing." |
---|
670 | // endif |
---|
671 | |
---|
672 | // Duplicate/O qw qbar,sigQ,fs |
---|
673 | // if(dimsize(resW,1) > 4) |
---|
674 | // //it's USANS put -dQv back in the last 3 columns |
---|
675 | // NVAR/Z dQv = USANS_dQv |
---|
676 | // if(NVAR_Exists(dQv) == 0) |
---|
677 | // SetDataFolder root: |
---|
678 | // Abort "It's USANS data, and I don't know what the slit height is." |
---|
679 | // endif |
---|
680 | // sigQ = -dQv |
---|
681 | // qbar = -dQv |
---|
682 | // fs = -dQv |
---|
683 | // else |
---|
684 | // //it's SANS |
---|
685 | // sigQ = resw[p][0] |
---|
686 | // qbar = resw[p][1] |
---|
687 | // fs = resw[p][2] |
---|
688 | // endif |
---|
689 | // |
---|
690 | |
---|
691 | PathInfo catPathName |
---|
692 | fullPath = S_Path + saveName |
---|
693 | |
---|
694 | Open refnum as fullpath |
---|
695 | |
---|
696 | fprintf refnum,"Combined data written from folder %s on %s\r\n",folderStr,(date()+" "+time()) |
---|
697 | |
---|
698 | // TODO -- make this work for 6-columns |
---|
699 | // formatStr = "%15.4g %15.4g %15.4g %15.4g %15.4g %15.4g\r\n" |
---|
700 | // fprintf refnum, "The 6 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm) | sigmaQ | meanQ | ShadowFactor|\r\n" |
---|
701 | // wfprintf refnum,formatStr,qw,iw,sw,sigQ,qbar,fs |
---|
702 | |
---|
703 | //currently, only three columns |
---|
704 | formatStr = "%15.4g %15.4g %15.4g\r\n" |
---|
705 | fprintf refnum, "The 3 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm)\r\n" |
---|
706 | |
---|
707 | wfprintf refnum,formatStr,qw,iw,sw |
---|
708 | Close refnum |
---|
709 | |
---|
710 | // KillWaves/Z sigQ,qbar,fs |
---|
711 | |
---|
712 | SetDataFolder root: |
---|
713 | return(0) |
---|
714 | End |
---|
715 | |
---|
716 | |
---|
717 | |
---|
718 | // TODO: |
---|
719 | // -- this is a temporary solution before a real writer is created |
---|
720 | // -- resolution is not generated here (and it shouldn't be) since resolution is not known yet. |
---|
721 | // -- but a real writer will need to be aware of resolution, and there may be different forms |
---|
722 | // |
---|
723 | // this will bypass save dialogs |
---|
724 | // -- AND WILL OVERWITE DATA WITH THE SAME NAME |
---|
725 | // |
---|
726 | Function V_Write1DData_NoConcat(folderStr,saveName,binType) |
---|
727 | String folderStr,saveName |
---|
728 | Variable binType |
---|
729 | |
---|
730 | String formatStr="",fullpath="" |
---|
731 | Variable refnum,dialog=1 |
---|
732 | |
---|
733 | SetDataFolder $("root:Packages:NIST:VSANS:"+folderStr) |
---|
734 | |
---|
735 | |
---|
736 | //TODO |
---|
737 | //-- make sure the waves exist |
---|
738 | |
---|
739 | // if(WaveExists(qw) == 0) |
---|
740 | // Abort "q is missing" |
---|
741 | // endif |
---|
742 | // if(WaveExists(iw) == 0) |
---|
743 | // Abort "i is missing" |
---|
744 | // endif |
---|
745 | // if(WaveExists(sw) == 0) |
---|
746 | // Abort "s is missing" |
---|
747 | // endif |
---|
748 | // if(WaveExists(resw) == 0) |
---|
749 | // Abort "Resolution information is missing." |
---|
750 | // endif |
---|
751 | |
---|
752 | // Duplicate/O qw qbar,sigQ,fs |
---|
753 | // if(dimsize(resW,1) > 4) |
---|
754 | // //it's USANS put -dQv back in the last 3 columns |
---|
755 | // NVAR/Z dQv = USANS_dQv |
---|
756 | // if(NVAR_Exists(dQv) == 0) |
---|
757 | // SetDataFolder root: |
---|
758 | // Abort "It's USANS data, and I don't know what the slit height is." |
---|
759 | // endif |
---|
760 | // sigQ = -dQv |
---|
761 | // qbar = -dQv |
---|
762 | // fs = -dQv |
---|
763 | // else |
---|
764 | // //it's SANS |
---|
765 | // sigQ = resw[p][0] |
---|
766 | // qbar = resw[p][1] |
---|
767 | // fs = resw[p][2] |
---|
768 | // endif |
---|
769 | // |
---|
770 | |
---|
771 | |
---|
772 | |
---|
773 | // TODO: |
---|
774 | // -- currently I'm using the Save comand and the /B flag |
---|
775 | // to save the data as Igor Text format, since otherwise the command string would be |
---|
776 | // too long. Need to come up with an Igor-demo friendly save here |
---|
777 | // |
---|
778 | // -- need a reader/plotter capable of handling this data. The regular data loader won't handle |
---|
779 | // all the different number of columns present, or the ITX format. See V_DataPlotting and duplicate these routines |
---|
780 | // Most of these routines take "winNameStr" as an argument, so I may be able to use them |
---|
781 | // |
---|
782 | // -- do I want to add the /O flag to force an overwrite if there is a name conflict? |
---|
783 | |
---|
784 | PathInfo catPathName |
---|
785 | fullPath = S_Path + saveName + ".itx" |
---|
786 | |
---|
787 | // Open refnum as fullpath |
---|
788 | // fprintf refnum,"Individual data sets written from folder %s on %s\r\n",folderStr,(date()+" "+time()) |
---|
789 | |
---|
790 | String waveStr="" |
---|
791 | // can be a multiple number of columns |
---|
792 | |
---|
793 | switch(binType) |
---|
794 | case 1: // 9 sets = 27 waves! |
---|
795 | waveStr = "qBin_qxqy_B;iBin_qxqy_B;eBin_qxqy_B;" |
---|
796 | waveStr += "qBin_qxqy_ML;iBin_qxqy_ML;eBin_qxqy_ML;" |
---|
797 | waveStr += "qBin_qxqy_MR;iBin_qxqy_MR;eBin_qxqy_MR;" |
---|
798 | waveStr += "qBin_qxqy_MT;iBin_qxqy_MT;eBin_qxqy_MT;" |
---|
799 | waveStr += "qBin_qxqy_MB;iBin_qxqy_MB;eBin_qxqy_MB;" |
---|
800 | waveStr += "qBin_qxqy_FL;iBin_qxqy_FL;eBin_qxqy_FL;" |
---|
801 | waveStr += "qBin_qxqy_FR;iBin_qxqy_FR;eBin_qxqy_FR;" |
---|
802 | waveStr += "qBin_qxqy_FT;iBin_qxqy_FT;eBin_qxqy_FT;" |
---|
803 | waveStr += "qBin_qxqy_FB;iBin_qxqy_FB;eBin_qxqy_FB;" |
---|
804 | |
---|
805 | |
---|
806 | Save/T/M="\r\n"/B waveStr as fullPath |
---|
807 | |
---|
808 | |
---|
809 | // formatStr = "%15.4g %15.4g %15.4g\r\n" |
---|
810 | // |
---|
811 | // fprintf refnum, "The 3 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm)\r\n" |
---|
812 | // |
---|
813 | // wfprintf refnum,formatStr,qw,iw,sw |
---|
814 | break |
---|
815 | case 2: // 5 sets |
---|
816 | |
---|
817 | waveStr = "qBin_qxqy_B;iBin_qxqy_B;eBin_qxqy_B;" |
---|
818 | waveStr += "qBin_qxqy_MLR;iBin_qxqy_MLR;eBin_qxqy_MLR;qBin_qxqy_MTB;iBin_qxqy_MTB;eBin_qxqy_MTB;" |
---|
819 | waveStr += "qBin_qxqy_FLR;iBin_qxqy_FLR;eBin_qxqy_FLR;qBin_qxqy_FTB;iBin_qxqy_FTB;eBin_qxqy_FTB;" |
---|
820 | |
---|
821 | Save/T/M="\r\n"/B waveStr as fullPath |
---|
822 | |
---|
823 | // formatStr = "%15.4g %15.4g %15.4g\r\n" |
---|
824 | // |
---|
825 | // fprintf refnum, "The 3 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm)\r\n" |
---|
826 | // |
---|
827 | // wfprintf refnum,formatStr,qw,iw,sw |
---|
828 | break |
---|
829 | case 3: // 3 sets |
---|
830 | // WAVE q1 = qBin_qxqy_B |
---|
831 | // WAVE i1 = iBin_qxqy_B |
---|
832 | // WAVE s1 = eBin_qxqy_B |
---|
833 | // WAVE q2 = qBin_qxqy_MLRTB |
---|
834 | // WAVE i2 = iBin_qxqy_MLRTB |
---|
835 | // WAVE s2 = eBin_qxqy_MLRTB |
---|
836 | // WAVE q3 = qBin_qxqy_FLRTB |
---|
837 | // WAVE i3 = iBin_qxqy_FLRTB |
---|
838 | // WAVE s3 = eBin_qxqy_FLRTB |
---|
839 | // |
---|
840 | // |
---|
841 | // Save/T/M="\r\n" q1,i1,s1,q2,i2,s2,q3,i3,s3 as fullPath |
---|
842 | |
---|
843 | waveStr = "qBin_qxqy_B;iBin_qxqy_B;eBin_qxqy_B;" |
---|
844 | waveStr += "qBin_qxqy_MLRTB;iBin_qxqy_MLRTB;eBin_qxqy_MLRTB;qBin_qxqy_FLRTB;iBin_qxqy_FLRTB;eBin_qxqy_FLRTB;" |
---|
845 | |
---|
846 | Save/T/M="\r\n"/B waveStr as fullPath |
---|
847 | |
---|
848 | |
---|
849 | // formatStr = "%15.4g %15.4g %15.4g\r\n" |
---|
850 | // |
---|
851 | // fprintf refnum, "The 3 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm)\r\n" |
---|
852 | // |
---|
853 | // wfprintf refnum,formatStr,qw,iw,sw |
---|
854 | break |
---|
855 | case 4: // 9 sets |
---|
856 | waveStr = "qBin_qxqy_B;iBin_qxqy_B;eBin_qxqy_B;" |
---|
857 | waveStr += "qBin_qxqy_ML;iBin_qxqy_ML;eBin_qxqy_ML;" |
---|
858 | waveStr += "qBin_qxqy_MR;iBin_qxqy_MR;eBin_qxqy_MR;" |
---|
859 | waveStr += "qBin_qxqy_MT;iBin_qxqy_MT;eBin_qxqy_MT;" |
---|
860 | waveStr += "qBin_qxqy_MB;iBin_qxqy_MB;eBin_qxqy_MB;" |
---|
861 | waveStr += "qBin_qxqy_FL;iBin_qxqy_FL;eBin_qxqy_FL;" |
---|
862 | waveStr += "qBin_qxqy_FR;iBin_qxqy_FR;eBin_qxqy_FR;" |
---|
863 | waveStr += "qBin_qxqy_FT;iBin_qxqy_FT;eBin_qxqy_FT;" |
---|
864 | waveStr += "qBin_qxqy_FB;iBin_qxqy_FB;eBin_qxqy_FB;" |
---|
865 | |
---|
866 | |
---|
867 | Save/T/M="\r\n"/B waveStr as fullPath |
---|
868 | |
---|
869 | // formatStr = "%15.4g %15.4g %15.4g\r\n" |
---|
870 | // |
---|
871 | // fprintf refnum, "The 3 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm)\r\n" |
---|
872 | // |
---|
873 | // wfprintf refnum,formatStr,qw,iw,sw |
---|
874 | break |
---|
875 | |
---|
876 | default: |
---|
877 | // do nothing, just close |
---|
878 | |
---|
879 | endswitch |
---|
880 | |
---|
881 | // Close refnum |
---|
882 | |
---|
883 | // TODO |
---|
884 | // -- clean up any waves on exit? Only if I generate extra waves |
---|
885 | // KillWaves/Z sigQ,qbar,fs |
---|
886 | |
---|
887 | SetDataFolder root: |
---|
888 | return(0) |
---|
889 | End |
---|