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

Last change on this file since 1121 was 1121, checked in by srkline, 4 years ago

adding procedures for calculating sector averages of the data

still need to add overlay of sector angles.

File size: 22.5 KB
Line 
1#pragma TextEncoding = "MacRoman"               // For details execute DisplayHelpTopic "The TextEncoding Pragma"
2#pragma rtGlobals=3             // Use modern global access method and strict wave access.
3
4
5//
6// Operation does no scaling, only the basic (default) trim of the ends, concatenate, sort, and save
7// -- if data has been converted to WORK and the solid angle correction was done, then the data
8//   is per unit solid angle, and matches up - at least the simulated data does...
9//   It should match up in real VSANS data since the flux conditions are identical for
10//   all panels, only the geometry is different.
11//
12//
13// V_DataPlotting.ipf is where the I(q) panel is drawn and the binning is set
14//
15// see the VCALC BinAllMiddlePanels() for an example of this
16// see the binning routines in VC_DetectorBinning_Utils.ipf for the details
17//
18
19// TODO
20//
21// -- verify the binning for slit mode. Looks correct, but verify
22// -- DOCUMENT
23//
24// x- detector "B" is currently skipped since the calibration waves are not faked
25//    when the raw data is loaded. Then the qxqyqz waves are not generated.
26//
27// x- REDO the logic here. It's a mess, and will get the calculation wrong
28//
29// x- figure out the binning type (where is it set for VSANS?)
30// x- don't know, so currently VSANS binning type is HARD-WIRED
31// x- figure out when this needs to be called to (force) re-calculate I vs Q
32//
33
34
35
36//
37// NOTE
38// this is the master conversion function
39// ***Use no others
40// *** When other bin types are developed, DO NOT reassign these numbers.
41//  instead, skip the old numbers and assign new ones.
42//
43// - the numbers here in the switch can be out of order - it's fine
44//
45// old modes can be removed from the string constant ksBinTypeStr(n) (in V_Initialize.ipf), but the
46// mode numbers are what many different binning, plotting, and reduction functions are
47// switching on. In the future, it may be necessary to change the key (everywhere) to a string
48// switch, but for now, stick with the numbers.
49//
50// Strconstant ksBinTypeStr = "F4-M4-B;F2-M2-B;F1-M1-B;F2-M1-B;F1-M2xTB-B;F2-M2xTB-B;SLIT-F2-M2-B;"
51//
52//
53Function V_BinTypeStr2Num(binStr)
54        String binStr
55       
56        Variable binType
57        strswitch(binStr)       // string switch
58                case "F4-M4-B":
59                        binType = 1
60                        break           // exit from switch
61                case "F2-M2-B":
62                        binType = 2
63                        break           // exit from switch
64                case "F1-M1-B":
65                        binType = 3
66                        break           // exit from switch
67                case "SLIT-F2-M2-B":
68                        binType = 4
69                        break           // exit from switch
70
71                case "F2-M1-B":
72                        binType = 5
73                        break
74                case "F1-M2xTB-B":
75                        binType = 6
76                        break
77                case "F2-M2xTB-B":
78                        binType = 7
79                        break
80                       
81                default:                        // optional default expression executed
82                        binType = 0
83                        Abort "Binning mode not found"// when no case matches
84        endswitch       
85       
86        return(binType)
87end
88
89//
90// TODO -- binType == 4 (slit mode) should never end up here
91// -- new logic in calling routines to dispatch to proper routine
92// -- AND need to write the routine for binning_SlitMode
93//
94Function V_QBinAllPanels_Circular(folderStr,binType,collimationStr)
95        String folderStr
96        Variable binType
97        String collimationStr
98
99        // do the back, middle, and front separately
100       
101//      figure out the binning type (where is it set?)
102        Variable ii,delQ
103        String detStr
104
105//      binType = V_GetBinningPopMode()
106
107        // set delta Q for binning (used later inside VC_fDoBinning_QxQy2D)
108        for(ii=0;ii<ItemsInList(ksDetectorListAll);ii+=1)
109                detStr = StringFromList(ii, ksDetectorListAll, ";")
110               
111                delQ = V_SetDeltaQ(folderStr,detStr)            // this sets (overwrites) the global value for each panel type
112        endfor
113       
114
115        switch(binType)
116                case 1:
117                        VC_fDoBinning_QxQy2D(folderStr,"FL",collimationStr)
118                        VC_fDoBinning_QxQy2D(folderStr,"FR",collimationStr)
119                        VC_fDoBinning_QxQy2D(folderStr,"FT",collimationStr)
120                        VC_fDoBinning_QxQy2D(folderStr,"FB",collimationStr)
121                        VC_fDoBinning_QxQy2D(folderStr,"ML",collimationStr)
122                        VC_fDoBinning_QxQy2D(folderStr,"MR",collimationStr)
123                        VC_fDoBinning_QxQy2D(folderStr,"MT",collimationStr)
124                        VC_fDoBinning_QxQy2D(folderStr,"MB",collimationStr)                     
125                        VC_fDoBinning_QxQy2D(folderStr, "B",collimationStr)             
126
127                        break
128                case 2:
129                        VC_fDoBinning_QxQy2D(folderStr,"FLR",collimationStr)
130                        VC_fDoBinning_QxQy2D(folderStr,"FTB",collimationStr)
131                        VC_fDoBinning_QxQy2D(folderStr,"MLR",collimationStr)
132                        VC_fDoBinning_QxQy2D(folderStr,"MTB",collimationStr)
133                        VC_fDoBinning_QxQy2D(folderStr, "B",collimationStr)             
134
135                        break
136                case 3:
137                        VC_fDoBinning_QxQy2D(folderStr,"MLRTB",collimationStr)
138                        VC_fDoBinning_QxQy2D(folderStr,"FLRTB",collimationStr)
139                        VC_fDoBinning_QxQy2D(folderStr, "B",collimationStr)             
140                       
141                        break
142                case 4:                         /// this is for a tall, narrow slit mode       
143                        VC_fBinDetector_byRows(folderStr,"FL")
144                        VC_fBinDetector_byRows(folderStr,"FR")
145                        VC_fBinDetector_byRows(folderStr,"ML")
146                        VC_fBinDetector_byRows(folderStr,"MR")
147                        VC_fBinDetector_byRows(folderStr,"B")
148
149                        break
150                case 5:
151                        VC_fDoBinning_QxQy2D(folderStr,"FTB",collimationStr)
152                        VC_fDoBinning_QxQy2D(folderStr,"FLR",collimationStr)
153                        VC_fDoBinning_QxQy2D(folderStr,"MLRTB",collimationStr)
154                        VC_fDoBinning_QxQy2D(folderStr, "B",collimationStr)             
155               
156                        break
157                case 6:
158                        VC_fDoBinning_QxQy2D(folderStr,"FLRTB",collimationStr)
159                        VC_fDoBinning_QxQy2D(folderStr,"MLR",collimationStr)
160                        VC_fDoBinning_QxQy2D(folderStr, "B",collimationStr)             
161               
162                        break
163                case 7:
164                        VC_fDoBinning_QxQy2D(folderStr,"FTB",collimationStr)
165                        VC_fDoBinning_QxQy2D(folderStr,"FLR",collimationStr)
166                        VC_fDoBinning_QxQy2D(folderStr,"MLR",collimationStr)
167                        VC_fDoBinning_QxQy2D(folderStr, "B",collimationStr)             
168               
169                        break
170                       
171                default:
172                        Abort "Binning mode not found in V_QBinAllPanels_Circular"// when no case matches       
173        endswitch
174       
175
176        return(0)
177End
178
179
180//
181// TODO -- binType == 4 (slit mode) should be the only case to end up here
182// -- new logic in calling routines to dispatch to proper routine
183// -- AND need to write the routine for binning_SlitMode
184//
185Function V_QBinAllPanels_Slit(folderStr,binType)
186        String folderStr
187        Variable binType
188
189        // do the back, middle, and front separately
190       
191//      figure out the binning type (where is it set?)
192        Variable ii,delQ
193        String detStr
194
195//      binType = V_GetBinningPopMode()
196
197        // set delta Q for binning (used later inside VC_fDoBinning_QxQy2D)
198        for(ii=0;ii<ItemsInList(ksDetectorListAll);ii+=1)
199                detStr = StringFromList(ii, ksDetectorListAll, ";")
200               
201                delQ = V_SetDeltaQ(folderStr,detStr)            // this sets (overwrites) the global value for each panel type
202        endfor
203       
204
205        switch(binType)
206                case 1:
207
208                        break
209                case 2:
210
211                        break
212                case 3:
213
214                        break
215                case 4:                         /// this is for a tall, narrow slit mode       
216                        VC_fBinDetector_byRows(folderStr,"FL")
217                        VC_fBinDetector_byRows(folderStr,"FR")
218                        VC_fBinDetector_byRows(folderStr,"ML")
219                        VC_fBinDetector_byRows(folderStr,"MR")
220                        VC_fBinDetector_byRows(folderStr,"B")
221
222                        break
223                case 5:
224               
225                        break
226                case 6:
227               
228                        break
229                case 7:
230       
231                        break
232                       
233                default:
234                        Abort "Binning mode not found in V_QBinAllPanels_Slit"// when no case matches   
235        endswitch
236       
237       
238
239        return(0)
240End
241
242
243
244// concatenates and sorts the 1D data in "type" WORK folder
245// uses the current display if type==""
246//
247Function V_ConcatenateForSave(pathStr,type,tagStr,binType)
248        String pathStr,type,tagStr
249        Variable binType
250       
251// get the current display type, if null string passed in
252        SVAR curtype = root:Packages:NIST:VSANS:Globals:gCurDispType
253       
254        if(strlen(type)==0)
255                type = curType
256        endif
257
258// trim the data if needed
259        // remove the q=0 point from the back detector, if it's there
260        // does not need to know binType
261        NVAR gIgnoreDetB = root:Packages:NIST:VSANS:Globals:gIgnoreDetB
262        if(!gIgnoreDetB)
263                V_RemoveQ0_B(type)
264        endif
265
266// concatenate the data sets
267// TODO x- figure out which binning was used (this is done in V_1DConcatenate())
268        // clear the old tmp waves first, if they still exist
269//      SetDataFolder $("root:Packages:NIST:VSANS:"+type)
270        SetDataFolder $(pathStr+type)
271        Killwaves/Z tmp_q,tmp_i,tmp_s,tmp_sq,tmp_qb,tmp_fs
272        setDataFolder root:
273        V_1DConcatenate(pathStr,type,tagStr,binType)
274       
275// sort the data set
276        V_TmpSort1D(pathStr,type)
277       
278        return(0)
279End
280
281//
282// this is only called from the button on the data panel (**not anymore**)
283// so the type is the currently displayed type, and the binning is from the panel
284//
285Function V_SimpleSave1DData(pathStr,type,tagStr,saveName)
286        String pathStr,type,tagStr,saveName
287
288//
289// get the current display type, if null string passed in
290        SVAR curtype = root:Packages:NIST:VSANS:Globals:gCurDispType
291        Variable binType = V_GetBinningPopMode()
292       
293        V_ConcatenateForSave(pathStr,curType,tagStr,binType)
294       
295// write out the data set to a file
296        if(strlen(saveName)==0)
297                Execute "V_GetNameForSave()"
298                SVAR newName = root:saveName
299                saveName = newName
300        endif
301       
302        V_Write1DData(pathStr,curtype,saveName)
303
304End
305
306
307Proc V_GetNameForSave(str)
308        String str
309        String/G root:saveName=str
310End
311
312
313// blindly assumes that there is only one zero at the top of the wave
314// could be more sophisticated in the future...
315Function V_RemoveQ0_B(type)
316        String type
317       
318        SetDataFolder $("root:Packages:NIST:VSANS:"+type)
319
320        WAVE/Z qBin = qBin_qxqy_B
321        WAVE/Z iBin = iBin_qxqy_B
322        WAVE/Z eBin = eBin_qxqy_B
323        WAVE/Z nBin = nBin_qxqy_B
324        WAVE/Z iBin2 = iBin2_qxqy_B
325
326        // resolution waves
327        Wave/Z sigQ = sigmaQ_qxqy_B
328        Wave/Z qBar = qBar_qxqy_B
329        Wave/Z fSubS = fSubS_qxqy_B
330
331        if(qBin[0] == 0)
332                DeletePoints 0, 1, qBin,iBin,eBin,nBin,iBin2,sigQ,qBar,fSubS
333        endif
334       
335        SetDataFolder root:
336        return(0)
337end
338
339
340// concatentate data in folderStr
341//
342// TODO:
343// x- !!! Resolution waves are currently skipped - these must be added
344//
345// x- this currently ignores the binning type (one, two, etc. )
346// x- change the Concatenate call to use the waveList, to eliminate the need to declare all of the waves
347// -- this currently assumes that all of the waves exist
348// -- need robust error checking for wave existence
349// -- wave names are hard-wired and their name and location may be different in the future
350// x- if different averaging options were chosen (bin type of 2, 4 etc) then
351//    although waves may exist, they may not be the right ones to use. There
352//    will be a somewhat complex selection process
353// x- detector B is currently skipped
354//
355// this seems like a lot of extra work to do something so simple...but it's better than a loop
356//
357//  root:Packages:NIST:VSANS:RAW:iBin_qxqy_FB
358//
359// Now, the extensions needed for each binType are handled in a loop using the strings
360// defined globally for each of the numbered binTypes
361//
362// binType = 1 = one
363// binType = 2 = two
364// binType = 3 = four
365// binType = 4 = Slit Mode
366// binType = 5...
367//
368// if binType is passed in as -9999, get the binning mode from the popup
369// otherwise the value is assumed good (from a protocol)
370//
371// pathStr must have the trailing colon
372// tagStr is normally null, but is "_trim" for data to be trimmed
373//
374Function V_1DConcatenate(pathStr,folderStr,tagStr,binType)
375        String pathStr,folderStr,tagStr
376        Variable binType
377       
378
379        if(binType==-9999)
380                binType = V_GetBinningPopMode()
381        endif   
382       
383        String binTypeString = V_getBinTypeString(binType)
384        if(strlen(binTypeString) == 0)
385                DoAlert 0,"binTypeString is null in V_1DConcatenate"
386                return(0)
387        endif
388       
389//      SetDataFolder $("root:Packages:NIST:VSANS:"+folderStr)
390        SetDataFolder $(pathStr+folderStr)
391
392        //kill these waves before starting, or the new concatenation will be added to the old
393        KillWaves/Z tmp_q,tmp_i,tmp_s,tmp_qb,tmp_sq,tmp_fs
394
395        String q_waveListStr=""
396        String i_waveListStr=""
397        String s_waveListStr=""
398        String sq_waveListStr=""
399        String qb_waveListStr=""
400        String fs_waveListStr=""
401       
402        Variable num,ii
403        String item=""
404       
405        //Generate string lists of the waves to be concatenated based on the
406        // binTypeString (a global string constant with the extensions)
407        //
408       
409        NVAR gIgnoreDetB = root:Packages:NIST:VSANS:Globals:gIgnoreDetB
410        if(!gIgnoreDetB)
411                q_waveListStr =  "qBin_qxqy_B" + tagStr + ";"
412                i_waveListStr =  "iBin_qxqy_B" + tagStr + ";"
413                s_waveListStr =  "eBin_qxqy_B" + tagStr + ";"
414                sq_waveListStr =  "sigmaQ_qxqy_B" + tagStr + ";"
415                qb_waveListStr =  "qBar_qxqy_B" + tagStr + ";"
416                fs_waveListStr =  "fSubS_qxqy_B" + tagStr + ";"
417        endif
418
419        num = ItemsInList(binTypeString, ";")
420        for(ii=0;ii<num;ii+=1)
421                item = StringFromList(ii, binTypeString  ,";") 
422       
423        // "B" was handled outside the loop, be sure to skip here
424                if(cmpstr(item,"B") != 0)
425                        q_waveListStr +=  "qBin_qxqy_" + item + tagStr + ";"
426                        i_waveListStr +=  "iBin_qxqy_" + item + tagStr + ";"
427                        s_waveListStr +=  "eBin_qxqy_" + item + tagStr + ";"
428                        sq_waveListStr +=  "sigmaQ_qxqy_" + item + tagStr + ";"
429                        qb_waveListStr +=  "qBar_qxqy_" + item + tagStr + ";"
430                        fs_waveListStr +=  "fSubS_qxqy_" + item + tagStr + ";" 
431                endif
432        endfor
433       
434        // concatenate each of the sets
435
436        Concatenate/NP/O q_waveListStr, tmp_q
437       
438        Concatenate/NP/O i_waveListStr, tmp_i
439               
440        Concatenate/NP/O s_waveListStr, tmp_s
441               
442        Concatenate/NP/O sq_waveListStr, tmp_sq
443
444        Concatenate/NP/O qb_waveListStr, tmp_qb
445               
446        Concatenate/NP/O fs_waveListStr, tmp_fs
447                                                                               
448
449
450// Can't kill here, since they are still needed to sort and write out!
451//      KillWaves/Z tmp_q,tmp_i,tmp_s,tmp_res0,tmp_res1,tmp_res2,tmp_res3       
452       
453        SetDataFolder root:
454       
455        return(0)               
456End
457
458// TODO:
459// -- resolution waves are ignored, since they don't exist (yet)
460// -- only a sort is done, no rescaling of data sets
461//    (it's too late now anyways, since the data was concatenated)
462//
463// see Auto_Sort() in the SANS Automation ipf for the rest of the details of
464// how to combine the resolution waves (they also need to be concatenated, which is currently not done)
465//
466Function V_TmpSort1D(pathStr,folderStr)
467        String pathStr,folderStr
468       
469        SetDataFolder $(pathStr+folderStr)
470
471        Wave qw = tmp_q
472        Wave iw = tmp_i
473        Wave sw = tmp_s
474        Wave sq = tmp_sq
475        Wave qb = tmp_qb
476        Wave fs = tmp_fs
477       
478
479        Sort qw, qw,iw,sw,sq,qb,fs
480
481
482        SetDataFolder root:
483        return(0)
484End
485
486
487Function V_RemoveDuplicateQvals(pathStr,folderStr)
488        String pathStr,folderStr
489       
490        SetDataFolder $(pathStr+folderStr)
491
492        Wave qw = tmp_q
493        Wave iw = tmp_i
494        Wave sw = tmp_s
495        Wave sq = tmp_sq
496        Wave qb = tmp_qb
497        Wave fs = tmp_fs
498       
499        // zero point waves can be generated from sector averages, exit now
500        if(numpnts(qw) == 0)
501                SetDataFolder root:
502                return(1)
503        endif
504       
505        Variable q1,q2,tol,ii
506        tol = 0.001             // 0.1 %
507        q1 = qw[0]
508        ii=0
509        do
510                q2 = qw[ii+1]
511                if(V_CloseEnough(q1,q2,q1*tol))
512                        // check to be sure that both values are actually real numbers before trying to average
513                        if(numtype(iw[ii])==0 && numtype(iw[ii+1])==0)          //==0 => real number
514                                iw[ii] = (iw[ii] + iw[ii+1])/2          //both OK
515                        endif
516                        if(numtype(iw[ii])==0 && numtype(iw[ii+1])!=0)          //==0 => real number
517                                iw[ii] = iw[ii]         //one OK
518                        endif
519                        if(numtype(iw[ii])!=0 && numtype(iw[ii+1])==0)          //==0 => real number
520                                iw[ii] = iw[ii+1]               //other OK
521                        endif
522                        if(numtype(iw[ii])!=0 && numtype(iw[ii+1])!=0)          //==0 => real number
523                                iw[ii] = (iw[ii])               // both NaN, get rid of it later
524                        endif
525               
526                        if(numtype(sw[ii])==0 && numtype(sw[ii+1])==0)          //==0 => real number
527                                sw[ii] = sqrt(sw[ii]^2 + sw[ii+1]^2)            //both OK
528                        endif
529                        if(numtype(sw[ii])==0 && numtype(sw[ii+1])!=0)          //==0 => real number
530                                sw[ii] = sw[ii]         //one OK
531                        endif
532                        if(numtype(sw[ii])!=0 && numtype(sw[ii+1])==0)          //==0 => real number
533                                sw[ii] = sw[ii+1]               //other OK
534                        endif
535                        if(numtype(sw[ii])!=0 && numtype(sw[ii+1])!=0)          //==0 => real number
536                                sw[ii] = (sw[ii])               // both NaN, get rid of it later
537                        endif
538                       
539                        DeletePoints ii+1, 1, qw,iw,sw,sq,qb,fs
540                else
541                        ii+=1
542                        q1 = q2
543                endif
544        while(ii<numpnts(qw)-2)
545       
546       
547
548        SetDataFolder root:
549        return(0)
550End
551
552//
553Proc V_Load_Data_ITX()
554        V_Load_itx("","",0,0)
555end
556
557// TODO
558// -- fill in
559// -- link somewhere?
560//
561// a function to load in the individual I(q) sets which were written out to a single
562// file, in itx format.
563//
564// The data, like other 1D data sets, is to be loaded to its own folder under root
565//
566// Then, the data sets can be plotted as VSANS data sets, depending on which data extensions are present.
567// (and color coded)
568// (and used for setting the trimming)
569// (and...)
570//
571//
572// see A_LoadOneDDataToName(fileStr,outStr,doPlot,forceOverwrite)
573//
574Function V_Load_itx(fileStr,outStr,doPlot,forceOverwrite)
575        String fileStr, outstr
576        Variable doPlot,forceOverwrite
577
578        SetDataFolder root:             //build sub-folders for each data set under root
579
580        // if no fileStr passed in, display dialog now
581        if (cmpStr(fileStr,"") == 0)
582                fileStr = DoOpenFileDialog("Select a data file to load")
583                if (cmpstr(fileStr,"") == 0)
584                        String/G root:Packages:NIST:gLastFileName = ""
585                        return(0)               //get out if no file selected
586                endif
587        endif
588
589        //Load the waves, using default waveX names
590        //if no path or file is specified for LoadWave, the default Mac open dialog will appear
591        LoadWave/O/T fileStr
592//      LoadWave/G/D/A/Q fileStr
593        String fileNamePath = S_Path+S_fileName
594//              String basestr = ParseFilePath(3,ParseFilePath(5,fileNamePath,":",0,0),":",0,0)
595
596        String basestr
597        if (!cmpstr(outstr, ""))                //Outstr = "", cmpstr returns 0
598//                      enforce a short enough name here to keep Igor objects < 31 chars
599                baseStr = ShortFileNameString(CleanupName(S_fileName,0))
600                baseStr = CleanupName(baseStr,0)                //in case the user added odd characters
601                //baseStr = CleanupName(S_fileName,0)
602        else
603                baseStr = outstr                        //for output, hopefully correct length as passed in
604        endif
605
606//              print "basestr :"+basestr
607        String fileName =  ParseFilePath(0,ParseFilePath(5,filestr,":",0,0),":",1,0)
608//              print "filename :"+filename
609       
610        Variable ii,num=ItemsinList(S_waveNames)
611       
612        if(DataFolderExists("root:"+baseStr))
613                if (!forceOverwrite)
614                        DoAlert 1,"The file "+S_filename+" has already been loaded. Do you want to load the new data file, overwriting the data in memory?"
615                        if(V_flag==2)   //user selected No, don't load the data
616                                SetDataFolder root:
617                                for(ii=0;ii<num;ii+=1)         
618                                        KillWaves $(StringFromList(ii, S_waveNames))    // kill the waves that were loaded
619                                endfor
620                                if(DataFolderExists("root:Packages:NIST"))
621                                        String/G root:Packages:NIST:gLastFileName = filename
622                                endif
623                                return(0)       //quits the macro
624                        endif
625                endif
626                SetDataFolder $("root:"+baseStr)
627        else
628                NewDataFolder/S $("root:"+baseStr)
629        endif
630       
631//                      ////overwrite the existing data, if it exists
632
633// a semicolon-delimited list of wave names loaded
634//S_waveNames
635        for(ii=0;ii<num;ii+=1)         
636                Duplicate/O $("root:"+StringFromList(ii, S_waveNames)), $(StringFromList(ii, S_waveNames))
637        endfor
638
639
640// clean up
641        SetDataFolder root:
642
643        for(ii=0;ii<num;ii+=1)         
644                KillWaves $(StringFromList(ii, S_waveNames))    // kill the waves that were loaded
645        endfor
646//                      Duplicate/O $("root:"+n0), $w0
647//                      Duplicate/O $("root:"+n1), $w1
648//                      Duplicate/O $("root:"+n2), $w2
649       
650        // no resolution matrix to make
651
652       
653        return(0)
654End
655
656
657
658// string function to select the correct string constant
659// that corresponds to the selected binType. This string constant
660// contains the list of extensions to be used for plotting, saving, etc.
661//
662// returns null string if no match
663//
664Function/S V_getBinTypeString(binType)
665        Variable binType
666       
667        String detListStr=""
668        if(binType == 1)
669                detListStr = ksBinType1
670        endif
671        if(binType == 2)
672                detListStr = ksBinType2
673        endif
674        if(binType == 3)
675                detListStr = ksBinType3
676        endif
677        if(binType == 4)
678                detListStr = ksBinType4
679        endif
680        if(binType == 5)
681                detListStr = ksBinType5
682        endif
683        if(binType == 6)
684                detListStr = ksBinType6
685        endif
686        if(binType == 7)
687                detListStr = ksBinType7
688        endif
689       
690       
691        return(detListStr)
692End
693
694// given strings of the number of points to remove, loop over the detectors
695//
696// TODO
697// -- currently uses global strings or default strings
698// -- if proper strings (non-null) are passed in, they are used, otherwise global, then default
699Function V_Trim1DDataStr(folderStr,binType,nBegStr,nEndStr)
700        String folderStr
701        Variable binType
702        String nBegStr,nEndStr
703       
704        String detListStr=""
705
706        detListStr = V_getBinTypeString(binType)                //the list of extensions
707        if(strlen(detListStr)==0)
708                return(0)
709        endif
710
711       
712        //use global, then default values if null string passed in
713        if(strlen(nBegStr)==0)
714                SVAR/Z gBegPtsStr=root:Packages:NIST:VSANS:Globals:Protocols:gBegPtsStr
715                SVAR/Z gEndPtsStr=root:Packages:NIST:VSANS:Globals:Protocols:gEndPtsStr
716       
717                if(!SVAR_exists(gBegPtsStr) || !SVAR_exists(gEndPtsStr) || strlen(gBegPtsStr)==0 || strlen(gEndPtsStr)==0)
718                        nBegStr = ksBinTrimBegDefault
719                        nEndStr = ksBinTrimEndDefault
720                else
721                        nBegStr = gBegPtsStr
722                        nEndStr = gEndPtsStr
723                endif
724        endif   
725
726        Variable num, ii,nBeg,nEnd
727        String item,detstr
728
729        NVAR gIgnoreDetB = root:Packages:NIST:VSANS:Globals:gIgnoreDetB
730       
731        num = ItemsInList(detListStr)
732        for(ii=0;ii<num;ii+=1)
733                detStr = StringFromList(ii, detListStr)
734                if(cmpstr(detStr,"B")==0 && gIgnoreDetB)
735                                //skip det B, do nothing
736                else
737                        nBeg = NumberByKey(detStr, nBegStr,"=",";")
738                        nEnd = NumberByKey(detStr, nEndStr,"=",";")
739
740                        V_TrimOneSet(folderStr,detStr,nBeg,nEnd)
741                endif
742        endfor
743
744        return(0)
745End
746
747// TODO
748// x- make this resolution-aware
749//
750Function V_TrimOneSet(folderStr,detStr,nBeg,nEnd)
751        String folderStr,detStr
752        Variable nBeg,nEnd
753       
754        SetDataFolder $("root:Packages:NIST:VSANS:"+folderStr)
755
756
757// TODO
758// for each binType block:
759// --declare the waves
760// --make a copy of the waves??
761//      //--Break out resolution wave into separate waves
762// --delete the beginning points from everything
763        // --trim off the last nEnd points from everything
764//      --DeletePoints num-nEnd,nEnd, qw,iw,sw
765//      // --delete all points where the shadow is < 0.98
766////--Put resolution contents back???
767
768                Wave/Z qw = $("qBin_qxqy_"+detStr)
769                Wave/Z iw = $("iBin_qxqy_"+detStr)
770                Wave/Z ew = $("eBin_qxqy_"+detStr)
771                // resolution waves
772                Wave/Z sigQ = $("sigmaQ_qxqy_"+detStr)
773                Wave/Z qBar = $("qBar_qxqy_"+detStr)
774                Wave/Z fSubS = $("fSubS_qxqy_"+detStr)
775
776// check for the existence of every wave + non-zero length
777// zero length/null waves can be generated with sector averages
778// exit if something is wrong
779                if(waveExists(qw) == 0 || numpnts(qw) == 0)
780                        SetDataFolder root:
781                        return(1)
782                endif
783                if(waveExists(iw) == 0 || numpnts(iw) == 0)
784                        SetDataFolder root:
785                        return(1)
786                endif
787                if(waveExists(ew) == 0 || numpnts(ew) == 0)
788                        SetDataFolder root:
789                        return(1)
790                endif
791                if(waveExists(sigQ) == 0 || numpnts(sigQ) == 0)
792                        SetDataFolder root:
793                        return(1)
794                endif
795                if(waveExists(qBar) == 0 || numpnts(qBar) == 0)
796                        SetDataFolder root:
797                        return(1)
798                endif
799                if(waveExists(fSubS) == 0 || numpnts(fSubS) == 0)
800                        SetDataFolder root:
801                        return(1)
802                endif
803
804
805        // waves all exist             
806                DeletePoints 0,nBeg, qw,iw,ew,sigQ,qBar,fSubS
807
808                Variable npt
809                npt = numpnts(qw)
810                DeletePoints npt-nEnd,nEnd, qw,iw,ew,sigQ,qBar,fSubS
811       
812                Printf "%d points removed from beginning, %d points from the end  of %s \r",nbeg,nend,detStr
813                SetDataFolder root:
814        return(0)
815End
816
817
818////
819//// returns 1 if the val is non-negative, other value
820//// indicates that the resoution data is USANS data.
821////
822//// TODO:
823//// -- this DUPLICATES a same-named SANS procedure, so there could be a clash at some point
824//// -- bigger issue - I'll need a better way to identify and load the different resolution
825////            conditions with VSANS
826////
827////
828//xFunction isSANSResolution(val)
829//      Variable val
830//     
831//      if(val >= 0)
832//              return(1)
833//      else
834//              return(0)
835//      endif
836//End
837
838
Note: See TracBrowser for help on using the repository browser.