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

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

two significant changes:

1- in the averaging, before the data is finally written out, duplicate q-values (within 0.1%) are averaged so that duplicate q-values do not appear in the data file. This has a very bad effect on the calculation of the smearing matrix (dq=0).

2-for the data from the back (high res) detector, two steps have been added to the processing at the point where the data is converted to WORK. First, a constant read noise value of 200 cts/pixel is subtracted (found from average of multiple runs with beam off) Second, a 3x3 median filter is applied to the whole image to eliminate the stray bright pixels. Some are saturatd, some are simply outliers. Very effective.

File size: 21.6 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        Variable q1,q2,tol,ii
500        tol = 0.001             // 0.1 %
501        q1 = qw[0]
502        ii=0
503        do
504                q2 = qw[ii+1]
505                if(V_CloseEnough(q1,q2,q1*tol))
506                        // check to be sure that both values are actually real numbers before trying to average
507                        if(numtype(iw[ii])==0 && numtype(iw[ii+1])==0)          //==0 => real number
508                                iw[ii] = (iw[ii] + iw[ii+1])/2          //both OK
509                        endif
510                        if(numtype(iw[ii])==0 && numtype(iw[ii+1])!=0)          //==0 => real number
511                                iw[ii] = iw[ii]         //one OK
512                        endif
513                        if(numtype(iw[ii])!=0 && numtype(iw[ii+1])==0)          //==0 => real number
514                                iw[ii] = iw[ii+1]               //other OK
515                        endif
516                        if(numtype(iw[ii])!=0 && numtype(iw[ii+1])!=0)          //==0 => real number
517                                iw[ii] = (iw[ii])               // both NaN, get rid of it later
518                        endif
519               
520                        if(numtype(sw[ii])==0 && numtype(sw[ii+1])==0)          //==0 => real number
521                                sw[ii] = sqrt(sw[ii]^2 + sw[ii+1]^2)            //both OK
522                        endif
523                        if(numtype(sw[ii])==0 && numtype(sw[ii+1])!=0)          //==0 => real number
524                                sw[ii] = sw[ii]         //one OK
525                        endif
526                        if(numtype(sw[ii])!=0 && numtype(sw[ii+1])==0)          //==0 => real number
527                                sw[ii] = sw[ii+1]               //other OK
528                        endif
529                        if(numtype(sw[ii])!=0 && numtype(sw[ii+1])!=0)          //==0 => real number
530                                sw[ii] = (sw[ii])               // both NaN, get rid of it later
531                        endif
532                       
533                        DeletePoints ii+1, 1, qw,iw,sw,sq,qb,fs
534                else
535                        ii+=1
536                        q1 = q2
537                endif
538        while(ii<numpnts(qw)-2)
539       
540       
541
542        SetDataFolder root:
543        return(0)
544End
545
546//
547Proc V_Load_Data_ITX()
548        V_Load_itx("","",0,0)
549end
550
551// TODO
552// -- fill in
553// -- link somewhere?
554//
555// a function to load in the individual I(q) sets which were written out to a single
556// file, in itx format.
557//
558// The data, like other 1D data sets, is to be loaded to its own folder under root
559//
560// Then, the data sets can be plotted as VSANS data sets, depending on which data extensions are present.
561// (and color coded)
562// (and used for setting the trimming)
563// (and...)
564//
565//
566// see A_LoadOneDDataToName(fileStr,outStr,doPlot,forceOverwrite)
567//
568Function V_Load_itx(fileStr,outStr,doPlot,forceOverwrite)
569        String fileStr, outstr
570        Variable doPlot,forceOverwrite
571
572        SetDataFolder root:             //build sub-folders for each data set under root
573
574        // if no fileStr passed in, display dialog now
575        if (cmpStr(fileStr,"") == 0)
576                fileStr = DoOpenFileDialog("Select a data file to load")
577                if (cmpstr(fileStr,"") == 0)
578                        String/G root:Packages:NIST:gLastFileName = ""
579                        return(0)               //get out if no file selected
580                endif
581        endif
582
583        //Load the waves, using default waveX names
584        //if no path or file is specified for LoadWave, the default Mac open dialog will appear
585        LoadWave/O/T fileStr
586//      LoadWave/G/D/A/Q fileStr
587        String fileNamePath = S_Path+S_fileName
588//              String basestr = ParseFilePath(3,ParseFilePath(5,fileNamePath,":",0,0),":",0,0)
589
590        String basestr
591        if (!cmpstr(outstr, ""))                //Outstr = "", cmpstr returns 0
592//                      enforce a short enough name here to keep Igor objects < 31 chars
593                baseStr = ShortFileNameString(CleanupName(S_fileName,0))
594                baseStr = CleanupName(baseStr,0)                //in case the user added odd characters
595                //baseStr = CleanupName(S_fileName,0)
596        else
597                baseStr = outstr                        //for output, hopefully correct length as passed in
598        endif
599
600//              print "basestr :"+basestr
601        String fileName =  ParseFilePath(0,ParseFilePath(5,filestr,":",0,0),":",1,0)
602//              print "filename :"+filename
603       
604        Variable ii,num=ItemsinList(S_waveNames)
605       
606        if(DataFolderExists("root:"+baseStr))
607                if (!forceOverwrite)
608                        DoAlert 1,"The file "+S_filename+" has already been loaded. Do you want to load the new data file, overwriting the data in memory?"
609                        if(V_flag==2)   //user selected No, don't load the data
610                                SetDataFolder root:
611                                for(ii=0;ii<num;ii+=1)         
612                                        KillWaves $(StringFromList(ii, S_waveNames))    // kill the waves that were loaded
613                                endfor
614                                if(DataFolderExists("root:Packages:NIST"))
615                                        String/G root:Packages:NIST:gLastFileName = filename
616                                endif
617                                return(0)       //quits the macro
618                        endif
619                endif
620                SetDataFolder $("root:"+baseStr)
621        else
622                NewDataFolder/S $("root:"+baseStr)
623        endif
624       
625//                      ////overwrite the existing data, if it exists
626
627// a semicolon-delimited list of wave names loaded
628//S_waveNames
629        for(ii=0;ii<num;ii+=1)         
630                Duplicate/O $("root:"+StringFromList(ii, S_waveNames)), $(StringFromList(ii, S_waveNames))
631        endfor
632
633
634// clean up
635        SetDataFolder root:
636
637        for(ii=0;ii<num;ii+=1)         
638                KillWaves $(StringFromList(ii, S_waveNames))    // kill the waves that were loaded
639        endfor
640//                      Duplicate/O $("root:"+n0), $w0
641//                      Duplicate/O $("root:"+n1), $w1
642//                      Duplicate/O $("root:"+n2), $w2
643       
644        // no resolution matrix to make
645
646       
647        return(0)
648End
649
650
651
652// string function to select the correct string constant
653// that corresponds to the selected binType. This string constant
654// contains the list of extensions to be used for plotting, saving, etc.
655//
656// returns null string if no match
657//
658Function/S V_getBinTypeString(binType)
659        Variable binType
660       
661        String detListStr=""
662        if(binType == 1)
663                detListStr = ksBinType1
664        endif
665        if(binType == 2)
666                detListStr = ksBinType2
667        endif
668        if(binType == 3)
669                detListStr = ksBinType3
670        endif
671        if(binType == 4)
672                detListStr = ksBinType4
673        endif
674        if(binType == 5)
675                detListStr = ksBinType5
676        endif
677        if(binType == 6)
678                detListStr = ksBinType6
679        endif
680        if(binType == 7)
681                detListStr = ksBinType7
682        endif
683       
684       
685        return(detListStr)
686End
687
688// given strings of the number of points to remove, loop over the detectors
689//
690// TODO
691// -- currently uses global strings or default strings
692// -- if proper strings (non-null) are passed in, they are used, otherwise global, then default
693Function V_Trim1DDataStr(folderStr,binType,nBegStr,nEndStr)
694        String folderStr
695        Variable binType
696        String nBegStr,nEndStr
697       
698        String detListStr=""
699
700        detListStr = V_getBinTypeString(binType)                //the list of extensions
701        if(strlen(detListStr)==0)
702                return(0)
703        endif
704
705       
706        //use global, then default values if null string passed in
707        if(strlen(nBegStr)==0)
708                SVAR/Z gBegPtsStr=root:Packages:NIST:VSANS:Globals:Protocols:gBegPtsStr
709                SVAR/Z gEndPtsStr=root:Packages:NIST:VSANS:Globals:Protocols:gEndPtsStr
710       
711                if(!SVAR_exists(gBegPtsStr) || !SVAR_exists(gEndPtsStr) || strlen(gBegPtsStr)==0 || strlen(gEndPtsStr)==0)
712                        nBegStr = ksBinTrimBegDefault
713                        nEndStr = ksBinTrimEndDefault
714                else
715                        nBegStr = gBegPtsStr
716                        nEndStr = gEndPtsStr
717                endif
718        endif   
719
720        Variable num, ii,nBeg,nEnd
721        String item,detstr
722
723        NVAR gIgnoreDetB = root:Packages:NIST:VSANS:Globals:gIgnoreDetB
724       
725        num = ItemsInList(detListStr)
726        for(ii=0;ii<num;ii+=1)
727                detStr = StringFromList(ii, detListStr)
728                if(cmpstr(detStr,"B")==0 && gIgnoreDetB)
729                                //skip det B, do nothing
730                else
731                        nBeg = NumberByKey(detStr, nBegStr,"=",";")
732                        nEnd = NumberByKey(detStr, nEndStr,"=",";")
733
734                        V_TrimOneSet(folderStr,detStr,nBeg,nEnd)
735                endif
736        endfor
737
738        return(0)
739End
740
741// TODO
742// x- make this resolution-aware
743//
744Function V_TrimOneSet(folderStr,detStr,nBeg,nEnd)
745        String folderStr,detStr
746        Variable nBeg,nEnd
747       
748        SetDataFolder $("root:Packages:NIST:VSANS:"+folderStr)
749
750        Printf "%d points removed from beginning, %d points from the end  of %s \r",nbeg,nend,detStr
751
752// TODO
753// for each binType block:
754// --declare the waves
755// --make a copy of the waves??
756//      //--Break out resolution wave into separate waves
757// --delete the beginning points from everything
758        // --trim off the last nEnd points from everything
759//      --DeletePoints num-nEnd,nEnd, qw,iw,sw
760//      // --delete all points where the shadow is < 0.98
761////--Put resolution contents back???
762
763                Wave/Z qw = $("qBin_qxqy_"+detStr)
764                Wave/Z iw = $("iBin_qxqy_"+detStr)
765                Wave/Z ew = $("eBin_qxqy_"+detStr)
766                // resolution waves
767                Wave/Z sigQ = $("sigmaQ_qxqy_"+detStr)
768                Wave/Z qBar = $("qBar_qxqy_"+detStr)
769                Wave/Z fSubS = $("fSubS_qxqy_"+detStr)
770                       
771                DeletePoints 0,nBeg, qw,iw,ew,sigQ,qBar,fSubS
772
773                Variable npt
774                npt = numpnts(qw)
775                DeletePoints npt-nEnd,nEnd, qw,iw,ew,sigQ,qBar,fSubS
776       
777        return(0)
778End
779
780
781////
782//// returns 1 if the val is non-negative, other value
783//// indicates that the resoution data is USANS data.
784////
785//// TODO:
786//// -- this DUPLICATES a same-named SANS procedure, so there could be a clash at some point
787//// -- bigger issue - I'll need a better way to identify and load the different resolution
788////            conditions with VSANS
789////
790////
791//xFunction isSANSResolution(val)
792//      Variable val
793//     
794//      if(val >= 0)
795//              return(1)
796//      else
797//              return(0)
798//      endif
799//End
800
801
Note: See TracBrowser for help on using the repository browser.