source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_IQ_Utilities.ipf @ 1044

Last change on this file since 1044 was 1044, checked in by srkline, 5 years ago

Significant changes to the base READ of individual data fields from data files. Now, if the field requested is from a WORK file, and it does not exist, an error condition is returned (or a null wave). Calling procedures are responsible for handling errors. This prevents a string of open file dialogs if fields are missing from a file if they were never in the file to begin with (like sensor logs, polarization hardware, etc.)

New get/write calls were added for the updated temperature sensor fields.

group_ID is now only in the sample block, not the duplicated in the reduction block, and is correctly a number not a string.

File size: 34.8 KB
Line 
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
36Strconstant ksPanelBinTypeList = "B;FT;FB;FL;FR;MT;MB;ML;MR;FTB;FLR;MTB;MLR;FLRTB;MLRTB;"
37Strconstant ksBinTrimBegDefault = "B=5;FT=6;FB=6;FL=6;FR=6;MT=6;MB=6;ML=6;MR=6;FTB=7;FLR=7;MTB=7;MLR=7;FLRTB=8;MLRTB=8;"
38Strconstant ksBinTrimEndDefault = "B=10;FT=9;FB=9;FL=9;FR=9;MT=9;MB=9;ML=9;MR=9;FTB=8;FLR=8;MTB=8;MLR=8;FLRTB=7;MLRTB=7;"
39
40
41//////////////////
42Strconstant ksBinTypeStr = "One;Two;Four;Slit Mode;"
43Strconstant ksBinType1 = "B;FT;FB;FL;FR;MT;MB;ML;MR;"           //these are the "active" extensions
44Strconstant ksBinType2 = "B;FTB;FLR;MTB;MLR;"
45Strconstant ksBinType3 = "B;FLRTB;MLRTB;"
46Strconstant ksBinType4 = "B;FT;FB;FL;FR;MT;MB;ML;MR;"
47///////////////////
48//
49// NOTE
50// this is the master conversion function
51// ***Use no others
52// *** When other bin types are developed, DO NOT reassign these numbers.
53//  instead, skip the old numbers and assign new ones.
54// old modes can be removed from the string constant ksBinTypeStr (above), but the
55// mode numbers are what many different binning, plotting, and reduction functions are
56// switching on. In the future, it may be necessary to change the key (everywhere) to a string
57// switch, but for now, stick with the numbers.
58Function V_BinTypeStr2Num(binStr)
59        String binStr
60       
61        Variable binType
62        strswitch(binStr)       // string switch
63                case "One":
64                        binType = 1
65                        break           // exit from switch
66                case "Two":
67                        binType = 2
68                        break           // exit from switch
69                case "Four":
70                        binType = 3
71                        break           // exit from switch
72                case "Slit Mode":
73                        binType = 4
74                        break           // exit from switch
75
76                default:                        // optional default expression executed
77                        binType = 0
78                        Abort "Binning mode not found"// when no case matches
79        endswitch       
80        return(binType)
81end
82
83//
84// TODO -- binType == 4 (slit mode) should never end up here
85// -- new logic in calling routines to dispatch to proper routine
86// -- AND need to write the routine for binning_SlitMode
87//
88Function V_QBinAllPanels_Circular(folderStr,binType)
89        String folderStr
90        Variable binType
91
92        // do the back, middle, and front separately
93       
94//      figure out the binning type (where is it set?)
95        Variable ii,delQ
96        String detStr
97
98//      binType = V_GetBinningPopMode()
99
100//// TODO:
101//
102//      Back detector is handled spearately since there is nothing to combine
103//
104        delQ = SetDeltaQ(folderStr,"B")
105       
106        // dispatch based on binning type
107        if(binType == 1 || binType == 2 || binType == 3)
108                VC_fDoBinning_QxQy2D(folderStr, "B")            //normal binning, nothing to combine
109        endif
110
111// TODO -- this is only a temporary fix for slit mode   
112        if(binType == 4)
113                /// this is for a tall, narrow slit mode       
114                VC_fBinDetector_byRows(folderStr,"B")
115        endif   
116
117
118
119// these are the binning types where detectors are not combined
120// other combined binning is below the loop
121        for(ii=0;ii<ItemsInList(ksDetectorListNoB);ii+=1)
122                detStr = StringFromList(ii, ksDetectorListNoB, ";")
123               
124                // set delta Q for binning
125                delQ = SetDeltaQ(folderStr,detStr)
126               
127                // dispatch based on binning type
128                if(binType==1)
129                        VC_fDoBinning_QxQy2D(folderStr,detStr)
130                endif
131               
132                // TODO -- this is only a temporary fix for slit mode   
133                if(binType == 4)
134                        /// this is for a tall, narrow slit mode       
135                        VC_fBinDetector_byRows(folderStr,detStr)
136                endif   
137               
138        endfor
139       
140        // bin in pairs
141        if(binType == 2)
142                VC_fDoBinning_QxQy2D(folderStr,"MLR")
143                VC_fDoBinning_QxQy2D(folderStr,"MTB")
144                VC_fDoBinning_QxQy2D(folderStr,"FLR")
145                VC_fDoBinning_QxQy2D(folderStr,"FTB")   
146        endif
147       
148        // bin everything on front or middle together
149        if(binType == 3)
150                VC_fDoBinning_QxQy2D(folderStr,"MLRTB")
151                VC_fDoBinning_QxQy2D(folderStr,"FLRTB")
152        endif
153
154        return(0)
155End
156
157// concatenates and sorts the 1D data in "type" WORK folder
158// uses the current display if type==""
159//
160Function V_ConcatenateForSave(pathStr,type,tagStr,binType)
161        String pathStr,type,tagStr
162        Variable binType
163       
164// get the current display type, if null string passed in
165        SVAR curtype = root:Packages:NIST:VSANS:Globals:gCurDispType
166       
167        if(strlen(type)==0)
168                type = curType
169        endif
170
171// trim the data if needed
172        // remove the q=0 point from the back detector, if it's there
173        // does not need to know binType
174        V_RemoveQ0_B(type)
175
176// concatenate the data sets
177// TODO x- figure out which binning was used (this is done in V_1DConcatenate())
178        // clear the old tmp waves first, if they still exist
179//      SetDataFolder $("root:Packages:NIST:VSANS:"+type)
180        SetDataFolder $(pathStr+type)
181        Killwaves/Z tmp_q,tmp_i,tmp_s
182        setDataFolder root:
183        V_1DConcatenate(pathStr,type,tagStr,binType)
184       
185// sort the data set
186        V_TmpSort1D(pathStr,type)
187       
188        return(0)
189End
190
191//
192// this is only called from the button on the data panel
193// so the type is the currently displayed type, and the binning is from the panel
194//
195Function V_SimpleSave1DData(pathStr,type,tagStr,saveName)
196        String pathStr,type,tagStr,saveName
197
198//
199// get the current display type, if null string passed in
200        SVAR curtype = root:Packages:NIST:VSANS:Globals:gCurDispType
201        Variable binType = V_GetBinningPopMode()
202       
203        V_ConcatenateForSave(pathStr,curType,tagStr,binType)
204       
205// write out the data set to a file
206        if(strlen(saveName)==0)
207                Execute "V_GetNameForSave()"
208                SVAR newName = root:saveName
209                saveName = newName
210        endif
211       
212        V_Write1DData(pathStr,curtype,saveName)
213
214End
215
216
217Proc V_GetNameForSave(str)
218        String str
219        String/G root:saveName=str
220End
221
222
223// blindly assumes that there is only one zero at the top of the wave
224// could be more sophisticated in the future...
225Function V_RemoveQ0_B(type)
226        String type
227       
228        SetDataFolder $("root:Packages:NIST:VSANS:"+type)
229
230        WAVE/Z qBin = qBin_qxqy_B
231        WAVE/Z iBin = iBin_qxqy_B
232        WAVE/Z eBin = eBin_qxqy_B
233        WAVE/Z nBin = nBin_qxqy_B
234        WAVE/Z iBin2 = iBin2_qxqy_B
235
236        if(qBin[0] == 0)
237                DeletePoints 0, 1, qBin,iBin,eBin,nBin,iBin2
238        endif
239       
240        SetDataFolder root:
241        return(0)
242end
243
244
245// concatentate data in folderStr
246//
247// TODO:
248// x- this currently ignores the binning type (one, two, etc. )
249// x- change the Concatenate call to use the waveList, to eliminate the need to declare all of the waves
250// -- this currently assumes that all of the waves exist
251// -- need robust error checking for wave existence
252// -- wave names are hard-wired and their name and location may be different in the future
253// x- if different averaging options were chosen (bin type of 2, 4 etc) then
254//    although waves may exist, they may not be the right ones to use. There
255//    will be a somewhat complex selection process
256// x- detector B is currently skipped
257//
258// this seems like a lot of extra work to do something so simple...but it's better than a loop
259//
260//  root:Packages:NIST:VSANS:RAW:iBin_qxqy_FB
261//
262// binType = 1 = one
263// binType = 2 = two
264// binType = 3 = four
265// binType = 4 = Slit Mode
266//
267// if binType is passed in as -9999, get the binning mode from the popup
268// otherwise the value is assumed good (from a protocol)
269//
270// pathStr must have the trailing colon
271// tagStr is normally null, but is "_trim" for data to be trimmed
272//
273Function V_1DConcatenate(pathStr,folderStr,tagStr,binType)
274        String pathStr,folderStr,tagStr
275        Variable binType
276       
277        if(binType==-9999)
278                binType = V_GetBinningPopMode()
279        endif   
280       
281//      SetDataFolder $("root:Packages:NIST:VSANS:"+folderStr)
282        SetDataFolder $(pathStr+folderStr)
283
284        //kill these waves before starting, or the new concatenation will be added to the old
285        KillWaves/Z tmp_q,tmp_i,tmp_s
286       
287        String waveListStr=""
288        if(binType == 1)
289                // q-values
290                waveListStr =  "qBin_qxqy_B" + tagStr + ";"
291                waveListStr += "qBin_qxqy_MB" + tagStr + ";"
292                waveListStr += "qBin_qxqy_MT" + tagStr + ";"
293                waveListStr += "qBin_qxqy_ML" + tagStr + ";"
294                waveListStr += "qBin_qxqy_MR" + tagStr + ";"
295                waveListStr += "qBin_qxqy_FB" + tagStr + ";"
296                waveListStr += "qBin_qxqy_FT" + tagStr + ";"
297                waveListStr += "qBin_qxqy_FL" + tagStr + ";"
298                waveListStr += "qBin_qxqy_FR" + tagStr + ";"
299
300                Concatenate/NP/O waveListStr, tmp_q
301
302                //intensity
303                waveListStr =  "iBin_qxqy_B" + tagStr + ";"
304                waveListStr += "iBin_qxqy_MB" + tagStr + ";"
305                waveListStr += "iBin_qxqy_MT" + tagStr + ";"
306                waveListStr += "iBin_qxqy_ML" + tagStr + ";"
307                waveListStr += "iBin_qxqy_MR" + tagStr + ";"
308                waveListStr += "iBin_qxqy_FB" + tagStr + ";"
309                waveListStr += "iBin_qxqy_FT" + tagStr + ";"
310                waveListStr += "iBin_qxqy_FL" + tagStr + ";"
311                waveListStr += "iBin_qxqy_FR" + tagStr + ";"
312//              waveListStr = "iBin_qxqy_B;iBin_qxqy_MB;iBin_qxqy_MT;iBin_qxqy_ML;iBin_qxqy_MR;"
313//              waveListStr += "iBin_qxqy_FB;iBin_qxqy_FT;iBin_qxqy_FL;iBin_qxqy_FR;"
314               
315                Concatenate/NP/O waveListStr, tmp_i
316
317                //error
318                waveListStr =  "eBin_qxqy_B" + tagStr + ";"
319                waveListStr += "eBin_qxqy_MB" + tagStr + ";"
320                waveListStr += "eBin_qxqy_MT" + tagStr + ";"
321                waveListStr += "eBin_qxqy_ML" + tagStr + ";"
322                waveListStr += "eBin_qxqy_MR" + tagStr + ";"
323                waveListStr += "eBin_qxqy_FB" + tagStr + ";"
324                waveListStr += "eBin_qxqy_FT" + tagStr + ";"
325                waveListStr += "eBin_qxqy_FL" + tagStr + ";"
326                waveListStr += "eBin_qxqy_FR" + tagStr + ";"
327//              waveListStr = "eBin_qxqy_B;eBin_qxqy_MB;eBin_qxqy_MT;eBin_qxqy_ML;eBin_qxqy_MR;"
328//              waveListStr += "eBin_qxqy_FB;eBin_qxqy_FT;eBin_qxqy_FL;eBin_qxqy_FR;"
329                       
330                Concatenate/NP/O waveListStr, tmp_s
331        endif
332
333        if(binType == 2)       
334                // q-values
335                waveListStr =  "qBin_qxqy_B" + tagStr + ";"
336                waveListStr += "qBin_qxqy_MTB" + tagStr + ";"
337                waveListStr += "qBin_qxqy_MLR" + tagStr + ";"
338                waveListStr += "qBin_qxqy_FTB" + tagStr + ";"
339                waveListStr += "qBin_qxqy_FLR" + tagStr + ";"
340
341//              waveListStr = "qBin_qxqy_B;qBin_qxqy_MTB;qBin_qxqy_MLR;"
342//              waveListStr += "qBin_qxqy_FTB;qBin_qxqy_FLR;"
343
344                Concatenate/NP/O waveListStr, tmp_q
345
346                //intensity
347                waveListStr =  "iBin_qxqy_B" + tagStr + ";"
348                waveListStr += "iBin_qxqy_MTB" + tagStr + ";"
349                waveListStr += "iBin_qxqy_MLR" + tagStr + ";"
350                waveListStr += "iBin_qxqy_FTB" + tagStr + ";"
351                waveListStr += "iBin_qxqy_FLR" + tagStr + ";"
352               
353//              waveListStr = "iBin_qxqy_B;iBin_qxqy_MTB;iBin_qxqy_MLR;"
354//              waveListStr += "iBin_qxqy_FTB;iBin_qxqy_FLR;"
355               
356                Concatenate/NP/O waveListStr, tmp_i
357
358                //error
359                waveListStr =  "eBin_qxqy_B" + tagStr + ";"
360                waveListStr += "eBin_qxqy_MTB" + tagStr + ";"
361                waveListStr += "eBin_qxqy_MLR" + tagStr + ";"
362                waveListStr += "eBin_qxqy_FTB" + tagStr + ";"
363                waveListStr += "eBin_qxqy_FLR" + tagStr + ";"
364               
365//              waveListStr = "eBin_qxqy_B;eBin_qxqy_MTB;eBin_qxqy_MLR;"
366//              waveListStr += "eBin_qxqy_FTB;eBin_qxqy_FLR;"
367                       
368                Concatenate/NP/O waveListStr, tmp_s
369        endif
370
371        if(binType == 3)       
372                // q-values
373                waveListStr =  "qBin_qxqy_B" + tagStr + ";"
374                waveListStr += "qBin_qxqy_MLRTB" + tagStr + ";"
375                waveListStr += "qBin_qxqy_FLRTB" + tagStr + ";"
376               
377//              waveListStr = "qBin_qxqy_B;qBin_qxqy_MLRTB;qBin_qxqy_FLRTB;"
378
379                Concatenate/NP/O waveListStr, tmp_q
380
381                //intensity
382                waveListStr =  "iBin_qxqy_B" + tagStr + ";"
383                waveListStr += "iBin_qxqy_MLRTB" + tagStr + ";"
384                waveListStr += "iBin_qxqy_FLRTB" + tagStr + ";"
385               
386//              waveListStr = "iBin_qxqy_B;iBin_qxqy_MLRTB;iBin_qxqy_FLRTB;"
387               
388                Concatenate/NP/O waveListStr, tmp_i
389
390                //error
391                waveListStr =  "eBin_qxqy_B" + tagStr + ";"
392                waveListStr += "eBin_qxqy_MLRTB" + tagStr + ";"
393                waveListStr += "eBin_qxqy_FLRTB" + tagStr + ";"
394               
395//              waveListStr = "eBin_qxqy_B;eBin_qxqy_MLRTB;eBin_qxqy_FLRTB;"
396                       
397                Concatenate/NP/O waveListStr, tmp_s
398        endif
399
400// TODO - This is the identical set of waves as for the case of binType = 1.
401// they have the same names, but are averaged differently since it's slit mode.
402// I have separated this, since in practice the TB panels are probably best to ignore
403// and NOT include in the averaging since the Qy range is so limited.
404        if(binType == 4)       
405                // q-values
406                waveListStr =  "qBin_qxqy_B" + tagStr + ";"
407                waveListStr += "qBin_qxqy_MB" + tagStr + ";"
408                waveListStr += "qBin_qxqy_MT" + tagStr + ";"
409                waveListStr += "qBin_qxqy_ML" + tagStr + ";"
410                waveListStr += "qBin_qxqy_MR" + tagStr + ";"
411                waveListStr += "qBin_qxqy_FB" + tagStr + ";"
412                waveListStr += "qBin_qxqy_FT" + tagStr + ";"
413                waveListStr += "qBin_qxqy_FL" + tagStr + ";"
414                waveListStr += "qBin_qxqy_FR" + tagStr + ";"
415//              waveListStr = "qBin_qxqy_B;qBin_qxqy_MB;qBin_qxqy_MT;qBin_qxqy_ML;qBin_qxqy_MR;"
416//              waveListStr += "qBin_qxqy_FB;qBin_qxqy_FT;qBin_qxqy_FL;qBin_qxqy_FR;"
417
418                Concatenate/NP/O waveListStr, tmp_q
419
420                //intensity
421                waveListStr =  "iBin_qxqy_B" + tagStr + ";"
422                waveListStr += "iBin_qxqy_MB" + tagStr + ";"
423                waveListStr += "iBin_qxqy_MT" + tagStr + ";"
424                waveListStr += "iBin_qxqy_ML" + tagStr + ";"
425                waveListStr += "iBin_qxqy_MR" + tagStr + ";"
426                waveListStr += "iBin_qxqy_FB" + tagStr + ";"
427                waveListStr += "iBin_qxqy_FT" + tagStr + ";"
428                waveListStr += "iBin_qxqy_FL" + tagStr + ";"
429                waveListStr += "iBin_qxqy_FR" + tagStr + ";"
430//              waveListStr = "iBin_qxqy_B;iBin_qxqy_MB;iBin_qxqy_MT;iBin_qxqy_ML;iBin_qxqy_MR;"
431//              waveListStr += "iBin_qxqy_FB;iBin_qxqy_FT;iBin_qxqy_FL;iBin_qxqy_FR;"
432               
433                Concatenate/NP/O waveListStr, tmp_i
434
435                //error
436                waveListStr =  "eBin_qxqy_B" + tagStr + ";"
437                waveListStr += "eBin_qxqy_MB" + tagStr + ";"
438                waveListStr += "eBin_qxqy_MT" + tagStr + ";"
439                waveListStr += "eBin_qxqy_ML" + tagStr + ";"
440                waveListStr += "eBin_qxqy_MR" + tagStr + ";"
441                waveListStr += "eBin_qxqy_FB" + tagStr + ";"
442                waveListStr += "eBin_qxqy_FT" + tagStr + ";"
443                waveListStr += "eBin_qxqy_FL" + tagStr + ";"
444                waveListStr += "eBin_qxqy_FR" + tagStr + ";"
445//              waveListStr = "eBin_qxqy_B;eBin_qxqy_MB;eBin_qxqy_MT;eBin_qxqy_ML;eBin_qxqy_MR;"
446//              waveListStr += "eBin_qxqy_FB;eBin_qxqy_FT;eBin_qxqy_FL;eBin_qxqy_FR;"
447                       
448                Concatenate/NP/O waveListStr, tmp_s
449        endif
450
451// Can't kill here, since they are still needed to sort and write out!
452//      KillWaves/Z tmp_q,tmp_i,tmp_s,tmp_res0,tmp_res1,tmp_res2,tmp_res3       
453       
454        SetDataFolder root:
455       
456        return(0)               
457End
458
459// TODO:
460// -- resolution waves are ignored, since they don't exist (yet)
461// -- only a sort is done, no rescaling of data sets
462//    (it's too late now anyways, since the data was concatenated)
463//
464// see Auto_Sort() in the SANS Automation ipf for the rest of the details of
465// how to combine the resolution waves (they also need to be concatenated, which is currently not done)
466//
467Function V_TmpSort1D(pathStr,folderStr)
468        String pathStr,folderStr
469       
470        SetDataFolder $(pathStr+folderStr)
471
472        Wave qw = tmp_q
473        Wave iw = tmp_i
474        Wave sw = tmp_s
475       
476//      Sort qw, qw,iw,sw,res0,res1,res2,res3
477
478        Sort qw, qw,iw,sw
479
480
481        SetDataFolder root:
482        return(0)
483End
484
485
486// TODO
487// (appears to be unused, in favor of the version that uses the global strings)
488// needs:
489// -- trim the beamstop out (based on shadow?)
490// -- trim out zero q from the file (bad actor in analysis functions)
491// -- trim num from the highQ end or lowQ end?
492// -- splits the res wave into individual waves in anticipation of concatenation
493//   -- or -- deal with the res wave after?
494//
495// -- make a copy of the waves?
496// -- then, what is the concatenate function looking for??
497//
498Function V_Trim1DData(dataFolder,binType,nBeg,nEnd)
499        String dataFolder
500        Variable binType,nBeg,nEnd
501
502        Variable npt,ii
503   SetDataFolder $("root:Packages:NIST:VSANS:"+dataFolder)
504
505        Printf "%d points removed from beginning, %d points from the end (of each set) before concatenating\r",nbeg,nend
506       
507// for each binType block:
508// declare the waves
509// make a copy of the waves??
510//      //Break out resolution wave into separate waves
511// delete the beginning points from everything
512        // trim off the last nEnd points from everything
513//      DeletePoints num-nEnd,nEnd, qw,iw,sw
514//      // delete all points where the shadow is < 0.98
515////Put resolution contents back???
516
517        if(binType == 1)       
518                Wave/Z q_fb = qBin_qxqy_FB
519                Wave/Z q_ft = qBin_qxqy_FT
520                Wave/Z q_fl = qBin_qxqy_FL
521                Wave/Z q_fr = qBin_qxqy_FR
522                Wave/Z q_mb = qBin_qxqy_MB
523                Wave/Z q_mt = qBin_qxqy_MT
524                Wave/Z q_ml = qBin_qxqy_ML
525                Wave/Z q_mr = qBin_qxqy_MR
526                Wave/Z q_b = qBin_qxqy_B
527       
528                Wave/Z i_fb = iBin_qxqy_FB
529                Wave/Z i_ft = iBin_qxqy_FT
530                Wave/Z i_fl = iBin_qxqy_FL
531                Wave/Z i_fr = iBin_qxqy_FR
532                Wave/Z i_mb = iBin_qxqy_MB
533                Wave/Z i_mt = iBin_qxqy_MT
534                Wave/Z i_ml = iBin_qxqy_ML
535                Wave/Z i_mr = iBin_qxqy_MR
536                Wave/Z i_b = iBin_qxqy_B
537               
538                Wave/Z s_fb = eBin_qxqy_FB
539                Wave/Z s_ft = eBin_qxqy_FT
540                Wave/Z s_fl = eBin_qxqy_FL
541                Wave/Z s_fr = eBin_qxqy_FR
542                Wave/Z s_mb = eBin_qxqy_MB
543                Wave/Z s_mt = eBin_qxqy_MT
544                Wave/Z s_ml = eBin_qxqy_ML
545                Wave/Z s_mr = eBin_qxqy_MR
546                Wave/Z s_b = eBin_qxqy_B
547
548
549                               
550                DeletePoints 0,nBeg, q_fb,q_ft,q_fl,q_fr,q_mb,q_mt,q_ml,q_mr,q_b
551                DeletePoints 0,nBeg, i_fb,i_ft,i_fl,i_fr,i_mb,i_mt,i_ml,i_mr,i_b
552                DeletePoints 0,nBeg, s_fb,s_ft,s_fl,s_fr,s_mb,s_mt,s_ml,s_mr,s_b
553                //since each set may have a different number of points
554                npt = numpnts(q_fb)
555                DeletePoints npt-nEnd,nEnd, q_fb,i_fb,s_fb
556
557                npt = numpnts(q_ft)
558                DeletePoints npt-nEnd,nEnd, q_ft,i_ft,s_ft
559
560                npt = numpnts(q_fl)
561                DeletePoints npt-nEnd,nEnd, q_fl,i_fl,s_fl
562
563                npt = numpnts(q_fr)
564                DeletePoints npt-nEnd,nEnd, q_fr,i_fr,s_fr
565
566                npt = numpnts(q_mb)
567                DeletePoints npt-nEnd,nEnd, q_mb,i_mb,s_mb
568
569                npt = numpnts(q_mt)
570                DeletePoints npt-nEnd,nEnd, q_mt,i_mt,s_mt
571
572                npt = numpnts(q_ml)
573                DeletePoints npt-nEnd,nEnd, q_ml,i_ml,s_ml
574
575                npt = numpnts(q_mr)
576                DeletePoints npt-nEnd,nEnd, q_mr,i_mr,s_mr
577
578                npt = numpnts(q_b)
579                DeletePoints npt-nEnd,nEnd, q_b,i_b,s_b
580               
581        endif
582
583        if(binType == 2)       
584                Wave/Z q_ftb = qBin_qxqy_FTB
585                Wave/Z q_flr = qBin_qxqy_FLR
586                Wave/Z q_mtb = qBin_qxqy_MTB
587                Wave/Z q_mlr = qBin_qxqy_MLR
588                Wave/Z q_b = qBin_qxqy_B
589               
590                Wave/Z i_ftb = iBin_qxqy_FTB
591                Wave/Z i_flr = iBin_qxqy_FLR
592                Wave/Z i_mtb = iBin_qxqy_MTB
593                Wave/Z i_mlr = iBin_qxqy_MLR
594                Wave/Z i_b = iBin_qxqy_B
595                               
596                Wave/Z s_ftb = eBin_qxqy_FTB
597                Wave/Z s_flr = eBin_qxqy_FLR
598                Wave/Z s_mtb = eBin_qxqy_MTB
599                Wave/Z s_mlr = eBin_qxqy_MLR
600                Wave/Z s_b = eBin_qxqy_B
601               
602
603                DeletePoints 0,nBeg, q_ftb,q_flr,q_mtb,q_mlr,q_b
604                DeletePoints 0,nBeg, i_ftb,i_flr,i_mtb,i_mlr,i_b
605                DeletePoints 0,nBeg, s_ftb,s_flr,s_mtb,s_mlr,s_b
606                //since each set may have a different number of points
607                npt = numpnts(q_ftb)
608                DeletePoints npt-nEnd,nEnd, q_ftb,i_ftb,s_ftb           
609               
610                npt = numpnts(q_flr)
611                DeletePoints npt-nEnd,nEnd, q_flr,i_flr,s_flr           
612               
613                npt = numpnts(q_mtb)
614                DeletePoints npt-nEnd,nEnd, q_mtb,i_mtb,s_mtb           
615               
616                npt = numpnts(q_mlr)
617                DeletePoints npt-nEnd,nEnd, q_mlr,i_mlr,s_mlr           
618               
619                npt = numpnts(q_b)
620                DeletePoints npt-nEnd,nEnd, q_b,i_b,s_b         
621               
622
623        endif
624
625        if(binType == 3)       
626                Wave/Z q_flrtb = qBin_qxqy_FLRTB
627                Wave/Z q_mlrtb = qBin_qxqy_MLRTB
628                Wave/Z q_b = qBin_qxqy_B
629               
630                Wave/Z i_flrtb = iBin_qxqy_FLRTB
631                Wave/Z i_mlrtb = iBin_qxqy_MLRTB
632                Wave/Z i_b = iBin_qxqy_B       
633               
634                Wave/Z s_flrtb = eBin_qxqy_FLRTB
635                Wave/Z s_mlrtb = eBin_qxqy_MLRTB
636                Wave/Z s_b = eBin_qxqy_B
637               
638                DeletePoints 0,nBeg, q_flrtb,q_mlrtb,q_b
639                DeletePoints 0,nBeg, i_flrtb,i_mlrtb,i_b
640                DeletePoints 0,nBeg, s_flrtb,s_mlrtb,s_b
641                //since each set may have a different number of points
642                npt = numpnts(q_flrtb)
643                DeletePoints npt-nEnd,nEnd, q_flrtb,i_flrtb,s_flrtb             
644               
645                npt = numpnts(q_mlrtb)
646                DeletePoints npt-nEnd,nEnd, q_mlrtb,i_mlrtb,s_mlrtb             
647               
648                npt = numpnts(q_b)
649                DeletePoints npt-nEnd,nEnd, q_b,i_b,s_b         
650
651        endif
652
653// TODO - This is the identical set of waves as for the case of binType = 1.
654// they have the same names, but are averaged differently since it's slit mode.
655// I have separated this, since in practice the TB panels are probably best to ignore
656// and NOT include in the averaging since the Qy range is so limited.
657        if(binType == 4)       
658                Wave/Z q_fb = qBin_qxqy_FB
659                Wave/Z q_ft = qBin_qxqy_FT
660                Wave/Z q_fl = qBin_qxqy_FL
661                Wave/Z q_fr = qBin_qxqy_FR
662                Wave/Z q_mb = qBin_qxqy_MB
663                Wave/Z q_mt = qBin_qxqy_MT
664                Wave/Z q_ml = qBin_qxqy_ML
665                Wave/Z q_mr = qBin_qxqy_MR
666                Wave/Z q_b = qBin_qxqy_B
667       
668                Wave/Z i_fb = iBin_qxqy_FB
669                Wave/Z i_ft = iBin_qxqy_FT
670                Wave/Z i_fl = iBin_qxqy_FL
671                Wave/Z i_fr = iBin_qxqy_FR
672                Wave/Z i_mb = iBin_qxqy_MB
673                Wave/Z i_mt = iBin_qxqy_MT
674                Wave/Z i_ml = iBin_qxqy_ML
675                Wave/Z i_mr = iBin_qxqy_MR
676                Wave/Z i_b = iBin_qxqy_B
677               
678                Wave/Z s_fb = eBin_qxqy_FB
679                Wave/Z s_ft = eBin_qxqy_FT
680                Wave/Z s_fl = eBin_qxqy_FL
681                Wave/Z s_fr = eBin_qxqy_FR
682                Wave/Z s_mb = eBin_qxqy_MB
683                Wave/Z s_mt = eBin_qxqy_MT
684                Wave/Z s_ml = eBin_qxqy_ML
685                Wave/Z s_mr = eBin_qxqy_MR
686                Wave/Z s_b = eBin_qxqy_B
687                               
688                DeletePoints 0,nBeg, q_fb,q_ft,q_fl,q_fr,q_mb,q_mt,q_ml,q_mr,q_b
689                DeletePoints 0,nBeg, i_fb,i_ft,i_fl,i_fr,i_mb,i_mt,i_ml,i_mr,i_b
690                DeletePoints 0,nBeg, s_fb,s_ft,s_fl,s_fr,s_mb,s_mt,s_ml,s_mr,s_b
691                //since each set may have a different number of points
692                npt = numpnts(q_fb)
693                DeletePoints npt-nEnd,nEnd, q_fb,i_fb,s_fb
694
695                npt = numpnts(q_ft)
696                DeletePoints npt-nEnd,nEnd, q_ft,i_ft,s_ft
697
698                npt = numpnts(q_fl)
699                DeletePoints npt-nEnd,nEnd, q_fl,i_fl,s_fl
700
701                npt = numpnts(q_fr)
702                DeletePoints npt-nEnd,nEnd, q_fr,i_fr,s_fr
703
704                npt = numpnts(q_mb)
705                DeletePoints npt-nEnd,nEnd, q_mb,i_mb,s_mb
706
707                npt = numpnts(q_mt)
708                DeletePoints npt-nEnd,nEnd, q_mt,i_mt,s_mt
709
710                npt = numpnts(q_ml)
711                DeletePoints npt-nEnd,nEnd, q_ml,i_ml,s_ml
712
713                npt = numpnts(q_mr)
714                DeletePoints npt-nEnd,nEnd, q_mr,i_mr,s_mr
715
716                npt = numpnts(q_b)
717                DeletePoints npt-nEnd,nEnd, q_b,i_b,s_b
718               
719        endif
720                       
721        SetDataFolder root:
722        return(0)
723end
724
725
726
727// TODO:
728// -- this is a temporary solution before a real writer is created
729// -- resolution is not generated here (and it shouldn't be) since resolution is not known yet.
730// -- but a real writer will need to be aware of resolution, and there may be different forms
731//
732// this will bypass save dialogs
733// -- AND WILL OVERWITE DATA WITH THE SAME NAME
734//
735Function V_Write1DData(pathStr,folderStr,saveName)
736        String pathStr,folderStr,saveName
737       
738        String formatStr="",fullpath=""
739        Variable refnum,dialog=1
740
741        SetDataFolder $(pathStr+folderStr)
742
743        Wave qw = tmp_q
744        Wave iw = tmp_i
745        Wave sw = tmp_s
746       
747        String dataSetFolderParent,basestr
748       
749        // ParseFilePath to get path without folder name
750//      dataSetFolderParent = ParseFilePath(1,folderStr,":",1,0)
751        // ParseFilePath to get basestr
752//      basestr = ParseFilePath(0,folderStr,":",1,0)
753       
754        //make sure the waves exist
755       
756        if(WaveExists(qw) == 0)
757                Abort "q is missing"
758        endif
759        if(WaveExists(iw) == 0)
760                Abort "i is missing"
761        endif
762        if(WaveExists(sw) == 0)
763                Abort "s is missing"
764        endif
765//      if(WaveExists(resw) == 0)
766//              Abort "Resolution information is missing."
767//      endif
768       
769//      Duplicate/O qw qbar,sigQ,fs
770//      if(dimsize(resW,1) > 4)
771//              //it's USANS put -dQv back in the last 3 columns
772//              NVAR/Z dQv = USANS_dQv
773//              if(NVAR_Exists(dQv) == 0)
774//                      SetDataFolder root:
775//                      Abort "It's USANS data, and I don't know what the slit height is."
776//              endif
777//              sigQ = -dQv
778//              qbar = -dQv
779//              fs = -dQv
780//      else
781//              //it's SANS
782//              sigQ = resw[p][0]
783//              qbar = resw[p][1]
784//              fs = resw[p][2]
785//      endif
786//     
787
788        PathInfo catPathName
789        fullPath = S_Path + saveName
790
791        Open refnum as fullpath
792
793        fprintf refnum,"Combined data written from folder %s on %s\r\n",folderStr,(date()+" "+time())
794
795// TODO -- make this work for 6-columns (or??)
796//      formatStr = "%15.4g %15.4g %15.4g %15.4g %15.4g %15.4g\r\n"     
797//      fprintf refnum, "The 6 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm) | sigmaQ | meanQ | ShadowFactor|\r\n"       
798//      wfprintf refnum,formatStr,qw,iw,sw,sigQ,qbar,fs
799
800        //currently, only three columns
801        formatStr = "%15.4g %15.4g %15.4g\r\n" 
802        fprintf refnum, "The 3 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm)\r\n"
803
804        wfprintf refnum,formatStr,qw,iw,sw
805        Close refnum
806       
807//      KillWaves/Z sigQ,qbar,fs
808        Print "Data written to: ",fullpath
809       
810        SetDataFolder root:
811        return(0)
812End
813
814
815
816// TODO:
817// -- this is a temporary solution before a real writer is created
818// -- resolution is not generated here (and it shouldn't be) since resolution is not known yet.
819// -- but a real writer will need to be aware of resolution, and there may be different forms
820//
821// This saves the data in Igor Text format, an ASCII format, but NOT standard SANS columns
822// No concatenation is done. This is meant to be used for input to TRIM, or for general troubleshooting
823//
824//
825// this will bypass save dialogs
826// -- AND WILL OVERWRITE DATA WITH THE SAME NAME
827//
828Function V_Write1DData_ITX(pathStr,folderStr,saveName,binType)
829        String pathStr,folderStr,saveName
830        Variable binType
831       
832        String formatStr="",fullpath=""
833        Variable refnum,dialog=1
834
835        SetDataFolder $(pathStr+folderStr)
836
837
838        //TODO
839        //-- make sure the waves exist
840       
841//      if(WaveExists(qw) == 0)
842//              Abort "q is missing"
843//      endif
844//      if(WaveExists(iw) == 0)
845//              Abort "i is missing"
846//      endif
847//      if(WaveExists(sw) == 0)
848//              Abort "s is missing"
849//      endif
850//      if(WaveExists(resw) == 0)
851//              Abort "Resolution information is missing."
852//      endif
853       
854//      Duplicate/O qw qbar,sigQ,fs
855//      if(dimsize(resW,1) > 4)
856//              //it's USANS put -dQv back in the last 3 columns
857//              NVAR/Z dQv = USANS_dQv
858//              if(NVAR_Exists(dQv) == 0)
859//                      SetDataFolder root:
860//                      Abort "It's USANS data, and I don't know what the slit height is."
861//              endif
862//              sigQ = -dQv
863//              qbar = -dQv
864//              fs = -dQv
865//      else
866//              //it's SANS
867//              sigQ = resw[p][0]
868//              qbar = resw[p][1]
869//              fs = resw[p][2]
870//      endif
871//     
872
873
874
875        // TODO:
876        // -- currently I'm using the Save comand and the /B flag
877        //    to save the data as Igor Text format, since otherwise the command string would be
878        //    too long. Need to come up with an Igor-demo friendly save here
879        //
880        // -- see V_ExportProtocol() for a quick example of how to generate the .ITX format
881        //
882        // -- need a reader/plotter capable of handling this data. The regular data loader won't handle
883        //    all the different number of columns present, or the ITX format. See V_DataPlotting and duplicate these routines
884        //    Most of these routines take "winNameStr" as an argument, so I may be able to use them
885        //
886        // -- do I want to add the /O flag to force an overwrite if there is a name conflict?
887
888        PathInfo catPathName
889        fullPath = S_Path + saveName + ".itx"
890
891//      Open refnum as fullpath
892//      fprintf refnum,"Individual data sets written from folder %s on %s\r\n",folderStr,(date()+" "+time())
893
894        String waveStr=""
895        // can be a multiple number of columns
896               
897        switch(binType)
898                case 1:         // 9 sets = 27 waves!
899                        waveStr = "qBin_qxqy_B;iBin_qxqy_B;eBin_qxqy_B;"
900                        waveStr += "qBin_qxqy_ML;iBin_qxqy_ML;eBin_qxqy_ML;"
901                        waveStr += "qBin_qxqy_MR;iBin_qxqy_MR;eBin_qxqy_MR;"
902                        waveStr += "qBin_qxqy_MT;iBin_qxqy_MT;eBin_qxqy_MT;"
903                        waveStr += "qBin_qxqy_MB;iBin_qxqy_MB;eBin_qxqy_MB;"
904                        waveStr += "qBin_qxqy_FL;iBin_qxqy_FL;eBin_qxqy_FL;"
905                        waveStr += "qBin_qxqy_FR;iBin_qxqy_FR;eBin_qxqy_FR;"
906                        waveStr += "qBin_qxqy_FT;iBin_qxqy_FT;eBin_qxqy_FT;"
907                        waveStr += "qBin_qxqy_FB;iBin_qxqy_FB;eBin_qxqy_FB;"
908                       
909                       
910                        Save/T/M="\r\n"/B waveStr as fullPath
911
912                                               
913//                      formatStr = "%15.4g %15.4g %15.4g\r\n"
914//                     
915//                      fprintf refnum, "The 3 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm)\r\n"
916//     
917//                      wfprintf refnum,formatStr,qw,iw,sw
918                        break
919                case 2:         // 5 sets
920
921                        waveStr = "qBin_qxqy_B;iBin_qxqy_B;eBin_qxqy_B;"
922                        waveStr += "qBin_qxqy_MLR;iBin_qxqy_MLR;eBin_qxqy_MLR;qBin_qxqy_MTB;iBin_qxqy_MTB;eBin_qxqy_MTB;"
923                        waveStr += "qBin_qxqy_FLR;iBin_qxqy_FLR;eBin_qxqy_FLR;qBin_qxqy_FTB;iBin_qxqy_FTB;eBin_qxqy_FTB;"
924
925                        Save/T/M="\r\n"/B waveStr as fullPath
926                       
927//                      formatStr = "%15.4g %15.4g %15.4g\r\n"
928//                     
929//                      fprintf refnum, "The 3 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm)\r\n"
930//     
931//                      wfprintf refnum,formatStr,qw,iw,sw
932                        break
933                case 3:         // 3 sets
934//                      WAVE q1 = qBin_qxqy_B
935//                      WAVE i1 = iBin_qxqy_B
936//                      WAVE s1 = eBin_qxqy_B
937//                      WAVE q2 = qBin_qxqy_MLRTB
938//                      WAVE i2 = iBin_qxqy_MLRTB
939//                      WAVE s2 = eBin_qxqy_MLRTB
940//                      WAVE q3 = qBin_qxqy_FLRTB
941//                      WAVE i3 = iBin_qxqy_FLRTB
942//                      WAVE s3 = eBin_qxqy_FLRTB
943//
944//                             
945//                      Save/T/M="\r\n" q1,i1,s1,q2,i2,s2,q3,i3,s3 as fullPath
946                       
947                        waveStr = "qBin_qxqy_B;iBin_qxqy_B;eBin_qxqy_B;"
948                        waveStr += "qBin_qxqy_MLRTB;iBin_qxqy_MLRTB;eBin_qxqy_MLRTB;qBin_qxqy_FLRTB;iBin_qxqy_FLRTB;eBin_qxqy_FLRTB;"
949
950                        Save/T/M="\r\n"/B waveStr as fullPath                   
951                       
952                       
953//                      formatStr = "%15.4g %15.4g %15.4g\r\n"
954//                     
955//                      fprintf refnum, "The 3 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm)\r\n"
956//     
957//                      wfprintf refnum,formatStr,qw,iw,sw
958                        break
959                case 4:         // 9 sets
960                        waveStr = "qBin_qxqy_B;iBin_qxqy_B;eBin_qxqy_B;"
961                        waveStr += "qBin_qxqy_ML;iBin_qxqy_ML;eBin_qxqy_ML;"
962                        waveStr += "qBin_qxqy_MR;iBin_qxqy_MR;eBin_qxqy_MR;"
963                        waveStr += "qBin_qxqy_MT;iBin_qxqy_MT;eBin_qxqy_MT;"
964                        waveStr += "qBin_qxqy_MB;iBin_qxqy_MB;eBin_qxqy_MB;"
965                        waveStr += "qBin_qxqy_FL;iBin_qxqy_FL;eBin_qxqy_FL;"
966                        waveStr += "qBin_qxqy_FR;iBin_qxqy_FR;eBin_qxqy_FR;"
967                        waveStr += "qBin_qxqy_FT;iBin_qxqy_FT;eBin_qxqy_FT;"
968                        waveStr += "qBin_qxqy_FB;iBin_qxqy_FB;eBin_qxqy_FB;"
969                       
970                       
971                        Save/T/M="\r\n"/B waveStr as fullPath
972
973//                      formatStr = "%15.4g %15.4g %15.4g\r\n"
974//                     
975//                      fprintf refnum, "The 3 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm)\r\n"
976//     
977//                      wfprintf refnum,formatStr,qw,iw,sw
978                        break
979                                       
980                default:
981                // do nothing, just close
982
983        endswitch
984
985//      Close refnum
986
987// TODO
988// -- clean up any waves on exit?        Only if I generate extra waves
989//      KillWaves/Z sigQ,qbar,fs
990       
991        SetDataFolder root:
992        return(0)
993End
994
995
996Proc V_Load_Data_ITX()
997        V_Load_itx("","",0,0)
998end
999
1000// TODO
1001// -- fill in
1002// -- link somewhere?
1003//
1004// a function to load in the individual I(q) sets which were written out to a single
1005// file, in itx format.
1006//
1007// The data, like other 1D data sets, is to be loaded to its own folder under root
1008//
1009// Then, the data sets can be plotted as VSANS data sets, depending on which data extensions are present.
1010// (and color coded)
1011// (and used for setting the trimming)
1012// (and...)
1013//
1014//
1015// see A_LoadOneDDataToName(fileStr,outStr,doPlot,forceOverwrite)
1016//
1017Function V_Load_itx(fileStr,outStr,doPlot,forceOverwrite)
1018        String fileStr, outstr
1019        Variable doPlot,forceOverwrite
1020
1021        SetDataFolder root:             //build sub-folders for each data set under root
1022
1023        // if no fileStr passed in, display dialog now
1024        if (cmpStr(fileStr,"") == 0)
1025                fileStr = DoOpenFileDialog("Select a data file to load")
1026                if (cmpstr(fileStr,"") == 0)
1027                        String/G root:Packages:NIST:gLastFileName = ""
1028                        return(0)               //get out if no file selected
1029                endif
1030        endif
1031
1032        //Load the waves, using default waveX names
1033        //if no path or file is specified for LoadWave, the default Mac open dialog will appear
1034        LoadWave/O/T fileStr
1035//      LoadWave/G/D/A/Q fileStr
1036        String fileNamePath = S_Path+S_fileName
1037//              String basestr = ParseFilePath(3,ParseFilePath(5,fileNamePath,":",0,0),":",0,0)
1038
1039        String basestr
1040        if (!cmpstr(outstr, ""))                //Outstr = "", cmpstr returns 0
1041//                      enforce a short enough name here to keep Igor objects < 31 chars
1042                baseStr = ShortFileNameString(CleanupName(S_fileName,0))
1043                baseStr = CleanupName(baseStr,0)                //in case the user added odd characters
1044                //baseStr = CleanupName(S_fileName,0)
1045        else
1046                baseStr = outstr                        //for output, hopefully correct length as passed in
1047        endif
1048
1049//              print "basestr :"+basestr
1050        String fileName =  ParseFilePath(0,ParseFilePath(5,filestr,":",0,0),":",1,0)
1051//              print "filename :"+filename
1052       
1053        Variable ii,num=ItemsinList(S_waveNames)
1054       
1055        if(DataFolderExists("root:"+baseStr))
1056                if (!forceOverwrite)
1057                        DoAlert 1,"The file "+S_filename+" has already been loaded. Do you want to load the new data file, overwriting the data in memory?"
1058                        if(V_flag==2)   //user selected No, don't load the data
1059                                SetDataFolder root:
1060                                for(ii=0;ii<num;ii+=1)         
1061                                        KillWaves $(StringFromList(ii, S_waveNames))    // kill the waves that were loaded
1062                                endfor
1063                                if(DataFolderExists("root:Packages:NIST"))
1064                                        String/G root:Packages:NIST:gLastFileName = filename
1065                                endif
1066                                return(0)       //quits the macro
1067                        endif
1068                endif
1069                SetDataFolder $("root:"+baseStr)
1070        else
1071                NewDataFolder/S $("root:"+baseStr)
1072        endif
1073       
1074//                      ////overwrite the existing data, if it exists
1075
1076// a semicolon-delimited list of wave names loaded
1077//S_waveNames
1078        for(ii=0;ii<num;ii+=1)         
1079                Duplicate/O $("root:"+StringFromList(ii, S_waveNames)), $(StringFromList(ii, S_waveNames))
1080        endfor
1081
1082
1083// clean up
1084        SetDataFolder root:
1085
1086        for(ii=0;ii<num;ii+=1)         
1087                KillWaves $(StringFromList(ii, S_waveNames))    // kill the waves that were loaded
1088        endfor
1089//                      Duplicate/O $("root:"+n0), $w0
1090//                      Duplicate/O $("root:"+n1), $w1
1091//                      Duplicate/O $("root:"+n2), $w2
1092       
1093                        // no resolution matrix to make
1094
1095       
1096        return(0)
1097End
1098
1099
1100// given strings of the number of points to remove, loop over the detectors
1101//
1102// TODO
1103// -- currently uses global strings or default strings
1104// -- if proper strings (non-null) are passed in, they are used, otherwise global, then default
1105Function V_Trim1DDataStr(folderStr,binType,nBegStr,nEndStr)
1106        String folderStr
1107        Variable binType
1108        String nBegStr,nEndStr
1109       
1110        String detListStr
1111        if(binType == 1)
1112                detListStr = ksBinType1
1113        endif
1114        if(binType == 2)
1115                detListStr = ksBinType2
1116        endif
1117        if(binType == 3)
1118                detListStr = ksBinType3
1119        endif
1120        if(binType == 4)
1121                detListStr = ksBinType4
1122        endif
1123        if(strlen(detListStr)==0)
1124                return(0)
1125        endif
1126
1127       
1128        //use global, then default values if null string passed in
1129        if(strlen(nBegStr)==0)
1130                SVAR/Z gBegPtsStr=root:Packages:NIST:VSANS:Globals:Protocols:gBegPtsStr
1131                SVAR/Z gEndPtsStr=root:Packages:NIST:VSANS:Globals:Protocols:gEndPtsStr
1132       
1133                if(!SVAR_exists(gBegPtsStr) || !SVAR_exists(gEndPtsStr) || strlen(gBegPtsStr)==0 || strlen(gEndPtsStr)==0)
1134                        nBegStr = ksBinTrimBegDefault
1135                        nEndStr = ksBinTrimEndDefault
1136                else
1137                        nBegStr = gBegPtsStr
1138                        nEndStr = gEndPtsStr
1139                endif
1140        endif   
1141
1142        Variable num, ii,nBeg,nEnd
1143        String item,detstr
1144       
1145        num = ItemsInList(detListStr)
1146        for(ii=0;ii<num;ii+=1)
1147                detStr = StringFromList(ii, detListStr)
1148                nBeg = NumberByKey(detStr, nBegStr,"=",";")
1149                nEnd = NumberByKey(detStr, nEndStr,"=",";")
1150                V_TrimOneSet(folderStr,detStr,nBeg,nEnd)
1151        endfor
1152
1153        return(0)
1154End
1155
1156// TODO
1157// -- make this resolution-aware
1158//
1159Function V_TrimOneSet(folderStr,detStr,nBeg,nEnd)
1160        String folderStr,detStr
1161        Variable nBeg,nEnd
1162       
1163        SetDataFolder $("root:Packages:NIST:VSANS:"+folderStr)
1164
1165        Printf "%d points removed from beginning, %d points from the end  of %s \r",nbeg,nend,detStr
1166
1167// TODO
1168// for each binType block:
1169// --declare the waves
1170// --make a copy of the waves??
1171//      //--Break out resolution wave into separate waves
1172// --delete the beginning points from everything
1173        // --trim off the last nEnd points from everything
1174//      --DeletePoints num-nEnd,nEnd, qw,iw,sw
1175//      // --delete all points where the shadow is < 0.98
1176////--Put resolution contents back???
1177
1178                Wave/Z qw = $("qBin_qxqy_"+detStr)
1179                Wave/Z iw = $("iBin_qxqy_"+detStr)
1180                Wave/Z ew = $("eBin_qxqy_"+detStr)
1181
1182                       
1183                DeletePoints 0,nBeg, qw,iw,ew
1184
1185                Variable npt
1186                npt = numpnts(qw)
1187                DeletePoints npt-nEnd,nEnd, qw,iw,ew
1188       
1189        return(0)
1190End
Note: See TracBrowser for help on using the repository browser.