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

Last change on this file was 1242, checked in by srkline, 2 years ago

updating the IgorVersion? pragma to v7.0 for all files to be consistent.

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