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

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

adding the annular average option to the protocol definition and execution.

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