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

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

a lot of little changes:

changed the name of the Raw Data display procedure file (removed test)

lots of bug fixes, moving items from the macros menu to proper locations, getting the file status to display properly, some error checking, and cleaning up a few TODO items.

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