source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_Utilities_General.ipf @ 1242

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

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

File size: 42.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#pragma IgorVersion = 7.00
4
5//
6//              general utilities
7//
8// for use by multiple panels and packages
9//
10
11
12//prompts user to choose the local folder that contains the VSANS Data
13//only one folder can be used, and its path is catPathName (and is a NAME, not a string)
14//this will overwrite the path selection
15//returns 1 if no path selected as error condition, or if user cancelled
16Function V_PickPath()
17       
18        //set the global string to the selected pathname
19        NewPath/O/M="pick the SANS data folder" catPathName
20        if(V_Flag != 0)
21                return(1)               //user cancelled
22        endif
23       
24        PathInfo/S catPathName
25        String dum = S_path
26        String alertStr = ""
27        alertStr = "You must set the path to Charlotte through a Mapped Network Drive, not through the Network Neighborhood"
28        //alertStr += "  Please see the manual for details."
29        if (V_flag == 0)
30                //path does not exist - no folder selected
31                String/G root:Packges:NIST:VSANS:Globals:gCatPathStr = "no folder selected"
32                return(1)
33        else
34        // SRK 2016, for windows 10, try to eliminate this restriction 
35        //---- connecting through the network neighborhood seems to be perfectly fine except for
36        //     path issues with GBLoadWave, which only affects VAX data sets
37               
38//              print igorinfo(3)
39//              //set the global to the path (as a string)
40//              // need 4 \ since it is the escape character
41//              if(cmpstr("\\\\",dum[0,1])==0)  //Windows user going through network neighborhood
42//                      DoAlert 0,alertStr
43//                      KillPath catPathName
44//                      return(1)
45//              endif
46                String/G root:Packges:NIST:VSANS:Globals:gCatPathStr = dum
47                return(0)               //no error
48        endif
49       
50End
51
52//
53// entry from the Main Panel
54//
55Proc V_ChangeDisplay(type)
56        String type
57        Prompt type,"WORK data type to display",popup,"RAW;SAM;EMP;BGD;COR;ABS;STO;SUB;ADJ;"
58
59// make sure that data exists before passing this on...
60       
61        if(V_DataExists(type) > 0)
62                V_UpdateDisplayInformation(type)
63        else
64                DoAlert 0,"No data in "+type
65        endif
66End
67
68//
69//
70// very simple function to look for something in a work folder
71// -- only checks for FR data to exist, assumes everything else is there
72// -- can't use the V_get() functions, these will try to load data if it's not there!
73Function V_DataExists(type)
74        String type
75       
76        Wave/Z w = $("root:Packages:NIST:VSANS:"+type+":entry:instrument:detector_FR:data")
77       
78        return(WaveExists(w))
79end
80
81
82
83// (DONE):
84// x- this must be called as needed to force a re-read of the data from disk
85//    "as needed" means that when an operation is done that needs to ensure
86//     a fresh read from disk, it must take care of the kill.
87//
88// ksBaseDFPath points to RawVSANS
89//
90//
91Function V_KillNamedDataFolder(fname)
92        String fname
93       
94        Variable err=0
95       
96        String folderStr = V_GetFileNameFromPathNoSemi(fname)
97        folderStr = V_RemoveDotExtension(folderStr)
98       
99        KillDataFolder/Z $(ksBaseDFPath+folderStr)
100        err = V_flag
101       
102        return(err)
103end
104
105// (DONE)
106// x- this still does not quite work. If there are no sub folders present in the RawVSANS folder
107//    it still thinks there is (1) item there.
108// x- if I replace the semicolon with a comma, it thinks there are two folders present and appears
109//    to delete the RawVSANS folder itself! seems very dangerous...this is because DataFolderDir returns
110//    a comma delimited list, but with a semicolon and \r at the end. need to remove these...
111//
112// NOTE -- use V_CleanupData_w_Progress(0,1) to get a progress bar - since this will take more than
113//     a few seconds to complete, especially if a file catalog was done, or a "batch" patching, etc.
114//
115// *** this appears to be unused, in favor of V_CleanupData_w_Progress(0,1)  **********
116//
117Function V_CleanOutRawVSANS()
118
119        SetDataFolder root:Packages:NIST:VSANS:RawVSANS:
120       
121        // get a list of the data folders there
122        // kill them all if possible
123        String list,item
124        Variable numFolders,ii,pt
125       
126        list = DataFolderDir(1)
127        // this has FOLDERS: at the beginning and is comma-delimited
128        list = list[8,strlen(list)]
129        pt = strsearch(list,";",inf,1)
130        list = list[0,pt-1]                     //remove the ";\r" from the end of the string
131//      print list
132       
133        numFolders = ItemsInList(list , ",")
134//      Print List
135//      print strlen(list)
136
137        for(ii=0;ii<numFolders;ii+=1)
138                item = StringFromList(ii, list ,",")
139//              Print item
140                KillDataFolder/Z $(item)
141        endfor
142
143        list = DataFolderDir(1)
144        list = list[8,strlen(list)]
145        pt = strsearch(list,";",inf,1)
146        list = list[0,pt-1]
147        numFolders = ItemsInList(list, ",")
148        Printf "%g RawVSANS folders could not be killed\r",numFolders
149               
150        SetDataFolder root:
151        return(0)
152End
153
154//
155// examples straight from Wavemetrics help file topic "Progress Windows"
156// Try simpletest(0,0) and simpletest(1,0), simpletest(0,1) and simpletest(1,1)
157//
158//
159// look for simpletest() function in Wavemetrics help file topic "Progress Windows"
160//  this is a modified version.
161//
162// call with (1,1) to get the candystripe bar
163// call with (0,1) to the the "countdown" bar as they are killed
164//
165Function V_CleanupData_w_Progress(indefinite, useIgorDraw)
166        Variable indefinite
167        Variable useIgorDraw            // True to use Igor's own draw method rather than native
168       
169        Variable num,numToClean
170       
171        // is there anything there to be killed?
172        num = V_CleanOutOneRawVSANS()
173        numToClean = num
174        if(num <= 0)
175                return(0)
176        endif
177       
178        // there are some folders to kill, so proceed
179       
180        NewPanel /N=ProgressPanel /W=(285,111,739,193)
181        ValDisplay valdisp0,win=ProgressPanel,pos={18,32},size={342,18},limits={0,num,0},barmisc={0,0}
182        ValDisplay valdisp0,win=ProgressPanel,value= _NUM:0
183        DrawText 20,24,"Cleaning up old files... Please Wait..."
184       
185        if( indefinite )
186                ValDisplay valdisp0,win=ProgressPanel,mode= 4   // candy stripe
187        else
188                ValDisplay valdisp0,win=ProgressPanel,mode= 3   // bar with no fractional part
189        endif
190        if( useIgorDraw )
191                ValDisplay valdisp0,win=ProgressPanel,highColor=(15000,45535,15000)             //(0,65535,0)
192        endif
193        Button bStop,win=ProgressPanel,pos={375,32},size={50,20},title="Stop"
194        DoUpdate /W=ProgressPanel /E=1  // mark this as our progress window
195
196        do
197                num = V_CleanOutOneRawVSANS()
198                if( V_Flag == 2 || num == 0 || num == -1)       // either "stop" or clean exit, or "done" exit from function
199                        break
200                endif
201               
202                ValDisplay valdisp0,win=ProgressPanel,value= _NUM:num
203                DoUpdate /W=ProgressPanel
204        while(1)
205       
206
207        KillWindow ProgressPanel
208        return(numToClean)
209End
210
211
212//
213// x- this still does not quite work. If there are no sub folders present in the RawVSANS folder
214//    it still thinks there is (1) item there.
215// x- if I replace the semicolon with a comma, it thinks there are two folders present and appears
216//    to delete the RawVSANS folder itself! seems very dangerous...this is because DataFolderDir returns
217//    a comma delimited list, but with a semicolon and \r at the end. need to remove these...
218//
219// x- for use with progress bar, kills only one folder, returns the new number of folders left
220// x- if n(in) = n(out), nothing was able to be killed, so return "done" code
221Function V_CleanOutOneRawVSANS()
222
223        SetDataFolder root:Packages:NIST:VSANS:RawVSANS:
224       
225        // get a list of the data folders there
226        // kill them all if possible
227        String list,item
228        Variable numFolders,ii,pt,numIn
229       
230        list = DataFolderDir(1)
231        // this has FOLDERS: at the beginning and is comma-delimited
232        list = list[8,strlen(list)]
233        pt = strsearch(list,";",inf,1)
234        list = list[0,pt-1]                     //remove the ";\r" from the end of the string
235//      print list
236       
237        numFolders = ItemsInList(list , ",")
238        numIn = numFolders
239//      Print List
240//      print strlen(list)
241
242        if(numIn > 0)
243                item = StringFromList(0, list ,",")
244//              Print item
245                KillDataFolder/Z $(item)
246        endif
247
248        list = DataFolderDir(1)
249        list = list[8,strlen(list)]
250        pt = strsearch(list,";",inf,1)
251        list = list[0,pt-1]
252        numFolders = ItemsInList(list, ",")
253       
254        if(numIn == numFolders)
255                Printf "%g RawVSANS folders could not be killed\r",numFolders
256                SetDataFolder root:
257
258                return (-1)
259        endif
260       
261        SetDataFolder root:     
262        return(numFolders)
263End
264
265
266
267
268
269//given a filename of a SANS data filename of the form
270// name.anything
271//returns the name as a string without the ".fbdfasga" extension
272//
273// returns the input string if a "." can't be found (maybe it wasn't there)
274Function/S V_RemoveDotExtension(item)
275        String item
276        String invalid = item   //
277        Variable num=-1
278       
279        //find the "dot"
280        String runStr=""
281        Variable pos = strsearch(item,".",0)
282        if(pos == -1)
283                //"dot" not found
284                return (invalid)
285        else
286                //found, get all of the characters preceeding it
287                runStr = item[0,pos-1]
288                return (runStr)
289        Endif
290End
291
292//returns a string containing filename (WITHOUT the ;vers)
293//the input string is a full path to the file (Mac-style, still works on Win in IGOR)
294//with the folders separated by colons
295//
296// called by MaskUtils.ipf, ProtocolAsPanel.ipf, WriteQIS.ipf
297//
298Function/S V_GetFileNameFromPathNoSemi(fullPath)
299        String fullPath
300       
301        Variable offset1,offset2
302        String filename=""
303        //String PartialPath
304        offset1 = 0
305        do
306                offset2 = StrSearch(fullPath, ":", offset1)
307                if (offset2 == -1)                              // no more colons ?
308                        fileName = FullPath[offset1,strlen(FullPath) ]
309                        //PartialPath = FullPath[0, offset1-1]
310                        break
311                endif
312                offset1 = offset2+1
313        while (1)
314       
315        //remove version number from name, if it's there - format should be: filename;N
316        filename =  StringFromList(0,filename,";")              //returns null if error
317       
318        Return filename
319End
320
321//
322// -- this was copied directly, no changes , from PlotUtils_Macro_v40
323//
324// returns the path to the file, or null if the user cancelled
325// fancy use of optional parameters
326//
327// enforce short file names (25 characters)
328Function/S V_DoSaveFileDialog(msg,[fname,suffix])
329        String msg,fname,suffix
330        Variable refNum
331//      String message = "Save the file as"
332
333        if(ParamIsDefault(fname))
334//              Print "fname not supplied"
335                fname = ""
336        endif
337        if(ParamIsDefault(suffix))
338//              Print "suffix not supplied"
339                suffix = ""
340        endif
341       
342        String outputPath,tmpName,testStr
343        Variable badLength=0,maxLength=25,l1,l2
344       
345       
346        tmpName = fname + suffix
347       
348        do
349                badLength=0
350                Open/D/M=msg/T="????" refNum as tmpName         //OS will allow 255 characters, but then I can't read it back in!
351                outputPath = S_fileName
352               
353                testStr = ParseFilePath(0, outputPath, ":", 1, 0)               //just the filename
354                if(strlen(testStr)==0)
355                        break           //cancel, allow exit
356                endif
357                if(strlen(testStr) > maxLength)
358                        badlength = 1
359                        DoAlert 2,"File name is too long. Is\r"+testStr[0,maxLength-1]+"\rOK?"
360                        if(V_flag==3)
361                                outputPath = ""
362                                break
363                        endif
364                        if(V_flag==1)                   //my suggested name is OK, so trim the output
365                                badlength=0
366                                l1 = strlen(testStr)            //too long length
367                                l1 = l1-maxLength               //number to trim
368                                //Print outputPath
369                                l2=strlen(outputPath)
370                                outputPath = outputPath[0,l2-1-l1]
371                                //Print "modified  ",outputPath
372                        endif
373                        //if(V_flag==2)  do nothing, let it go around again
374                endif
375               
376        while(badLength)
377       
378        return outputPath
379End
380
381
382
383//
384// this will only load the data into RAW, overwriting whatever is there. no copy is put in rawVSANS
385//
386Function V_LoadAndPlotRAW_wName(fname)
387        String fname
388
389        Variable err=   V_LoadHDF5Data(fname,"RAW")                     // load the data
390//      Print "Load err = "+num2str(err)
391        if(!err)
392                SVAR hdfDF = root:file_name                     // last file loaded, may not be the safest way to pass
393                String folder = StringFromList(0,hdfDF,".")
394               
395                // this (in SANS) just passes directly to fRawWindowHook()
396                V_UpdateDisplayInformation("RAW")               // plot the data in whatever folder type
397                               
398                // set the global to display ONLY if the load was called from here, not from the
399                // other routines that load data (to read in values)
400                SVAR gLastFile =        root:Packages:NIST:VSANS:Globals:gLastLoadedFile
401                gLastFile = hdfDF
402        endif
403End
404
405
406
407//
408// previous/next button needs these functions
409// as well as many other utilities that manipulate the data file names
410// and parse run numbers.
411//
412
413
414// TODO
415// -- getting the file_name from the root: global is a poor choice.
416//     Need a better, more reliable solution than this
417//
418// DONE
419// x- load in the proper file
420// x- re-click the I(q) button
421// x- be sure that the globals are updated w/ filename
422// x- make a copy of "oldName" that is local and not the SVAR, as the SVAR changes
423//    when the next file is loaded in (if it's not in RawVSANS), resulting in a "skipped" file number
424//
425//displays next (or previous) file in series of run numbers
426//file is read from disk, if path is set and the file number is present
427//increment +1, adds 1 to run number, -1 subtracts one
428//
429// will automatically step a gap of 10 run numbers, but nothing larger. Don't want to loop too long
430// trying to find a file (frustrating), don't want to look past the end of the run numbers (waste)
431// -- may find a more elegant solution later.
432//
433Function V_LoadPlotAndDisplayRAW(increment)
434        Variable increment
435
436        Variable i,val
437        String filename,tmp,curFileName,str
438        //take the currently displayed RAW file
439        SVAR oldName = root:Packages:NIST:VSANS:Globals:gLastLoadedFile
440        oldname = V_RemoveAllSpaces(oldname)            //
441        curFileName = oldName
442       
443        filename = oldname
444
445        i = 1
446        val = increment
447        do
448
449                val = i*increment
450                filename = V_GetPrevNextRawFile(oldName,val)
451               
452//              printf "i=%d, file=%s\r",i,filename
453               
454                tmp = ParseFilePath(0, filename, ":", 1, 0)
455                               
456                i+=1
457        while( strlen(tmp) == 0 && i < 11)
458
459
460        if(strlen(tmp) == 0)            //in some cases, a null string can be returned - handle gracefully
461                return(0)
462        endif
463       
464        // display the specified RAW data file
465        // this is the set of steps done in DisplayMainButtonProc(ctrlName) : ButtonControl
466        Variable err=   V_LoadHDF5Data(filename,"RAW")                  // load the data, set the global w/file name loaded
467//      Print "Load err = "+num2str(err)
468        if(!err)
469                SVAR hdfDF = root:file_name                     // last file loaded, may not be the safest way to pass
470                String folder = StringFromList(0,hdfDF,".")
471               
472                // this (in SANS) just passes directly to fRawWindowHook()
473                V_UpdateDisplayInformation("RAW")       // plot the data in whatever folder type
474               
475                // set the global to display ONLY if the load was called from here, not from the
476                // other routines that load data (to read in values)
477                SVAR gLastLoad = root:Packages:NIST:VSANS:Globals:gLastLoadedFile
478                gLastLoad = hdfDF
479        endif
480
481        //
482        // x- update the 1D plotting as needed. these are SANS calls (OK for now, but will need to be better)
483        //do the average and plot (either the default, or what is on the panel currently)
484        SVAR type = root:Packages:NIST:VSANS:Globals:gCurDispType
485        type = "RAW"
486        V_PlotData_Panel()              // read the binType from the panel
487        Variable binType = V_GetBinningPopMode()
488        ControlInfo/W=V_1D_Data popup0
489        V_BinningModePopup("",binType,S_Value)          // does default circular binning and updates the graph
490
491
492        return(0)
493End
494
495
496// Return the full path:filename that represents the previous or next file.
497// Input is current filename and increment.
498// Increment should be -1 or 1
499// -1 => previous file
500// 1 => next file
501//
502// V_CheckIfRawData(fname)
503//
504Function/S V_GetPrevNextRawFile(curfilename, prevnext)
505        String curfilename
506        Variable prevnext
507
508        String filename
509       
510        //get the run number
511        Variable num = V_GetRunNumFromFile(curfilename)
512               
513        //find the next specified file by number
514        fileName = V_FindFileFromRunNumber(num+prevnext)
515
516        Return filename
517End
518
519
520//returns a string containing the full path to the file containing the
521//run number "num". The null string is returned if no valid file can be found
522//the path "catPathName" used and is hard-wired, will abort if this path does not exist
523//the file returned will be a RAW VSANS data file, other types of files are
524//filtered out.
525//
526//
527// -- with the run numbers incrementing from 1, there is no need to add leading zeros to the
528//    file names. simply add the number and go.
529//
530// called by Buttons.ipf and Transmission.ipf, and locally by parsing routines
531//
532Function/S V_FindFileFromRunNumber(num)
533        Variable num
534       
535        String fullName="",partialName="",item=""
536        //get list of raw data files in folder that match "num"
537
538        String numStr=""
539        numStr = num2istr(num)
540
541        //make sure that path exists
542        PathInfo catPathName
543        String path = S_path
544        if (V_flag == 0)
545                Abort "folder path does not exist - use Pick Path button"
546        Endif
547        String list="",newList="",testStr=""
548       
549        list = IndexedFile(catPathName,-1,"????")       //get all files in folder
550        //find (the) one with the number in the run # location in the name
551        Variable numItems,ii,runFound,isRAW
552        numItems = ItemsInList(list,";")                //get the new number of items in the list
553        ii=0
554        do
555                //parse through the list in this order:
556                // 1 - does item contain run number (as a string) "TTTTTnnn.SAn_XXX_Tyyy"
557                // 2 - exclude by isRaw? (to minimize disk access)
558                item = StringFromList(ii, list  ,";" )
559                if(strlen(item) != 0)
560                        //find the run number, if it exists as a three character string
561                        testStr = V_GetRunNumStrFromFile(item)
562                        runFound= cmpstr(numStr,testStr)        //compare the three character strings, 0 if equal
563                        if(runFound == 0)
564                                //the run Number was found
565                                //build valid filename
566                                partialName = V_FindValidFileName(item)
567                                if(strlen(partialName) != 0)            //non-null return from FindValidFileName()
568                                        fullName = path + partialName
569                                        //check if RAW, if so,this must be the file!
570                                        isRAW = V_CheckIfRawData(fullName)
571                                        if(isRaw)
572                                                //print "is raw, ",fullname
573                                                //stop here
574                                                return(fullname)
575                                        Endif
576                                Endif
577                        Endif
578                Endif
579                ii+=1
580        while(ii<numItems)              //process all items in list
581        Return ("")     //null return if file not found in list
582End
583
584//
585//  x- for VSANS Nexus files, how do I quickly identify if a file is
586//   RAW VSANS data? I don't want to generate any errors, but I want to quickly
587//   weed out the reduced data sets, etc. from file catalogs.
588//      (check the instrument name...)
589
590// (DONE) x- as was written by SANS, this function is expecting fname to be the path:fileName
591// - but are the V_get() functions OK with getting a full path, and what do they
592//  do when they fail? I don't want them to spit up another open file dialog
593//
594// x- problem -- if "sans1234.abs" is passed, then V_getStringFromHDF5(fname,path,num)
595//  will remove the extension and look for the sans1234 folder -- which may or may not be present.
596//  If it is present, then sans1234 validates as RAW data -- which is incorrect!
597// x- so I need a way to exclude everything that does not have the proper extension...
598//
599//
600Function V_CheckIfRawData(fname)
601        String fname
602       
603        String testStr=""
604
605// check for the proper raw data extension
606        if( stringmatch(fname,"*.nxs.ngv*") )
607                // name appears OK, proceed
608                testStr = V_getInstrumentName(fname)
609
610                if(cmpstr(testStr,"NG3-VSANS") == 0)
611                        //testStr exists, ASSUMING it's a raw VSANS data file
612                        Return(1)
613                else
614                        //some other file
615                        Return(0)
616                Endif
617       
618        else
619                // not a proper raw VSANS file name
620                return(0)
621               
622        endif   
623       
624
625End
626
627//  x- need to fill in correctly by determining this from the INTENT field
628//
629Function V_isTransFile(fname)
630        String fname
631       
632        Variable refnum,totalBytes
633        String testStr=""
634       
635        testStr = V_getReduction_intent(fname)
636
637        if(cmpstr(testStr,"TRANSMISSION") == 0)         //
638                //yes, a transmission file
639                Return(1)
640        else
641                //some other file intent
642                Return(0)
643        Endif
644End
645
646
647Function V_GetRunNumFromFile(item)
648        String item
649       
650        String str = V_GetRunNumStrFromFile(item)
651       
652        return(str2num(str))
653end
654
655
656// (DONE) x- the file name structure for VSANS file is undecided
657// so some of these base functions will need to change
658//
659//given a filename of a VSANS data filename of the form
660// sansNNNN.nxs.ngv
661//returns the run number "NNNN" as a STRING of (x) characters
662//
663// -- the run number incements from 1, so the number of digits is UNKNOWN
664// -- number starts at position [4] (the 5th character)
665// -- number ends with the character prior to the first "."
666//
667//returns "ABCD" as an invalid file number
668//
669// local function to aid in locating files by run number
670//
671Function/S V_GetRunNumStrFromFile(item)
672        String item
673        String invalid = "ABCD" //"ABCD" is not a valid run number, since it's text
674        Variable num=-1
675       
676        //find the "dot"
677        String runStr=""
678        Variable numChar = 4
679        Variable pos = strsearch(item,".",0)
680        if(pos == -1)
681                //"dot" not found
682                return (invalid)
683        else
684                //found, get the characters preceeding it, but still after the "sans" characters
685                if (pos-1 < 4)
686                        //not enough characters
687                        return (invalid)
688                else
689                        runStr = item[4,pos-1]
690                        return (runStr)
691                Endif
692        Endif
693End
694
695//Function attempts to find valid filename from partial name by checking for
696// the existence of the file on disk.
697// - checks as is
698// - strips spaces
699// - permutations of upper/lowercase
700//
701// added 11/99 - uppercase and lowercase versions of the file are tried, if necessary
702// since from marquee, the filename field (textread[0]) must be used, and can be a mix of                       //02JUL13
703// upper/lowercase letters, while the filename on the server (should) be all caps
704// now makes repeated calls to ValidFileString()
705//
706// returns a valid filename (No path prepended) or a null string
707//
708// called by any functions, both external and local
709//
710Function/S V_FindValidFilename(partialName)
711        String PartialName
712       
713        String retStr=""
714       
715        //try name with no changes - to allow for ABS files that have spaces in the names 12APR04
716        retStr = V_ValidFileString(partialName)
717        if(cmpstr(retStr,"") !=0)
718                //non-null return
719                return(retStr)
720        Endif
721       
722        //if the partial name is derived from the file header, there can be spaces at the beginning
723        //or in the middle of the filename - depending on the prefix and initials used
724        //
725        //remove any leading spaces from the name before starting
726        partialName = V_RemoveAllSpaces(partialName)
727       
728        //try name with no spaces
729        retStr = V_ValidFileString(partialName)
730        if(cmpstr(retStr,"") !=0)
731                //non-null return
732                return(retStr)
733        Endif
734       
735        //try all UPPERCASE
736        partialName = UpperStr(partialName)
737        retStr = V_ValidFileString(partialName)
738        if(cmpstr(retStr,"") !=0)
739                //non-null return
740                return(retStr)
741        Endif
742       
743        //try all lowercase (ret null if failure)
744        partialName = LowerStr(partialName)
745        retStr = V_ValidFileString(partialName)
746        if(cmpstr(retStr,"") !=0)
747                //non-null return
748                return(retStr)
749        else
750                return(retStr)
751        Endif
752End
753
754
755// Function checks for the existence of a file
756// partialName;vers (to account for VAX filenaming conventions)
757// The partial name is tried first with no version number
758//
759// *** the PATH is hard-wired to catPathName (which is assumed to exist)
760// version numers up to ;10 are tried
761// only the "name;vers" is returned if successful. The path is not prepended
762//
763// local function
764//
765// DONE
766// x- this is essentially a pass-through, since there are no version numbers for VSANS data files
767//    it is kept in case there are conditions in the future.
768//
769Function/S V_ValidFileString(partialName)
770        String partialName
771       
772        String tempName = "",msg=""
773        Variable ii,refnum
774       
775        ii=0
776        do
777                if(ii==0)
778                        //first pass, try the partialName
779                        tempName = partialName
780                        Open/Z/R/T="????TEXT"/P=catPathName refnum tempName     //Does open file (/Z flag)
781                        if(V_flag == 0)
782                                //file exists
783                                Close refnum            //YES needed,
784                                break
785                        endif
786                else
787                        tempName = partialName + ";" + num2istr(ii)
788                        Open/Z/R/T="????TEXT"/P=catPathName refnum tempName
789                        if(V_flag == 0)
790                                //file exists
791                                Close refnum
792                                break
793                        endif
794                Endif
795                ii+=1
796                //print "ii=",ii
797        while(ii<11)
798        //go get the selected bits of information, using tempName, which exists
799        if(ii>=11)
800                //msg = partialName + " not found. is version number > 11?"
801                //DoAlert 0, msg
802                //PathInfo catPathName
803                //Print S_Path
804                Return ("")             //use null string as error condition
805        Endif
806       
807        Return (tempName)
808End
809
810//function to remove all spaces from names when searching for filenames
811//the filename (as saved) will never have interior spaces (TTTTTnnn_AB _Bnnn)
812//but the text field in the header WILL, if less than 3 characters were used for the
813//user's initials, and can have leading spaces if prefix was less than 5 characters
814//
815//returns a string identical to the original string, except with the interior spaces removed
816//
817// local function for file name manipulation
818//
819Function/S V_RemoveAllSpaces(str)
820        String str
821       
822        String tempstr = str
823        Variable ii,spc,len             //should never be more than 2 or 3 trailing spaces in a filename
824        ii=0
825        do
826                len = strlen(tempStr)
827                spc = strsearch(tempStr," ",0)          //is the last character a space?
828                if (spc == -1)
829                        break           //no more spaces found, get out
830                endif
831                str = tempstr
832                tempStr = str[0,(spc-1)] + str[(spc+1),(len-1)] //remove the space from the string
833        While(1)        //should never be more than 2 or 3
834       
835        If(strlen(tempStr) < 1)
836                tempStr = ""            //be sure to return a null string if problem found
837        Endif
838       
839        //Print strlen(tempstr)
840       
841        Return(tempStr)
842               
843End
844
845// returns a list of raw data files in the catPathName directory on disk
846// - list is SEMICOLON-delimited
847//
848//  decide how to do this...
849// (1)
850// checks each file in the directory to see if it is a RAW data file by
851// call to V_CheckIfRawData() which currently looks for the instrument name in the file.
852// -- CON - this is excruciatingly slow, and by checking a field in the file, has to load in the
853//  ENTIRE data file, and will load EVERY file in the folder. ugh.
854//
855// (2)
856// as was done for VAX files, look for a specific string in the file name as written by the acquisition
857//  (was .saN), now key on ".nxs.ngv"?
858//
859// ** use method (2), reading each file is just way too slow
860//
861//
862Function/S V_GetRawDataFileList()
863       
864        //make sure that path exists
865        PathInfo catPathName
866        if (V_flag == 0)
867                Abort "Folder path does not exist - use Pick Path button on Main Panel"
868        Endif
869        String path = S_Path
870       
871        String list=IndexedFile(catPathName,-1,"????")
872        String newList="",item="",validName="",fullName=""
873        Variable num=ItemsInList(list,";"),ii
874       
875        for(ii=0;ii<num;ii+=1)
876                item = StringFromList(ii, list  ,";")
877
878                validName = V_FindValidFileName(item)
879                if(strlen(validName) != 0)              //non-null return from FindValidFileName()
880                        fullName = path + validName             
881
882        //method (1)                   
883//                      if(V_CheckIfRawData(item))
884//                              newlist += item + ";"
885//                      endif
886
887        //method (2)                   
888                        if( stringmatch(item,"*.nxs.ngv*") )
889                                newlist += item + ";"
890                        endif
891
892                       
893                endif
894                //print "ii=",ii
895        endfor
896        newList = SortList(newList,";",0)
897        return(newList)
898End
899
900//
901//
902// x- does this need to be more sophisticated?
903//
904// simple "not" of V_GetRawDataFileList()
905Function/S V_Get_NotRawDataFileList()
906       
907        //make sure that path exists
908        PathInfo catPathName
909        if (V_flag == 0)
910                Abort "Folder path does not exist - use Pick Path button on Main Panel"
911        Endif
912        String path = S_Path
913       
914        String list=IndexedFile(catPathName,-1,"????")
915        String newList="",item="",validName="",fullName=""
916        Variable num=ItemsInList(list,";"),ii
917       
918        for(ii=0;ii<num;ii+=1)
919                item = StringFromList(ii, list  ,";")
920
921//              validName = V_FindValidFileName(item)
922//              if(strlen(validName) != 0)              //non-null return from FindValidFileName()
923//                      fullName = path + validName             
924
925        //method (2)                   
926                        if( !stringmatch(item,"*.nxs.ngv*") )
927                                newlist += item + ";"
928                        endif
929
930                       
931//              endif
932                //print "ii=",ii
933        endfor
934        newList = SortList(newList,";",0)
935        return(newList)
936End
937
938// removes any item with ".EXT" from the list
939// don't pass the "."
940// returns a modified list
941Function/S V_RemoveEXTFromList(list,ext)
942        String list,ext
943       
944        ext = "*."+ext
945        Variable num=ItemsInList(list,";"),ii
946        String item,newList=""
947       
948        for(ii=0;ii<num;ii+=1)
949                item = StringFromList(ii, list  ,";")
950
951                if( !stringmatch(item,ext) )
952                        newlist += item + ";"
953                endif
954               
955        endfor
956        return(newList)
957End
958
959//the following is a WaveMetrics procedure from <StrMatchList>
960// MatchList(matchStr,list,sep)
961// Returns the items of the list whose items match matchStr
962// The lists are separated by the sep character, usually ";"
963//
964// matchStr may be something like "abc", in which case it is identical to CmpStr
965// matchStr may also be "*" to match anything, "abc*" to match anything starting with "abc",
966//      "*abc" to match anything ending with "abc".
967// matchStr may also begin with "!" to indicate a match to anything not matching the rest of
968//      the pattern.
969// At most one "*" and one "!" are allowed in matchStr, otherwise the results are not guaranteed.
970//
971Function/S V_MyMatchList(matchStr,list,sep)
972        String matchStr,list,sep
973        String item,outList=""
974        Variable n=strlen(list)
975        Variable en,st=0
976        do
977                en= strsearch(list,sep,st)
978                if( en < 0 )
979                        if( st < n-1 )
980                                en= n   // no trailing separator
981                                sep=""  // don't put sep in output, either
982                        else
983                                break   // no more items in list
984                        endif
985                endif
986                item=list[st,en-1]
987                if( V_MyStrMatch(matchStr,item) == 0 )
988                        outlist += item+sep
989                Endif
990                st=en+1
991        while (st < n ) // exit is by break, above
992        return outlist
993End
994
995//the following is a WaveMetrics procedure from <StrMatchList>
996// StrMatch(matchStr,str)
997// Returns 0 if the pattern in matchStr matches str, else it returns 1
998//
999// matchStr may be something like "abc", in which case it is identical to CmpStr
1000// matchStr may also be "*" to match anything, "abc*" to match anything starting with "abc",
1001//      "*abc" to match anything ending with "abc".
1002// matchStr may also begin with "!" to indicate a match to anything not matching the rest of
1003//      the pattern.
1004// At most one "*" and one "!" are allowed in matchStr, otherwise the results are not guaranteed.
1005//
1006Function V_MyStrMatch(matchStr,str)
1007        String matchStr,str
1008        Variable match = 1              // 0 means match
1009        Variable invert= strsearch(matchStr,"!",0) == 0
1010        if( invert )
1011                matchStr[0,0]=""        // remove the "!"
1012        endif
1013        Variable st=0,en=strlen(str)-1
1014        Variable starPos= strsearch(matchStr,"*",0)
1015        if( starPos >= 0 )      // have a star
1016                if( starPos == 0 )      // at start
1017                        matchStr[0,0]=""                                // remove star at start
1018                else                                    // at end
1019                        matchStr[starPos,999999]=""     // remove star and rest of (ignored, illegal) pattern
1020                endif
1021                Variable len=strlen(matchStr)
1022                if( len > 0 )
1023                        if(starPos == 0)        // star at start, match must be at end
1024                                st=en-len+1
1025                        else
1026                                en=len-1        // star at end, match at start
1027                        endif
1028                else
1029                        str=""  // so that "*" matches anything
1030                endif
1031        endif
1032        match= !CmpStr(matchStr,str[st,en])==0  // 1 or 0
1033        if( invert )
1034                match= 1-match
1035        endif
1036        return match
1037End
1038
1039
1040//input is a list of run numbers, and output is a list of filenames (not the full path)
1041//*** input list must be COMMA delimited***
1042//output is equivalent to selecting from the CAT table
1043//if some or all of the list items are valid filenames, keep them...
1044//if an error is encountered, notify of the offending element and return a null list
1045//
1046//output is COMMA delimited
1047//
1048// this routine is expecting that the "ask", "none" special cases are handled elsewhere
1049//and not passed here
1050//
1051// called by Marquee.ipf, MultipleReduce.ipf, ProtocolAsPanel.ipf
1052//
1053Function/S V_ParseRunNumberList(list)
1054        String list
1055       
1056        String newList="",item="",tempStr=""
1057        Variable num,ii,runNum
1058       
1059        //expand number ranges, if any
1060        list = V_ExpandNumRanges(list)
1061       
1062        num=itemsinlist(list,",")
1063       
1064        for(ii=0;ii<num;ii+=1)
1065                //get the item
1066                item = StringFromList(ii,list,",")
1067                //is it already a valid filename?
1068                tempStr=V_FindValidFilename(item) //returns filename if good, null if error
1069                if(strlen(tempstr)!=0)
1070                        //valid name, add to list
1071                        //Print "it's a file"
1072                        newList += tempStr + ","
1073                else
1074                        //not a valid name
1075                        //is it a number?
1076                        runNum=str2num(item)
1077                        //print runnum
1078                        if(numtype(runNum) != 0)
1079                                //not a number -  maybe an error                       
1080                                DoAlert 0,"List item "+item+" is not a valid run number or filename. Please enter a valid number or filename."
1081                                return("")
1082                        else
1083                                //a run number or an error
1084                                tempStr = V_GetFileNameFromPathNoSemi( V_FindFileFromRunNumber(runNum) )
1085                                if(strlen(tempstr)==0)
1086                                        //file not found, error
1087                                        DoAlert 0,"List item "+item+" is not a valid run number. Please enter a valid number."
1088                                        return("")
1089                                else
1090                                        newList += tempStr + ","
1091                                endif
1092                        endif
1093                endif
1094        endfor          //loop over all items in list
1095       
1096        return(newList)
1097End
1098
1099//takes a comma delimited list that MAY contain number range, and
1100//expands any range of run numbers into a comma-delimited list...
1101//and returns the new list - if not a range, return unchanged
1102//
1103// local function
1104//
1105Function/S V_ExpandNumRanges(list)
1106        String list
1107       
1108        String newList="",dash="-",item,str
1109        Variable num,ii,hasDash
1110       
1111        num=itemsinlist(list,",")
1112//      print num
1113        for(ii=0;ii<num;ii+=1)
1114                //get the item
1115                item = StringFromList(ii,list,",")
1116                //does it contain a dash?
1117                hasDash = strsearch(item,dash,0)                //-1 if no dash found
1118                if(hasDash == -1)
1119                        //not a range, keep it in the list
1120                        newList += item + ","
1121                else
1122                        //has a dash (so it's a range), expand (or add null)
1123                        newList += V_ListFromDash(item)         
1124                endif
1125        endfor
1126       
1127        return newList
1128End
1129
1130//be sure to add a trailing comma to the return string...
1131//
1132// local function
1133//
1134Function/S V_ListFromDash(item)
1135        String item
1136       
1137        String numList="",loStr="",hiStr=""
1138        Variable lo,hi,ii
1139       
1140        loStr=StringFromList(0,item,"-")        //treat the range as a list
1141        hiStr=StringFromList(1,item,"-")
1142        lo=str2num(loStr)
1143        hi=str2num(hiStr)
1144        if( (numtype(lo) != 0) || (numtype(hi) !=0 ) || (lo > hi) )
1145                numList=""
1146                return numList
1147        endif
1148        for(ii=lo;ii<=hi;ii+=1)
1149                numList += num2istr(ii) + ","
1150        endfor
1151       
1152        Return numList
1153End
1154
1155//*********************
1156// List utilities
1157//*********************
1158Function/WAVE V_List2TextWave(list,sep,waveStr)
1159        String list,sep,waveStr
1160       
1161        Variable n= ItemsInList(list,sep)
1162        Make/O/T/N=(n) $waveStr= StringFromList(p,list,sep)
1163        return $waveStr
1164End
1165
1166Function/WAVE V_List2NumWave(list,sep,waveStr)
1167        String list,sep,waveStr
1168       
1169        Variable n= ItemsInList(list,sep)
1170        Make/O/D/N=(n) $waveStr= str2num( StringFromList(p,list,sep) )
1171        return $waveStr
1172End
1173
1174Function /S V_TextWave2List(w,sep)
1175        Wave/T w
1176        String sep
1177       
1178        String newList=""
1179        Variable n=numpnts(w),ii=0
1180        do
1181                newList += w[ii] + sep
1182                ii+=1
1183        while(ii<n)
1184        return(newList)
1185End
1186
1187//for numerical waves
1188Function/S V_NumWave2List(w,sep)
1189        Wave w
1190        String sep
1191       
1192        String newList="",temp=""
1193        Variable n=numpnts(w),ii=0,val
1194        do
1195                val=w[ii]
1196                temp=""
1197                sprintf temp,"%g",val
1198                newList += temp
1199                newList += sep
1200                ii+=1
1201        while(ii<n)
1202        return(newList)
1203End
1204
1205
1206/////
1207// @ IgorExchange
1208//TicToc
1209//Posted April 16th, 2009 by bgallarda
1210//      ¥       in Programming 6.10.x
1211
1212////duplicated here -- for VSANS use
1213function v_tic()
1214        variable/G tictoc = startMSTimer
1215end
1216 
1217function v_toc()
1218        NVAR/Z tictoc
1219        variable ttTime = stopMSTimer(tictoc)
1220        printf "%g seconds\r", (ttTime/1e6)
1221        killvariables/Z tictoc
1222end
1223
1224
1225
1226////// methods for filtering out different lists of files.
1227
1228// testStr is the "intent" string, or grep string
1229// method is the method to use to find the file
1230// 0 = (default) is to use the file catalog (= fastest)
1231// 1 = Grep (not terribly slow)
1232// 2 = read every file (bad choice)
1233//
1234Function/S V_getFileIntentList(testStr,method)
1235        String testStr
1236        Variable method
1237       
1238        Variable ii,num
1239        String list="",item="",fname,newList,intent
1240
1241        // read every file...
1242        if(method == 2)
1243                PathInfo catPathName
1244                String path = S_path
1245                newList = V_GetRawDataFileList()
1246                num=ItemsInList(newList)
1247               
1248                for(ii=0;ii<num;ii+=1)
1249                        item=StringFromList(ii, newList , ";")
1250                        fname = path + item
1251                        intent = V_getReduction_intent(fname)
1252                        if(cmpstr(intent,testStr) == 0)
1253                                list += item + ";"
1254                        endif
1255                endfor 
1256        endif
1257       
1258        // use Grep
1259        if(method == 1)
1260                newList = V_GetRawDataFileList()
1261                num=ItemsInList(newList)
1262                for(ii=0;ii<num;ii+=1)
1263                        item=StringFromList(ii, newList , ";")
1264                        Grep/P=catPathName/Q/E=("(?i)"+testStr) item
1265                        if( V_value )   // at least one instance was found
1266        //                              Print "found ", item,ii
1267                                list += item + ";"
1268                        endif
1269                endfor 
1270       
1271        else
1272        // get the list from the file catalog
1273       
1274                WAVE/T fileNameW = root:Packages:NIST:VSANS:CatVSHeaderInfo:Filenames
1275                WAVE/T intentW = root:Packages:NIST:VSANS:CatVSHeaderInfo:Intent
1276               
1277                Variable np = numpnts(intentW)          //fileNameW is LONGER - so don't use numpnts(fileWave)
1278                for(ii=0;ii<np;ii+=1)
1279                        if(cmpstr(intentW[ii],testStr)==0)              //this is case-INSENSITIVE (necessary, since the case is unknown)
1280                                list += fileNameW[ii] + ";"
1281                        endif           
1282                endfor
1283               
1284                List = SortList(List,";",0)
1285        endif
1286       
1287        return(list)
1288end
1289
1290
1291// testStr is the "purpose" string, or grep string
1292// method is the method to use to find the file
1293// 0 = (default) is to use the file catalog (= fastest)
1294// 1 = Grep (not terribly slow)
1295// 2 = read every file (bad choice)
1296//
1297Function/S V_getFilePurposeList(testStr,method)
1298        String testStr
1299        Variable method
1300       
1301        Variable ii,num
1302        String list="",item="",fname,newList,purpose
1303
1304        // read every file...
1305        if(method == 2)
1306                PathInfo catPathName
1307                String path = S_path
1308                newList = V_GetRawDataFileList()
1309                num=ItemsInList(newList)
1310               
1311                for(ii=0;ii<num;ii+=1)
1312                        item=StringFromList(ii, newList , ";")
1313                        fname = path + item
1314                        purpose = V_getReduction_purpose(fname)
1315                        if(cmpstr(purpose,testStr) == 0)
1316                                list += item + ";"
1317                        endif
1318                endfor 
1319        endif
1320       
1321        // use Grep
1322        if(method == 1)
1323                newList = V_GetRawDataFileList()
1324                num=ItemsInList(newList)
1325                for(ii=0;ii<num;ii+=1)
1326                        item=StringFromList(ii, newList , ";")
1327                        Grep/P=catPathName/Q/E=("(?i)"+testStr) item
1328                        if( V_value )   // at least one instance was found
1329        //                              Print "found ", item,ii
1330                                list += item + ";"
1331                        endif
1332                endfor 
1333       
1334        else
1335        // get the list from the file catalog
1336       
1337                WAVE/T fileNameW = root:Packages:NIST:VSANS:CatVSHeaderInfo:Filenames
1338                WAVE/T purposeW = root:Packages:NIST:VSANS:CatVSHeaderInfo:Purpose
1339               
1340                Variable np = numpnts(purposeW)         //fileNameW is LONGER - so don't use numpnts(fileWave)
1341                for(ii=0;ii<np;ii+=1)
1342                        if(cmpstr(purposeW[ii],testStr)==0)             //this is case-INSENSITIVE (necessary, since the case is unknown)
1343                                list += fileNameW[ii] + ";"
1344                        endif           
1345                endfor
1346               
1347                List = SortList(List,";",0)
1348        endif
1349       
1350        return(list)
1351end
1352
1353
1354// match BOTH the intent and purpose
1355// -- needed to identify the SAMPLE + SCATTERING data files.
1356//
1357//
1358// method is the method to use to find the file (currently ignored, CAT is always used)
1359// 0 = (default) is to use the file catalog (= fastest)
1360// 1 = Grep (not terribly slow)
1361// 2 = read every file (bad choice)
1362//
1363Function/S V_getFileIntentPurposeList(intent,purpose,method)
1364        String intent,purpose
1365        Variable method
1366       
1367        Variable ii,num
1368        String list="",item="",fname,newList
1369
1370//      // read every file...
1371//      if(method == 2)
1372//              PathInfo catPathName
1373//              String path = S_path
1374//              newList = V_GetRawDataFileList()
1375//              num=ItemsInList(newList)
1376//             
1377//              for(ii=0;ii<num;ii+=1)
1378//                      item=StringFromList(ii, newList , ";")
1379//                      fname = path + item
1380//                      purpose = V_getReduction_purpose(fname)
1381//                      if(cmpstr(purpose,testStr) == 0)
1382//                              list += item + ";"
1383//                      endif
1384//              endfor 
1385//      endif
1386//     
1387//      // use Grep
1388//      if(method == 1)
1389//              newList = V_GetRawDataFileList()
1390//              num=ItemsInList(newList)
1391//              for(ii=0;ii<num;ii+=1)
1392//                      item=StringFromList(ii, newList , ";")
1393//                      Grep/P=catPathName/Q/E=("(?i)"+testStr) item
1394//                      if( V_value )   // at least one instance was found
1395//      //                              Print "found ", item,ii
1396//                              list += item + ";"
1397//                      endif
1398//              endfor 
1399//     
1400//      else
1401        // get the list from the file catalog
1402       
1403                WAVE/T fileNameW = root:Packages:NIST:VSANS:CatVSHeaderInfo:Filenames
1404                WAVE/T purposeW = root:Packages:NIST:VSANS:CatVSHeaderInfo:Purpose
1405                WAVE/T intentW = root:Packages:NIST:VSANS:CatVSHeaderInfo:Intent
1406               
1407                Variable np = numpnts(purposeW)         //fileNameW is LONGER - so don't use numpnts(fileWave)
1408                for(ii=0;ii<np;ii+=1)
1409                        if(cmpstr(purposeW[ii],purpose)==0 && cmpstr(intentW[ii],intent)==0)            //this is case-INSENSITIVE (necessary, since the case is unknown)
1410                                list += fileNameW[ii] + ";"
1411                        endif           
1412                endfor
1413               
1414                List = SortList(List,";",0)
1415       
1416        return(list)
1417end
1418
1419
1420// match the INTENT and PURPOSE and GROUP_ID
1421//
1422// -- needed to identify the SAMPLE + SCATTERING data files.
1423//
1424//
1425// method is the method to use to find the file (currently ignored, CAT is always used)
1426// 0 = (default) is to use the file catalog (= fastest)
1427// 1 = Grep (not terribly slow)
1428// 2 = read every file (bad choice)
1429//
1430Function/S V_getFileIntentPurposeIDList(intent,purpose,targetID,method)
1431        String intent,purpose
1432        Variable targetID,method
1433       
1434        Variable ii,num
1435        String list="",item="",fname,newList
1436
1437//      // read every file...
1438//      if(method == 2)
1439//              PathInfo catPathName
1440//              String path = S_path
1441//              newList = V_GetRawDataFileList()
1442//              num=ItemsInList(newList)
1443//             
1444//              for(ii=0;ii<num;ii+=1)
1445//                      item=StringFromList(ii, newList , ";")
1446//                      fname = path + item
1447//                      purpose = V_getReduction_purpose(fname)
1448//                      if(cmpstr(purpose,testStr) == 0)
1449//                              list += item + ";"
1450//                      endif
1451//              endfor 
1452//      endif
1453//     
1454//      // use Grep
1455//      if(method == 1)
1456//              newList = V_GetRawDataFileList()
1457//              num=ItemsInList(newList)
1458//              for(ii=0;ii<num;ii+=1)
1459//                      item=StringFromList(ii, newList , ";")
1460//                      Grep/P=catPathName/Q/E=("(?i)"+testStr) item
1461//                      if( V_value )   // at least one instance was found
1462//      //                              Print "found ", item,ii
1463//                              list += item + ";"
1464//                      endif
1465//              endfor 
1466//     
1467//      else
1468        // get the list from the file catalog
1469       
1470                WAVE/T fileNameW = root:Packages:NIST:VSANS:CatVSHeaderInfo:Filenames
1471                WAVE/T purposeW = root:Packages:NIST:VSANS:CatVSHeaderInfo:Purpose
1472                WAVE/T intentW = root:Packages:NIST:VSANS:CatVSHeaderInfo:Intent
1473                WAVE groupIDW = root:Packages:NIST:VSANS:CatVSHeaderInfo:group_id
1474               
1475                Variable np = numpnts(purposeW)         //fileNameW is LONGER - so don't use numpnts(fileWave)
1476                for(ii=0;ii<np;ii+=1)
1477                        if(cmpstr(purposeW[ii],purpose)==0 && cmpstr(intentW[ii],intent)==0 && groupIDW[ii]==targetID)          //this is case-INSENSITIVE (necessary, since the case is unknown)
1478                                list += fileNameW[ii] + ";"
1479                        endif           
1480                endfor
1481               
1482                List = SortList(List,";",0)
1483       
1484        return(list)
1485end
1486
1487// from WM procedure, extended to three waves for I(q) data sets
1488//
1489// RemoveNaNsQIS(theQWave, theIWave, theSWave)
1490//      Removes all points in an XYZ triple if any of the three waves has the value NaN.
1491//      A NaN represents a blank or missing value.
1492//      Returns the number of points removed.
1493Function V_RemoveNaNsQIS(theXWave, theYWave, theZWave)
1494        Wave theXWave
1495        Wave theYWave
1496        Wave theZWave
1497
1498        Variable p, numPoints, numNaNs
1499        Variable xval, yval, zval
1500       
1501        numNaNs = 0
1502        p = 0                                                                                   // the loop index
1503        numPoints = numpnts(theXWave)                   // number of times to loop
1504
1505        do
1506                xval = theXWave[p]
1507                yval = theYWave[p]
1508                zval = theZWave[p]
1509                if ((numtype(xval)==2) %| (numtype(yval)==2) %| (numtype(zval)==2) )            // either is NaN?
1510                        numNaNs += 1
1511                else                                                                            // if not an outlier
1512                        theXWave[p - numNaNs] = xval            // copy to input wave
1513                        theYWave[p - numNaNs] = yval            // copy to input wave
1514                        theZWave[p - numNaNs] = zval            // copy to input wave
1515                endif
1516                p += 1
1517        while (p < numPoints)
1518       
1519        // Truncate the wave
1520        DeletePoints numPoints-numNaNs, numNaNs, theXWave, theYWave, theZWave
1521       
1522        return(numNaNs)
1523End
1524
1525
1526//
1527////// utilities for the back detector to diagnose saturation issues
1528//
1529//
1530// as of March 2019, the detector data is processed differently, with more
1531// processing done before passing the data to the file. The data is collected
1532// in 1x1 mode, then filtered (11x11) and rebinned. This increases the
1533// pixel saturation value to 16399*16 = 262384
1534// and the read background to Å 200*16
1535//
1536//
1537//
1538// old values were (pre-March 2019) =  saturation value of 16384 and read baackground of 200
1539// (before the 1x1 collection)
1540//
1541
1542
1543Proc Vm_NumberSaturated(folderStr)
1544        String folderStr="RAW"
1545        V_NumberSaturated(folderStr)
1546End
1547
1548Function V_NumberSaturated(folderStr)
1549        String folderStr
1550       
1551        Variable num,saturationValue
1552        Duplicate/O $("root:Packages:NIST:VSANS:"+folderStr+":entry:instrument:detector_B:data") tmpData
1553       
1554        saturationValue = 16399*16
1555       
1556        tmpData = (tmpData > saturationValue-1) ? NaN : tmpData
1557        WaveStats/Q tmpData
1558        num = V_numNaNs
1559       
1560        Printf "Number of saturated pixels = %d (%g %)\r",num,num/(680*1656)*100
1561        KillWaves/Z tmpData
1562       
1563        V_ColorizeSaturated()
1564        return(num)
1565end
1566
1567// turns the saturated values to lime green
1568Function V_ColorizeSaturated()
1569        ModifyImage data ctab= {0,16399*16-1,ColdWarm,0},minRGB=0,maxRGB=(32792,65535,1)
1570End
1571
1572
1573
1574///
1575
Note: See TracBrowser for help on using the repository browser.