source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/MultipleReduce.ipf @ 715

Last change on this file since 715 was 699, checked in by srkline, 13 years ago

typos in HFIR_Utils, and integer format on RunNumber? (8-digit) for HFIR in MRED panel.

File size: 26.0 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma version=5.0
3#pragma IgorVersion=6.1
4
5//*************************
6// Vers. 1.2 092101
7//
8// Procedures for the MRED panel to allow quick batch reduction of data files
9// -as of 8/01, use the new method of requiring only run numbers to select the datafiles
10//              and these data failes need not be consecutively numbered
11//
12//****note that much of this file is becoming obsolete as improved methods for
13//reducing multiple files are introduced. Some of these procedures may not last long***
14//
15//**************************
16
17//panel to allow reduction of a series of files using a selected  protocol
18//
19//main entry procedure to open the panel, initializing if necessary
20Proc ReduceMultipleFiles()
21       
22        DoWindow/F Multiple_Reduce_Panel
23        If(V_flag == 0)
24                InitializeMultReducePanel()
25                //draw panel
26                Multiple_Reduce_Panel()
27                //pop the protocol list
28                MRProtoPopMenuProc("",1,"")
29        Endif
30End
31
32//create the global variables needed to run the MReduce Panel
33//all are kept in root:myGlobals:MRED
34//
35Proc InitializeMultReducePanel()
36
37        If(DataFolderExists("root:myGlobals:MRED"))
38                //ok, do nothing
39        else
40                //no, create the folder and the globals
41                NewDataFolder/O root:myGlobals:MRED
42//              String/G root:myGlobals:MRED:gMRedMatchStr = "*"
43                PathInfo catPathName
44                If(V_flag==1)
45                        String dum = S_path
46                        String/G root:myGlobals:MRED:gCatPathStr = dum
47                else
48                        String/G root:myGlobals:MRED:gCatPathStr = "no path selected"
49                endif
50                String/G root:myGlobals:MRED:gMRedList = "none"
51                String/G root:myGlobals:MRED:gMRProtoList = "none"
52                String/G root:myGlobals:MRED:gFileNumList=""
53//              String/G root:myGlobals:MRED:gMRS1 = "no file selected"
54//              String/G root:myGlobals:MRED:gMRS2 = "no file selected"
55//              String/G root:myGlobals:MRED:gMRS3 = "no box selected"
56//              Variable/G root:myGlobals:MRED:gMRV1 =0
57//              Variable/G root:myGlobals:MRED:gMRV2 = 999
58        Endif
59End
60
61//panel recreation macro for the MRED panel
62//
63Window Multiple_Reduce_Panel()
64        PauseUpdate; Silent 1           // building window...
65        NewPanel /W=(535,72,951,228) /K=1 as "Multiple File Reduction"
66        ModifyPanel cbRGB=(65535,49151,29490)
67        ModifyPanel fixedSize=1
68        SetDrawLayer UserBack
69        DrawLine 7,30,422,30
70        SetVariable PathDisplay,pos={77,7},size={300,13},title="Path"
71        SetVariable PathDisplay,help={"This is the path to the folder that will be used to find the SANS data while reducing. If no files appear in the popup, make sure that this folder is set correctly"}
72        SetVariable PathDisplay,limits={-Inf,Inf,0},value= root:myGlobals:MRED:gCatPathStr
73        Button PathButton,pos={3,3},size={70,20},proc=PickMRPathButton,title="Pick Path"
74        Button PathButton,help={"Select the folder containing the raw SANS data files"}
75        Button helpButton,pos={385,3},size={25,20},proc=ShowMRHelp,title="?"
76        Button helpButton,help={"Show the help file for reducing multiple files using the same protocol"}
77        PopupMenu MRFilesPopup,pos={3,72},size={167,19},proc=MRedPopMenuProc,title="File(s) to Reduce"
78        PopupMenu MRFilesPopup,help={"The displayed file is the one that will be reduced. The entire list will be reduced if \"Reduce All..\" is selected. \r If no items, or the wrong items appear, click on the popup to refresh."}
79        PopupMenu MRFilesPopup,mode=1,popvalue="none",value= #"root:myGlobals:MRED:gMRedList"
80        SetVariable MRList,pos={3,48},size={350,13},proc=FileNumberListProc,title="File number list: "
81        SetVariable MRList,help={"Enter a comma delimited list of file numbers to reduce. Ranges can be entered using a dash."}
82        SetVariable MRList,limits={-Inf,Inf,1},value= root:myGlobals:MRED:gFileNumList
83        Button ReduceAllButton,pos={3,128},size={180,20},proc=ReduceAllPopupFiles,title="Reduce All Files in Popup"
84        Button ReduceAllButton,help={"This will reduce ALL of the files in the popup list, not just the top file."}
85        Button DoneButton,pos={280,128},size={110,20},proc=MRDoneButtonProc,title="Done Reducing"
86        Button DoneButton,help={"When done reducing files, this will close this control panel."}
87//      Button cat_short,pos={310,72},size={90,20},proc=DoCatShort,title="File Catalog"
88//      Button cat_short,help={"Use this button to generate a table with file header information. Very useful for identifying files."}
89//      Button show_cat_short,pos={280,98},size={120,20},proc=ShowCatShort_MRED,title="Show File Catalog"
90//      Button show_cat_short,help={"Use this button to bring the File Catalog window to the front."}
91        Button sddList,pos={280,72},size={120,20},proc=ScatteringAtSDDTableButton,title="Files at SDD List"
92        Button sddList,help={"Use this button to generate a table of scattering files at a given ample to detector distance."}
93        Button acceptList,pos={280,98},size={120,20},proc=AcceptMREDList,title="Accept List"
94        Button acceptList,help={"Accept the list of files to reduce."}
95        PopupMenu MRProto_pop,pos={3,98},size={119,19},proc=MRProtoPopMenuProc,title="Protocol "
96        PopupMenu MRProto_pop,help={"All of the data files in the popup will be reduced using this protocol"}
97        PopupMenu MRProto_pop,mode=1,popvalue="none",value= #"root:myGlobals:MRED:gMRProtoList"
98EndMacro
99
100//simple procedure to bring the CAT TABLE to the front if it is present
101//alerts user, but does nothing else if CAT TABLE is not present
102//called by several panels
103//
104Proc ShowCATWindow()
105        DoWindow/F CatVSTable
106        if(V_flag==0)
107                DoAlert 0,"There is no File Catalog table. Use the File Catalog button to create one."
108        Endif
109End
110
111
112//function takes a list of filenames (just the name, no path , no extension)
113//that is COMMA delimited, and creates a new list that is also COMMA delimited
114//and contains the full path:file;vers for each file in the list
115//and ensures that files in returned list are RAW data , and can be found on disk
116//
117Function/S  FullNameListFromFileList(list)
118        String list
119       
120        String newList="",pathStr="",sepStr=","
121        PathInfo catPathName
122        if(V_flag==0)
123                Abort "CatPath does not exist - use Pick Path to select the data folder"
124        else
125                pathStr = S_Path
126        Endif
127       
128        Variable ii,num,ok
129        String fullName="",partialName="",tempName="",str
130         
131        num = ItemsInList(list,",")
132        ii=0
133        do
134                //take each item, and try to find the file (extensions for raw data should be ;1)
135                partialName = StringFromList(ii,list,",")       //COMMA separated list
136                if(strlen(partialName)!=0)              //null string items will be skipped
137                        tempName = FindValidFilename(partialName)               //will add the version # if needed     
138                        fullName = pathStr + tempName                                           //prepend the path (CAT)
139                       
140                        //discard strings that are not filenames (print the non-files)
141                        //make sure the file is really a RAW data file
142                        ok = CheckIfRawData(fullName)           // 1 if RAW, 0 if unknown type
143                        if (!ok)
144                                //write to cmd window that file was not a RAW SANS file
145                                str = "This file is not recognized as a RAW SANS data file: "+tempName+"\r"
146                                Print str
147                        else
148                                //yes, a valid file:path;ext that is RAW SANS
149                                //add the full path:file;ext +"," to the newList
150                                newList += fullName + sepStr
151                        Endif
152                endif           //partialName from original list != ""
153                ii+=1
154        while(ii<num)   //process all items in list
155       
156        Return(newList)
157End
158
159//takes a COMMA delimited list of files (full path:name;vers output of FullNameListFromFileList()
160//function and reduces each of the files in the list
161//the protocol is from the global string (wich is NOt in the MRED folder, but in the Protocols folder
162//
163Function DoReduceList(list)
164        String list
165       
166        //selected protocol is in a temporary global variable so that it can be used with execute
167        SVAR gMredProtoStr = root:myGlobals:Protocols:gMredProtoStr
168        //input list is a comma delimited list of individual sample files to be reduced using the
169        //given protocol - based on WM proc "ExecuteCmdOnList()"
170        //input filenames must be full path:file;ext, so they can be found on disk
171       
172        String cmdTemplate = "ExecuteProtocol(\"" + gMredProtoStr + "\",\"%s\")"
173        String theItem
174        Variable index=0
175        String cmd
176        Variable num = ItemsInList(list,",")
177        do
178                theItem = StringFromList(index,list,",")        //COMMA separated list
179                if(strlen(theItem)!=0)
180                        sprintf cmd,cmdTemplate,theItem         //null string items will be skipped
181                        //Print "cmd = ",cmd
182                        Execute cmd
183                endif
184                index +=1
185        while(index<num)        //exit after all items have been processed
186       
187        //will continue until all files in list are reduced, according to gMredProtoStr protocol
188        return(0)
189End
190
191//executed when a list of filenumbers is entered in the box
192//responds as if the file popup was hit, to update the popup list contents
193//
194Function FileNumberListProc(ctrlName,varNum,varStr,varName) : SetVariableControl
195        String ctrlName
196        Variable varNum
197        String varStr
198        String varName
199               
200        MRedPopMenuProc("MRFilesPopup",0,"")
201End
202
203Proc ShowMRHelp(ctrlName) : ButtonControl
204        String ctrlName
205
206        DisplayHelpTopic/Z/K=1 "SANS Data Reduction Tutorial[Reduce Multiple Files]"
207        if(V_flag !=0)
208                DoAlert 0,"The SANS Data Reduction Tutorial Help file could not be found"
209        endif
210End
211
212//button procedure for bringing File Catalog window to front, if it exists
213//so that the user can see what's going on
214//
215Proc ShowCatShort_MRED(ctrlName) : ButtonControl
216        String ctrlName
217
218        ShowCATWindow()
219End
220
221//allows the user to set the path to the local folder that contains the SANS data
222//2 global strings are reset after the path "catPathName" is reset in the function PickPath()
223// this path is the only one, the globals are simply for convenience
224//
225Function PickMRPathButton(PathButton) : ButtonControl
226        String PathButton
227       
228        PickPath()              //sets the main global path string for catPathName
229       
230        //then update the "local" copy in the MRED subfolder
231        PathInfo/S catPathName
232        String dum = S_path
233        if (V_flag == 0)
234                //path does not exist - no folder selected
235                String/G root:myGlobals:MRED:gCatPathStr = "no folder selected"
236        else
237                String/G root:myGlobals:MRED:gCatPathStr = dum
238        endif
239       
240        //Update the pathStr variable box
241        ControlUpdate/W=Multiple_Reduce_Panel $"PathDisplay"
242       
243        //then update the popup list
244        MRedPopMenuProc("MRFilesPopup",1,"")
245End
246
247// changes the contents of the popup list of files to be reduced based on the
248// range of file numbers entered in the text box
249//
250Function MREDPopMenuProc(MRFilesPopup,popNum,popStr) : PopupMenuControl
251        String MRFilesPopup
252        Variable popNum
253        String popStr
254
255        String list = GetValidMRedPopupList()
256//     
257        String/G root:myGlobals:MRED:gMredList = list
258        ControlUpdate MRFilesPopup
259
260End
261
262//parses the file number list to get valid raw data filenames for reduction
263// -if the numbers and full ranges can be translated to correspond to actual files
264// on disk, the popup list is updated - otherwise the offending number is reported
265// and the user must fix the problem before any reduction can be done
266//
267//ParseRunNumberList() does the work, as it does for the protocol panel
268//
269Function/S GetValidMRedPopupList()
270
271        String commaList="",semiList=""
272        SVAR numList=root:myGLobals:MRED:gFileNumList
273       
274        commaList = ParseRunNumberList(numList)
275        //convert commaList to a semicolon delimited list
276        Variable num=ItemsinList(commaList,","),ii
277        for(ii=0;ii<num;ii+=1)
278                semiList += StringFromList(ii, commaList  ,",") + ";"
279        endfor
280//      print semiList
281//sort the list
282        semiList = SortList(semiList,";",0)
283        return(semiList)
284End
285
286//returns a list of the available protocol waves in the protocols folder
287//removes "CreateNew", "tempProtocol" and "fakeProtocol" from list (if they exist)
288//since these waves do not contain valid protocol instructions
289//
290Function MRProtoPopMenuProc(MRProto_pop,popNum,popStr) : PopupMenuControl
291        String MRProto_pop
292        Variable popNum
293        String popStr
294
295        //get list of currently valid protocols, and put it in the popup (the global list)
296        //excluding "tempProtocol" and "CreateNew" if they exist
297        SetDataFolder root:myGlobals:Protocols
298        String list = WaveList("*",";","")
299        SetDataFolder root:
300       
301        //remove items from the list (list is unchanged if the items are not present)
302        list = RemoveFromList("CreateNew", list, ";")
303        list = RemoveFromList("tempProtocol", list, ";")
304        list = RemoveFromList("fakeProtocol", list, ";")
305       
306        String/G root:myGlobals:MRED:gMRProtoList = list
307        ControlUpdate MRProto_pop
308
309End
310
311//button procedure to close the panel, and the SDD table if if was generated
312//
313Function MRDoneButtonProc(ctrlName) : ButtonControl
314        String ctrlName
315
316        // this button will make sure all files are closed
317        //and close the panel
318
319        Close/A
320        DoWindow/K Multiple_Reduce_Panel
321       
322        DoWindow/K SDDTable     
323        KillDataFolder root:myGlobals:MRED
324End
325
326//button action function caled to reduce all of the files in the "file" popup
327//using the protocol specified in the "protocol" popup
328//converts list of files into comma delimited list of full path:filename;vers
329//that can be reduced as a list
330// also sets the current protocol to a global accessible to the list processing routine
331//
332Function ReduceAllPopupFiles(ctrlName) : ButtonControl
333        String ctrlName
334       
335        //popup (and global list) is a semicolon separated list of files, WITHOUT extensions
336        //transform this list into a COMMA delimited list of FULL filenames, and then they can be processed
337       
338        SVAR semiList = root:myGlobals:MRED:gMredList
339       
340        //process each item in the list, and generate commaList
341        Variable num = ItemsInList(semiList,";" )
342        Variable ii=0
343        String commaList = "",item = ""
344        do
345                item = StringFromList(ii, semiList  ,";" )
346                commaList += item + ","
347                ii+=1
348        while(ii<num)
349        //080601 - send only the comma list of filenames, not full path:name   
350        //commaList = FullNameListFromFileList(commaList)               //gets the full file names (including extension) for each item in list
351
352        //get the selected protocol, and pass as a global
353        ControlInfo MRProto_pop
354        String protocolNameStr = S_Value
355        String/G root:myGlobals:Protocols:gMredProtoStr = "root:myGlobals:Protocols:"+protocolNameStr
356       
357        //also set this as the current protocol, for the function that writes the averaged waves
358        String/G root:myGlobals:Protocols:gProtoStr = protocolNameStr
359       
360        //reduce all the files in the list here, using the global protocol(the full reference)
361        //DoReduceList is found in MultipleReduce.ipf
362        DoReduceList(commaList)
363       
364        Return 0
365End
366
367
368//****************************
369// below are very old procedures, not used (maybe of no value)
370
371
372//little used procedure - works only with menu selections of list processing
373//
374Proc ClearFileList()
375        String/G root:myGlobals:Protocols:gReduceList=""
376        DoAlert 0,"The file reduction list has been initialized"
377        ShowList()
378End
379
380//old procedure, (not used) - data is saved to the catPathName folder, the same folder
381//where the data came from in the first place, avoiding extra paths
382Proc PickSaveFolder()
383        NewPath/O/M="pick folder for averaged data" Save_path
384        PathInfo/S Save_path
385        if (V_flag == 0)
386                //path does not exist - no folder selected
387                Print "No destination path selected - save dialog will be presented"
388        endif
389End
390
391//little used reduction procedure, asks for protocol, then uses this protocol
392//to reduce the files in a list built by selecting files from the CAT window
393//did not get favorable reviews from users and may not be kept
394//
395Proc ReduceFilesInList()
396
397        String protocolName=""
398
399        //generate a list of valid path:file;ext items, comma separated as the input filenames for
400        //ExecuteProtocol(), their final destination
401       
402        String list = root:myGlobals:Protocols:gReduceList
403        Variable num = ItemsInList(list,"," )
404       
405        list = FullNameListFromFileList(list)
406       
407        //Print list
408       
409        //get protocolName in the same manner as "recallprotocol" button
410        //but remember to set a global for  Execute to use
411        SetDataFolder root:myGlobals:Protocols          //must be in protocols folder before executing this Proc       
412        Execute "PickAProtocol()"
413        //get the selected protocol wave choice through a global string variable
414        protocolName = root:myGlobals:Protocols:gProtoStr
415        //If "CreateNew" was selected, ask user to try again
416        if(cmpstr("CreateNew",protocolName) == 0)
417                Abort "CreateNew is for making a new Protocol. Select a previously saved Protocol"
418        Endif
419        SetDataFolder root:
420//      String/G root:myGlobals:Protocols:gMredProtoStr = "root:myGlobals:Protocols:"+protocolName
421       
422        //pass the full path to the protocol for ExecuteProtocol() later
423        //Print gMredProtoStr," protocol name"
424       
425        DoReduceList(list)
426       
427//      KillStrings/Z gMredProtoStr
428       
429//      SetDataFolder root:
430       
431End
432
433//displays the current contents of the FileList window, for multiple file reduction
434//little used function and may not be kept
435//
436Proc ShowList()
437       
438        DoWindow/F ListWin
439        If(V_Flag ==0)
440                NewNotebook/F=1/N=ListWin as "File List"
441        Endif
442        //clear old window contents, reset the path
443        Notebook ListWin,selection={startOfFile,EndOfFile}
444        Notebook ListWin,text="\r"
445       
446        //Write out each item of the comma-delimited list to the notebook
447        String list = root:myGlobals:Protocols:gReduceList
448        Variable index = 0
449        String theItem=""
450        Variable num = ItemsInList(list,"," )
451        do
452                theItem = StringFromList(index,list,",")        //COMMA separated list
453                if(strlen(theItem)!=0)
454                        Notebook ListWin,text=(theItem+"\r")            //null string items will be skipped
455                endif
456                index +=1
457        while(index<num)        //exit after all items are printed
458End
459
460
461//little used function to add the selected file from the CAT/SHORT window to the fileList
462//so that the list of files can be processed batchwise
463//
464Proc AddSelectionToList()
465
466        if(WinType("CatWin")==0)
467                Abort "There is no CAT/SHORT window. Use the CAT/SHORT button to create one."
468        Endif
469        GetSelection notebook,CatWin,3
470        //build a comma separated list of names
471        //does the global variable exist?
472        if(exists("root:myGlobals:Protocols:gReduceList")==2)           //a string exists
473                //do nothing extra
474        else
475                //create (initialize) the global string
476                String/G root:myGlobals:Protocols:gReduceList = ""
477        endif
478        String list = root:myGlobals:Protocols:gReduceList
479        list += S_Selection + ","
480        String/G root:myGlobals:Protocols:gReduceList = list            //reassign the global
481       
482       
483End
484
485//little used function to remove the selected file in the CAT/SHORT window from the fileList
486Proc RemoveFileFromList()
487        //if(WinType("CatWin")==0)
488                //Abort "There is no CAT/SHORT window. Use the CAT/SHORT button to create one."
489        //Endif
490        GetSelection notebook,ListWin,3
491        //remove the selected item from the list
492        String list = root:myGlobals:Protocols:gReduceList
493        list = RemoveFromList(S_selection,list,",")
494        String/G root:myGlobals:Protocols:gReduceList = list
495       
496        ShowList()
497End
498
499// based on WM PossiblyQuoteList(list, separator)
500//      Input is a list of names that may contain liberal names.
501//      Returns the list with liberal names quoted.
502//      Example:
503//              Input:          "wave0;wave 1;"
504//              Output:         "wave0;'wave 1';"
505//      The list is expected to be a standard separated list, like "wave0;wave1;wave2;".
506//*****unused*******
507Function/S PossiblyQuoteFileList(list, separator)
508        String list
509        String separator
510       
511        String item, outputList = ""
512        Variable ii= 0
513        Variable items= ItemsInList(list, separator)
514        do
515                if (ii >= items)                        // no more items?
516                        break
517                endif
518                item= StringFromList(ii, list, separator)
519                outputList += PossiblyQuoteName(item) + separator
520                ii += 1
521        while(1)
522        return outputList
523End
524
525Function ScatteringAtSDDTableButton(ctrlName)
526        String ctrlName
527       
528        Execute "CreateScatteringAtSDDTable()"
529        return(0)
530End
531
532Function AcceptMREDList(ctrlName)
533        String ctrlName
534       
535        SVAR/Z list = root:myGlobals:MRED:gFileNumList
536        if(SVAR_Exists(list)==0)                //check for myself
537                DoAlert 0,"The Multiple Reduce Panel must be open for you to use this function"
538                Return(1)
539        endif
540       
541        // convert the wave to a comma-delimited List
542        wave/Z numW = $"root:myGlobals:MRED:RunNumber"
543        if(waveExists(numW)==0 || numpnts(numW)==0)
544                DoAlert 0, "Generate a list of files at a specific detector distance using the Files at SDD List button"
545                return(0)
546        Endif
547       
548        list = NumWave2IntegerCommaList(numW)
549       
550        //force an update If the SVAR exists, then the panel does too - MRED cleans up after itself when done
551        DoWindow/F Multiple_Reduce_Panel                        //bring to front
552        MRedPopMenuProc("MRFilesPopup",0,"")            //parse the list, pop the menu
553       
554       
555        return(0)
556End
557
558// - to create a table of scattering runs at an input SDD
559Proc CreateScatteringAtSDDTable(SDD_to_Filter)
560        Variable SDD_to_Filter
561       
562        NewDataFolder/O root:myGlobals:MRED
563        DoWindow/F SDDTable
564       
565        Make/O/T/N=0 $"root:myGlobals:MRED:Filenames"
566        Make/O/T/N=0 $"root:myGlobals:MRED:Suffix"
567        Make/O/T/N=0 $"root:myGlobals:MRED:Labels"
568        Make/O/D/N=0 $"root:myGlobals:MRED:SDD"
569        Make/O/D/N=0 $"root:myGlobals:MRED:RunNumber"
570        Make/O/D/N=0 $"root:myGlobals:MRED:IsTrans"
571
572        If(V_Flag==0)
573                SetDataFolder root:myGlobals:MRED
574                Edit Labels, SDD, runNumber as "Scattering at SDD"
575                DoWindow/C $"SDDTable"
576               
577                ModifyTable width(SDD)=40
578                ModifyTable width(Labels)=180
579                ModifyTable format(RunNumber)=1         //so that HFIR 8-digit numbers are interpreted correctly as integers
580               
581                ModifyTable width(Point)=0              //JUN04, remove point numbers - confuses users since point != run
582                SetDataFolder root:
583        Endif
584
585        //get a list of all files in the folder, some will be junk version numbers that don't exist     
586        String list,partialName,tempName,temp=""
587        list = IndexedFile(catPathName,-1,"????")       //get all files in folder
588        Variable numitems,ii,ok
589       
590        //remove version numbers from semicolon-delimited list
591        list =  RemoveVersNumsFromList(list)
592        numitems = ItemsInList(list,";")
593       
594        //loop through all of the files in the list, reading CAT/SHORT information if the file is RAW SANS
595        //***version numbers have been removed***
596        String str,fullName
597        Variable lastPoint
598        ii=0
599       
600        Make/T/O/N=0 notRAWlist
601        do
602                //get current item in the list
603                partialName = StringFromList(ii, list, ";")
604                //get a valid file based on this partialName and catPathName
605                tempName = FindValidFilename(partialName)
606                If(cmpstr(tempName,"")==0)              //a null string was returned
607                        //write to notebook that file was not found
608                        //if string is not a number, report the error
609                        if(str2num(partialName) == NaN)
610                                str = "this file was not found: "+partialName+"\r\r"
611                                //Notebook CatWin,font="Times",fsize=12,text=str
612                        Endif
613                else
614                        //prepend path to tempName for read routine
615                        PathInfo catPathName
616                        FullName = S_path + tempName
617                        //make sure the file is really a RAW data file
618                        ok = CheckIfRawData(fullName)
619                        if (!ok)
620                                //write to notebook that file was not a RAW SANS file
621                                lastPoint = numpnts(notRAWlist)
622                                InsertPoints lastPoint,1,notRAWlist
623                                notRAWlist[lastPoint]=tempname
624                        else
625                                //go write the header information to the Notebook
626                                GetHeaderInfoToSDDWave(fullName,tempName)
627                        Endif
628                Endif
629                ii+=1
630        while(ii<numitems)
631//Now sort them all based on the suffix data (orders them as collected)
632//      SortCombineWaves()
633// sort by label
634//      SortCombineByLabel()
635// remove the transmission waves
636//
637        RemoveTransFilesFromSDDList()
638
639// Remove anything not at the desired SDD, then sort by run number
640        RemoveWrongSDDFromSDDList(SDD_to_Filter)
641       
642// remove anything named blocked, empty cell, etc.
643        RemoveLabeledFromSDDList("EMPTY")               //not case-sensitive
644        RemoveLabeledFromSDDList("MT CELL")             //not case-sensitive
645        RemoveLabeledFromSDDList("BLOCKED BEAM")                //not case-sensitive
646        RemoveLabeledFromSDDList("BEAM BLOCKED")                //not case-sensitive
647
648End
649
650// need fuzzy comparison, since SDD = 1.33 may actually be represented in FP as 1.33000004      !!!
651//
652Function RemoveLabeledFromSDDList(findThisStr)
653        String findThisStr
654        Wave/T filenames = $"root:myGlobals:MRED:Filenames"
655        Wave/T suffix = $"root:myGlobals:MRED:Suffix"
656        Wave/T labels = $"root:myGlobals:MRED:Labels"
657        Wave sdd = $"root:myGlobals:MRED:SDD"
658        Wave runnum = $"root:myGlobals:MRED:RunNumber"
659        Wave isTrans = $"root:myGlobals:MRED:IsTrans"
660       
661        Variable num=numpnts(Labels),ii,loc
662        ii=num-1
663        do
664                loc = strsearch(labels[ii], findThisStr, 0 ,2)          //2==case insensitive, but Igor 5 specific
665                if(loc != -1)
666                        Print "Remove w[ii] = ",num,"  ",labels[ii]
667                        DeletePoints ii, 1, filenames,suffix,labels,sdd,runnum,isTrans
668                endif
669                ii-=1
670        while(ii>=0)
671        return(0)
672End             
673
674// need fuzzy comparison, since SDD = 1.33 may actually be represented in FP as 1.33000004      !!!
675//
676Function RemoveWrongSDDFromSDDList(tSDD)
677        Variable tSDD
678       
679        Wave/T filenames = $"root:myGlobals:MRED:Filenames"
680        Wave/T suffix = $"root:myGlobals:MRED:Suffix"
681        Wave/T labels = $"root:myGlobals:MRED:Labels"
682        Wave sdd = $"root:myGlobals:MRED:SDD"
683        Wave runnum = $"root:myGlobals:MRED:RunNumber"
684        Wave isTrans = $"root:myGlobals:MRED:IsTrans"
685       
686        Variable num=numpnts(sdd),ii,tol = 0.001
687        ii=num-1
688        do
689                if(abs(sdd[ii] - tSDD) > tol)           //if numerically more than 0.001 m different, they're not the same
690                        DeletePoints ii, 1, filenames,suffix,labels,sdd,runnum,isTrans
691                endif
692                ii-=1
693        while(ii>=0)
694       
695        // now sort
696        Sort RunNum,    filenames,suffix,labels,sdd,runnum,isTrans
697        return(0)
698End
699
700
701Function RemoveTransFilesFromSDDList()
702        Wave/T filenames = $"root:myGlobals:MRED:Filenames"
703        Wave/T suffix = $"root:myGlobals:MRED:Suffix"
704        Wave/T labels = $"root:myGlobals:MRED:Labels"
705        Wave sdd = $"root:myGlobals:MRED:SDD"
706        Wave runnum = $"root:myGlobals:MRED:RunNumber"
707        Wave isTrans = $"root:myGlobals:MRED:IsTrans"
708       
709        Variable num=numpnts(isTrans),ii
710        ii=num-1
711        do
712                if(isTrans[ii] != 0)
713                        DeletePoints ii, 1, filenames,suffix,labels,sdd,runnum,isTrans
714                endif
715                ii-=1
716        while(ii>=0)
717        return(0)
718End
719
720//reads header information and puts it in the appropriate waves for display in the table.
721//fname is the full path for opening (and reading) information from the file
722//which alreay was found to exist. sname is the file;vers to be written out,
723//avoiding the need to re-extract it from fname.
724Function GetHeaderInfoToSDDWave(fname,sname)
725        String fname,sname
726       
727        String textstr,temp,lbl,date_time,suffix
728        Variable ctime,lambda,sdd,detcnt,cntrate,refNum,trans,thick,xcenter,ycenter,numatten
729        Variable lastPoint, beamstop
730
731        Wave/T GFilenames = $"root:myGlobals:MRED:Filenames"
732        Wave/T GSuffix = $"root:myGlobals:MRED:Suffix"
733        Wave/T GLabels = $"root:myGlobals:MRED:Labels"
734        Wave GSDD = $"root:myGlobals:MRED:SDD"
735        Wave GRunNumber = $"root:myGlobals:MRED:RunNumber"
736        Wave GIsTrans = $"root:myGlobals:MRED:IsTrans"
737       
738        lastPoint = numpnts(GLambda)
739               
740        InsertPoints lastPoint,1,GFilenames
741        GFilenames[lastPoint]=sname
742       
743        //read the file suffix
744        InsertPoints lastPoint,1,GSuffix
745        GSuffix[lastPoint]=getSuffix(fname)
746
747        // read the sample.label text field
748        InsertPoints lastPoint,1,GLabels
749        GLabels[lastPoint]=getSampleLabel(fname)
750       
751        //read in the SDD
752        InsertPoints lastPoint,1,GSDD
753        GSDD[lastPoint]= getSDD(fname)
754
755        //the run number (not displayed in the table, but carried along)
756        InsertPoints lastPoint,1,GRunNumber
757        GRunNumber[lastPoint] = GetRunNumFromFile(sname)
758
759        // 0 if the file is a scattering  file, 1 (truth) if the file is a transmission file
760        InsertPoints lastPoint,1,GIsTrans
761        GIsTrans[lastPoint]  = isTransFile(fname)               //returns one if beamstop is "out"
762       
763        KillWaves/Z w
764        return(0)
765End
Note: See TracBrowser for help on using the repository browser.