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

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

Adding procedures to allow trimming of data sets before concatenation. This is different than SANS, since the trimming and scaling choices must be made before reduction is done, since they must be part of the reduction protocol - as all data sets I(q) are part of the same data file.

How this is handled is still very much a work in progress...

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