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

Last change on this file since 1039 was 1039, checked in by srkline, 6 years ago

changes to incorporate trimming and plotting of data that has been saved as individual detector I(q), as Igor .itx format. This allows the trimming parameters to be set for each detector panel, which can then be used during the reduction protocol to automatically trim and combine the panels. Next step is to incorporate this into the actual protocol definintion by expanding the current definition.

File size: 34.4 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 will bypass save dialogs
817// -- AND WILL OVERWRITE DATA WITH THE SAME NAME
818//
819Function V_Write1DData_NoConcat(pathStr,folderStr,saveName,binType)
820        String pathStr,folderStr,saveName
821        Variable binType
822       
823        String formatStr="",fullpath=""
824        Variable refnum,dialog=1
825
826        SetDataFolder $(pathStr+folderStr)
827
828
829        //TODO
830        //-- make sure the waves exist
831       
832//      if(WaveExists(qw) == 0)
833//              Abort "q is missing"
834//      endif
835//      if(WaveExists(iw) == 0)
836//              Abort "i is missing"
837//      endif
838//      if(WaveExists(sw) == 0)
839//              Abort "s is missing"
840//      endif
841//      if(WaveExists(resw) == 0)
842//              Abort "Resolution information is missing."
843//      endif
844       
845//      Duplicate/O qw qbar,sigQ,fs
846//      if(dimsize(resW,1) > 4)
847//              //it's USANS put -dQv back in the last 3 columns
848//              NVAR/Z dQv = USANS_dQv
849//              if(NVAR_Exists(dQv) == 0)
850//                      SetDataFolder root:
851//                      Abort "It's USANS data, and I don't know what the slit height is."
852//              endif
853//              sigQ = -dQv
854//              qbar = -dQv
855//              fs = -dQv
856//      else
857//              //it's SANS
858//              sigQ = resw[p][0]
859//              qbar = resw[p][1]
860//              fs = resw[p][2]
861//      endif
862//     
863
864
865
866        // TODO:
867        // -- currently I'm using the Save comand and the /B flag
868        //    to save the data as Igor Text format, since otherwise the command string would be
869        //    too long. Need to come up with an Igor-demo friendly save here
870        //
871        // -- see V_ExportProtocol() for a quick example of how to generate the .ITX format
872        //
873        // -- need a reader/plotter capable of handling this data. The regular data loader won't handle
874        //    all the different number of columns present, or the ITX format. See V_DataPlotting and duplicate these routines
875        //    Most of these routines take "winNameStr" as an argument, so I may be able to use them
876        //
877        // -- do I want to add the /O flag to force an overwrite if there is a name conflict?
878
879        PathInfo catPathName
880        fullPath = S_Path + saveName + ".itx"
881
882//      Open refnum as fullpath
883//      fprintf refnum,"Individual data sets written from folder %s on %s\r\n",folderStr,(date()+" "+time())
884
885        String waveStr=""
886        // can be a multiple number of columns
887               
888        switch(binType)
889                case 1:         // 9 sets = 27 waves!
890                        waveStr = "qBin_qxqy_B;iBin_qxqy_B;eBin_qxqy_B;"
891                        waveStr += "qBin_qxqy_ML;iBin_qxqy_ML;eBin_qxqy_ML;"
892                        waveStr += "qBin_qxqy_MR;iBin_qxqy_MR;eBin_qxqy_MR;"
893                        waveStr += "qBin_qxqy_MT;iBin_qxqy_MT;eBin_qxqy_MT;"
894                        waveStr += "qBin_qxqy_MB;iBin_qxqy_MB;eBin_qxqy_MB;"
895                        waveStr += "qBin_qxqy_FL;iBin_qxqy_FL;eBin_qxqy_FL;"
896                        waveStr += "qBin_qxqy_FR;iBin_qxqy_FR;eBin_qxqy_FR;"
897                        waveStr += "qBin_qxqy_FT;iBin_qxqy_FT;eBin_qxqy_FT;"
898                        waveStr += "qBin_qxqy_FB;iBin_qxqy_FB;eBin_qxqy_FB;"
899                       
900                       
901                        Save/T/M="\r\n"/B waveStr as fullPath
902
903                                               
904//                      formatStr = "%15.4g %15.4g %15.4g\r\n"
905//                     
906//                      fprintf refnum, "The 3 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm)\r\n"
907//     
908//                      wfprintf refnum,formatStr,qw,iw,sw
909                        break
910                case 2:         // 5 sets
911
912                        waveStr = "qBin_qxqy_B;iBin_qxqy_B;eBin_qxqy_B;"
913                        waveStr += "qBin_qxqy_MLR;iBin_qxqy_MLR;eBin_qxqy_MLR;qBin_qxqy_MTB;iBin_qxqy_MTB;eBin_qxqy_MTB;"
914                        waveStr += "qBin_qxqy_FLR;iBin_qxqy_FLR;eBin_qxqy_FLR;qBin_qxqy_FTB;iBin_qxqy_FTB;eBin_qxqy_FTB;"
915
916                        Save/T/M="\r\n"/B waveStr as fullPath
917                       
918//                      formatStr = "%15.4g %15.4g %15.4g\r\n"
919//                     
920//                      fprintf refnum, "The 3 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm)\r\n"
921//     
922//                      wfprintf refnum,formatStr,qw,iw,sw
923                        break
924                case 3:         // 3 sets
925//                      WAVE q1 = qBin_qxqy_B
926//                      WAVE i1 = iBin_qxqy_B
927//                      WAVE s1 = eBin_qxqy_B
928//                      WAVE q2 = qBin_qxqy_MLRTB
929//                      WAVE i2 = iBin_qxqy_MLRTB
930//                      WAVE s2 = eBin_qxqy_MLRTB
931//                      WAVE q3 = qBin_qxqy_FLRTB
932//                      WAVE i3 = iBin_qxqy_FLRTB
933//                      WAVE s3 = eBin_qxqy_FLRTB
934//
935//                             
936//                      Save/T/M="\r\n" q1,i1,s1,q2,i2,s2,q3,i3,s3 as fullPath
937                       
938                        waveStr = "qBin_qxqy_B;iBin_qxqy_B;eBin_qxqy_B;"
939                        waveStr += "qBin_qxqy_MLRTB;iBin_qxqy_MLRTB;eBin_qxqy_MLRTB;qBin_qxqy_FLRTB;iBin_qxqy_FLRTB;eBin_qxqy_FLRTB;"
940
941                        Save/T/M="\r\n"/B waveStr as fullPath                   
942                       
943                       
944//                      formatStr = "%15.4g %15.4g %15.4g\r\n"
945//                     
946//                      fprintf refnum, "The 3 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm)\r\n"
947//     
948//                      wfprintf refnum,formatStr,qw,iw,sw
949                        break
950                case 4:         // 9 sets
951                        waveStr = "qBin_qxqy_B;iBin_qxqy_B;eBin_qxqy_B;"
952                        waveStr += "qBin_qxqy_ML;iBin_qxqy_ML;eBin_qxqy_ML;"
953                        waveStr += "qBin_qxqy_MR;iBin_qxqy_MR;eBin_qxqy_MR;"
954                        waveStr += "qBin_qxqy_MT;iBin_qxqy_MT;eBin_qxqy_MT;"
955                        waveStr += "qBin_qxqy_MB;iBin_qxqy_MB;eBin_qxqy_MB;"
956                        waveStr += "qBin_qxqy_FL;iBin_qxqy_FL;eBin_qxqy_FL;"
957                        waveStr += "qBin_qxqy_FR;iBin_qxqy_FR;eBin_qxqy_FR;"
958                        waveStr += "qBin_qxqy_FT;iBin_qxqy_FT;eBin_qxqy_FT;"
959                        waveStr += "qBin_qxqy_FB;iBin_qxqy_FB;eBin_qxqy_FB;"
960                       
961                       
962                        Save/T/M="\r\n"/B waveStr as fullPath
963
964//                      formatStr = "%15.4g %15.4g %15.4g\r\n"
965//                     
966//                      fprintf refnum, "The 3 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm)\r\n"
967//     
968//                      wfprintf refnum,formatStr,qw,iw,sw
969                        break
970                                       
971                default:
972                // do nothing, just close
973
974        endswitch
975
976//      Close refnum
977
978// TODO
979// -- clean up any waves on exit?        Only if I generate extra waves
980//      KillWaves/Z sigQ,qbar,fs
981       
982        SetDataFolder root:
983        return(0)
984End
985
986
987Macro V_Load_Data_ITX()
988        V_Load_itx("","",0,0)
989end
990
991// TODO
992// -- fill in
993// -- link somewhere?
994//
995// a function to load in the individual I(q) sets which were written out to a single
996// file, in itx format.
997//
998// The data, like other 1D data sets, is to be loaded to its own folder under root
999//
1000// Then, the data sets can be plotted as VSANS data sets, depending on which data extensions are present.
1001// (and color coded)
1002// (and used for setting the trimming)
1003// (and...)
1004//
1005//
1006// see A_LoadOneDDataToName(fileStr,outStr,doPlot,forceOverwrite)
1007//
1008Function V_Load_itx(fileStr,outStr,doPlot,forceOverwrite)
1009        String fileStr, outstr
1010        Variable doPlot,forceOverwrite
1011
1012        SetDataFolder root:             //build sub-folders for each data set under root
1013
1014        // if no fileStr passed in, display dialog now
1015        if (cmpStr(fileStr,"") == 0)
1016                fileStr = DoOpenFileDialog("Select a data file to load")
1017                if (cmpstr(fileStr,"") == 0)
1018                        String/G root:Packages:NIST:gLastFileName = ""
1019                        return(0)               //get out if no file selected
1020                endif
1021        endif
1022
1023        //Load the waves, using default waveX names
1024        //if no path or file is specified for LoadWave, the default Mac open dialog will appear
1025        LoadWave/O/T fileStr
1026//      LoadWave/G/D/A/Q fileStr
1027        String fileNamePath = S_Path+S_fileName
1028//              String basestr = ParseFilePath(3,ParseFilePath(5,fileNamePath,":",0,0),":",0,0)
1029
1030        String basestr
1031        if (!cmpstr(outstr, ""))                //Outstr = "", cmpstr returns 0
1032//                      enforce a short enough name here to keep Igor objects < 31 chars
1033                baseStr = ShortFileNameString(CleanupName(S_fileName,0))
1034                baseStr = CleanupName(baseStr,0)                //in case the user added odd characters
1035                //baseStr = CleanupName(S_fileName,0)
1036        else
1037                baseStr = outstr                        //for output, hopefully correct length as passed in
1038        endif
1039
1040//              print "basestr :"+basestr
1041        String fileName =  ParseFilePath(0,ParseFilePath(5,filestr,":",0,0),":",1,0)
1042//              print "filename :"+filename
1043       
1044        Variable ii,num=ItemsinList(S_waveNames)
1045       
1046        if(DataFolderExists("root:"+baseStr))
1047                if (!forceOverwrite)
1048                        DoAlert 1,"The file "+S_filename+" has already been loaded. Do you want to load the new data file, overwriting the data in memory?"
1049                        if(V_flag==2)   //user selected No, don't load the data
1050                                SetDataFolder root:
1051                                for(ii=0;ii<num;ii+=1)         
1052                                        KillWaves $(StringFromList(ii, S_waveNames))    // kill the waves that were loaded
1053                                endfor
1054                                if(DataFolderExists("root:Packages:NIST"))
1055                                        String/G root:Packages:NIST:gLastFileName = filename
1056                                endif
1057                                return(0)       //quits the macro
1058                        endif
1059                endif
1060                SetDataFolder $("root:"+baseStr)
1061        else
1062                NewDataFolder/S $("root:"+baseStr)
1063        endif
1064       
1065//                      ////overwrite the existing data, if it exists
1066
1067// a semicolon-delimited list of wave names loaded
1068//S_waveNames
1069        for(ii=0;ii<num;ii+=1)         
1070                Duplicate/O $("root:"+StringFromList(ii, S_waveNames)), $(StringFromList(ii, S_waveNames))
1071        endfor
1072
1073
1074// clean up
1075        SetDataFolder root:
1076
1077        for(ii=0;ii<num;ii+=1)         
1078                KillWaves $(StringFromList(ii, S_waveNames))    // kill the waves that were loaded
1079        endfor
1080//                      Duplicate/O $("root:"+n0), $w0
1081//                      Duplicate/O $("root:"+n1), $w1
1082//                      Duplicate/O $("root:"+n2), $w2
1083       
1084                        // no resolution matrix to make
1085
1086       
1087        return(0)
1088End
1089
1090
1091// given strings of the number of points to remove, loop over the detectors
1092//
1093// TODO
1094// -- currently uses global strings or default strings
1095// -- if proper strings (non-null) are passed in, they are used, otherwise global, then default
1096Function V_Trim1DDataStr(folderStr,binType,nBegStr,nEndStr)
1097        String folderStr
1098        Variable binType
1099        String nBegStr,nEndStr
1100       
1101        String detListStr
1102        if(binType == 1)
1103                detListStr = ksBinType1
1104        endif
1105        if(binType == 2)
1106                detListStr = ksBinType2
1107        endif
1108        if(binType == 3)
1109                detListStr = ksBinType3
1110        endif
1111        if(binType == 4)
1112                detListStr = ksBinType4
1113        endif
1114        if(strlen(detListStr)==0)
1115                return(0)
1116        endif
1117
1118       
1119        //use global, then default values if null string passed in
1120        if(strlen(nBegStr)==0)
1121                SVAR/Z gBegPtsStr=root:Packages:NIST:VSANS:Globals:Protocols:gBegPtsStr
1122                SVAR/Z gEndPtsStr=root:Packages:NIST:VSANS:Globals:Protocols:gEndPtsStr
1123       
1124                if(!SVAR_exists(gBegPtsStr) || !SVAR_exists(gEndPtsStr) || strlen(gBegPtsStr)==0 || strlen(gEndPtsStr)==0)
1125                        nBegStr = ksBinTrimBegDefault
1126                        nEndStr = ksBinTrimEndDefault
1127                else
1128                        nBegStr = gBegPtsStr
1129                        nEndStr = gEndPtsStr
1130                endif
1131        endif   
1132
1133        Variable num, ii,nBeg,nEnd
1134        String item,detstr
1135       
1136        num = ItemsInList(detListStr)
1137        for(ii=0;ii<num;ii+=1)
1138                detStr = StringFromList(ii, detListStr)
1139                nBeg = NumberByKey(detStr, nBegStr,"=",";")
1140                nEnd = NumberByKey(detStr, nEndStr,"=",";")
1141                V_TrimOneSet(folderStr,detStr,nBeg,nEnd)
1142        endfor
1143
1144        return(0)
1145End
1146
1147// TODO
1148// -- make this resolution-aware
1149//
1150Function V_TrimOneSet(folderStr,detStr,nBeg,nEnd)
1151        String folderStr,detStr
1152        Variable nBeg,nEnd
1153       
1154        SetDataFolder $("root:Packages:NIST:VSANS:"+folderStr)
1155
1156        Printf "%d points removed from beginning, %d points from the end  of %s \r",nbeg,nend,detStr
1157
1158// TODO
1159// for each binType block:
1160// --declare the waves
1161// --make a copy of the waves??
1162//      //--Break out resolution wave into separate waves
1163// --delete the beginning points from everything
1164        // --trim off the last nEnd points from everything
1165//      --DeletePoints num-nEnd,nEnd, qw,iw,sw
1166//      // --delete all points where the shadow is < 0.98
1167////--Put resolution contents back???
1168
1169                Wave/Z qw = $("qBin_qxqy_"+detStr)
1170                Wave/Z iw = $("iBin_qxqy_"+detStr)
1171                Wave/Z ew = $("eBin_qxqy_"+detStr)
1172
1173                       
1174                DeletePoints 0,nBeg, qw,iw,ew
1175
1176                Variable npt
1177                npt = numpnts(qw)
1178                DeletePoints npt-nEnd,nEnd, qw,iw,ew
1179       
1180        return(0)
1181End
Note: See TracBrowser for help on using the repository browser.