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

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

moved dead time correction to before the solid angle correction, so that the dead time would be correcting counts, not counts per solid angle

added a routine to kill all of the waves and folders possible, if the overall DF kill failed. This is to prevent stray folders and waves from being present if different data files are loaded - since different data blocks are present for say, 3He data, data with temperature logging, etc.
This kill routine is used every time, before raw data is loaded, DIV or MASK loaded, or data is converted to WORK.

changed the "Save I(q)" button on the data display panel to save as ITX format, since the data has not been processed, and data can more easily be used for trimming input.

picking protocols in dialogs now excludes/includes appropriate waves

menus are consolidated

Fixed bug in SANS macros where the DRK[] item in the protocol could be null, and force the read of a DRK file, even if it was not desired.

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