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

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

updated mask drawing to draw arbitrary shapes, fixing bugs in the operation.

fix operation of popups in transmission panel.

other bug fixes that I don't recall from the past week.

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