source: sans/SANSReduction/branches/kline_29MAR07/Put in User Procedures/SANS_Reduction_v5.00/MultipleReduce.ipf @ 82

Last change on this file since 82 was 76, checked in by srkline, 16 years ago

2nd pass of pulling out NCNR calls. Also cleared a lot of deadwood from the code, removing depricated functions that were mostly already commented out.

File size: 17.9 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma version=5.0
3#pragma IgorVersion=4.0
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={292,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        PopupMenu MRProto_pop,pos={3,98},size={119,19},proc=MRProtoPopMenuProc,title="Protocol "
92        PopupMenu MRProto_pop,help={"All of the data files in the popup will be reduced using this protocol"}
93        PopupMenu MRProto_pop,mode=1,popvalue="none",value= #"root:myGlobals:MRED:gMRProtoList"
94EndMacro
95
96//simple procedure to bring the CAT TABLE to the front if it is present
97//alerts user, but does nothing else if CAT TABLE is not present
98//called by several panels
99//
100Proc ShowCATWindow()
101        DoWindow/F CatVSTable
102        if(V_flag==0)
103                DoAlert 0,"There is no File Catalog table. Use the File Catalog button to create one."
104        Endif
105End
106
107
108//function takes a list of filenames (just the name, no path , no extension)
109//that is COMMA delimited, and creates a new list that is also COMMA delimited
110//and contains the full path:file;vers for each file in the list
111//and ensures that files in returned list are RAW data , and can be found on disk
112//
113Function/S  FullNameListFromFileList(list)
114        String list
115       
116        String newList="",pathStr="",sepStr=","
117        PathInfo catPathName
118        if(V_flag==0)
119                Abort "CatPath does not exist - use Pick Path to select the data folder"
120        else
121                pathStr = S_Path
122        Endif
123       
124        Variable ii,num,ok
125        String fullName="",partialName="",tempName="",str
126         
127        num = ItemsInList(list,",")
128        ii=0
129        do
130                //take each item, and try to find the file (extensions for raw data should be ;1)
131                partialName = StringFromList(ii,list,",")       //COMMA separated list
132                if(strlen(partialName)!=0)              //null string items will be skipped
133                        tempName = FindValidFilename(partialName)               //will add the version # if needed     
134                        fullName = pathStr + tempName                                           //prepend the path (CAT)
135                       
136                        //discard strings that are not filenames (print the non-files)
137                        //make sure the file is really a RAW data file
138                        ok = CheckIfRawData(fullName)           // 1 if RAW, 0 if unknown type
139                        if (!ok)
140                                //write to cmd window that file was not a RAW SANS file
141                                str = "This file is not recognized as a RAW SANS data file: "+tempName+"\r"
142                                Print str
143                        else
144                                //yes, a valid file:path;ext that is RAW SANS
145                                //add the full path:file;ext +"," to the newList
146                                newList += fullName + sepStr
147                        Endif
148                endif           //partialName from original list != ""
149                ii+=1
150        while(ii<num)   //process all items in list
151       
152        Return(newList)
153End
154
155//takes a COMMA delimited list of files (full path:name;vers output of FullNameListFromFileList()
156//function and reduces each of the files in the list
157//the protocol is from the global string (wich is NOt in the MRED folder, but in the Protocols folder
158//
159Function DoReduceList(list)
160        String list
161       
162        //selected protocol is in a temporary global variable so that it can be used with execute
163        SVAR gMredProtoStr = root:myGlobals:Protocols:gMredProtoStr
164        //input list is a comma delimited list of individual sample files to be reduced using the
165        //given protocol - based on WM proc "ExecuteCmdOnList()"
166        //input filenames must be full path:file;ext, so they can be found on disk
167       
168        String cmdTemplate = "ExecuteProtocol(\"" + gMredProtoStr + "\",\"%s\")"
169        String theItem
170        Variable index=0
171        String cmd
172        Variable num = ItemsInList(list,",")
173        do
174                theItem = StringFromList(index,list,",")        //COMMA separated list
175                if(strlen(theItem)!=0)
176                        sprintf cmd,cmdTemplate,theItem         //null string items will be skipped
177                        //Print "cmd = ",cmd
178                        Execute cmd
179                endif
180                index +=1
181        while(index<num)        //exit after all items have been processed
182       
183        //will continue until all files in list are reduced, according to gMredProtoStr protocol
184        return(0)
185End
186
187//executed when a list of filenumbers is entered in the box
188//responds as if the file popup was hit, to update the popup list contents
189//
190Function FileNumberListProc(ctrlName,varNum,varStr,varName) : SetVariableControl
191        String ctrlName
192        Variable varNum
193        String varStr
194        String varName
195               
196        MRedPopMenuProc("MRFilesPopup",0,"")
197End
198
199Proc ShowMRHelp(ctrlName) : ButtonControl
200        String ctrlName
201
202        DisplayHelpTopic/K=1 "SANS Data Reduction Tutorial[Reduce Multiple Files]"
203End
204
205//button procedure for bringing File Catalog window to front, if it exists
206//so that the user can see what's going on
207//
208Proc ShowCatShort_MRED(ctrlName) : ButtonControl
209        String ctrlName
210
211        ShowCATWindow()
212End
213
214//allows the user to set the path to the local folder that contains the SANS data
215//2 global strings are reset after the path "catPathName" is reset in the function PickPath()
216// this path is the only one, the globals are simply for convenience
217//
218Function PickMRPathButton(PathButton) : ButtonControl
219        String PathButton
220       
221        PickPath()              //sets the main global path string for catPathName
222       
223        //then update the "local" copy in the MRED subfolder
224        PathInfo/S catPathName
225        String dum = S_path
226        if (V_flag == 0)
227                //path does not exist - no folder selected
228                String/G root:myGlobals:MRED:gCatPathStr = "no folder selected"
229        else
230                String/G root:myGlobals:MRED:gCatPathStr = dum
231        endif
232       
233        //Update the pathStr variable box
234        ControlUpdate/W=Multiple_Reduce_Panel $"PathDisplay"
235       
236        //then update the popup list
237        MRedPopMenuProc("MRFilesPopup",1,"")
238End
239
240// changes the contents of the popup list of files to be reduced based on the
241// range of file numbers entered in the text box
242//
243Function MREDPopMenuProc(MRFilesPopup,popNum,popStr) : PopupMenuControl
244        String MRFilesPopup
245        Variable popNum
246        String popStr
247
248        String list = GetValidMRedPopupList()
249//     
250        String/G root:myGlobals:MRED:gMredList = list
251        ControlUpdate MRFilesPopup
252
253End
254
255//parses the file number list to get valid raw data filenames for reduction
256// -if the numbers and full ranges can be translated to correspond to actual files
257// on disk, the popup list is updated - otherwise the offending number is reported
258// and the user must fix the problem before any reduction can be done
259//
260//ParseRunNumberList() does the work, as it does for the protocol panel
261//
262Function/S GetValidMRedPopupList()
263
264        String commaList="",semiList=""
265        SVAR numList=root:myGLobals:MRED:gFileNumList
266       
267        commaList = ParseRunNumberList(numList)
268        //convert commaList to a semicolon delimited list
269        Variable num=ItemsinList(commaList,","),ii
270        for(ii=0;ii<num;ii+=1)
271                semiList += StringFromList(ii, commaList  ,",") + ";"
272        endfor
273//      print semiList
274//sort the list
275        semiList = SortList(semiList,";",0)
276        return(semiList)
277End
278
279//returns a list of the available protocol waves in the protocols folder
280//removes "CreateNew", "tempProtocol" and "fakeProtocol" from list (if they exist)
281//since these waves do not contain valid protocol instructions
282//
283Function MRProtoPopMenuProc(MRProto_pop,popNum,popStr) : PopupMenuControl
284        String MRProto_pop
285        Variable popNum
286        String popStr
287
288        //get list of currently valid protocols, and put it in the popup (the global list)
289        //excluding "tempProtocol" and "CreateNew" if they exist
290        SetDataFolder root:myGlobals:Protocols
291        String list = WaveList("*",";","")
292        SetDataFolder root:
293       
294        //remove items from the list (list is unchanged if the items are not present)
295        list = RemoveFromList("CreateNew", list, ";")
296        list = RemoveFromList("tempProtocol", list, ";")
297        list = RemoveFromList("fakeProtocol", list, ";")
298       
299        String/G root:myGlobals:MRED:gMRProtoList = list
300        ControlUpdate MRProto_pop
301
302End
303
304//button procedure to close the panel
305//
306Function MRDoneButtonProc(ctrlName) : ButtonControl
307        String ctrlName
308
309        // this button will make sure all files are closed
310        //and close the panel
311
312        Close/A
313        DoWindow/K Multiple_Reduce_Panel
314        KillDataFolder root:myGlobals:MRED
315End
316
317//button action function caled to reduce all of the files in the "file" popup
318//using the protocol specified in the "protocol" popup
319//converts list of files into comma delimited list of full path:filename;vers
320//that can be reduced as a list
321// also sets the current protocol to a global accessible to the list processing routine
322//
323Function ReduceAllPopupFiles(ctrlName) : ButtonControl
324        String ctrlName
325       
326        //popup (and global list) is a semicolon separated list of files, WITHOUT extensions
327        //transform this list into a COMMA delimited list of FULL filenames, and then they can be processed
328       
329        SVAR semiList = root:myGlobals:MRED:gMredList
330       
331        //process each item in the list, and generate commaList
332        Variable num = ItemsInList(semiList,";" )
333        Variable ii=0
334        String commaList = "",item = ""
335        do
336                item = StringFromList(ii, semiList  ,";" )
337                commaList += item + ","
338                ii+=1
339        while(ii<num)
340        //080601 - send only the comma list of filenames, not full path:name   
341        //commaList = FullNameListFromFileList(commaList)               //gets the full file names (including extension) for each item in list
342
343        //get the selected protocol, and pass as a global
344        ControlInfo MRProto_pop
345        String protocolNameStr = S_Value
346        String/G root:myGlobals:Protocols:gMredProtoStr = "root:myGlobals:Protocols:"+protocolNameStr
347       
348        //also set this as the current protocol, for the function that writes the averaged waves
349        String/G root:myGlobals:Protocols:gProtoStr = protocolNameStr
350       
351        //reduce all the files in the list here, using the global protocol(the full reference)
352        //DoReduceList is found in MultipleReduce.ipf
353        DoReduceList(commaList)
354       
355        Return 0
356End
357
358
359//****************************
360// below are very old procedures, not used (maybe of no value)
361
362
363//little used procedure - works only with menu selections of list processing
364//
365Proc ClearFileList()
366        String/G root:myGlobals:Protocols:gReduceList=""
367        DoAlert 0,"The file reduction list has been initialized"
368        ShowList()
369End
370
371//old procedure, (not used) - data is saved to the catPathName folder, the same folder
372//where the data came from in the first place, avoiding extra paths
373Proc PickSaveFolder()
374        NewPath/O/M="pick folder for averaged data" Save_path
375        PathInfo/S Save_path
376        if (V_flag == 0)
377                //path does not exist - no folder selected
378                Print "No destination path selected - save dialog will be presented"
379        endif
380End
381
382//little used reduction procedure, asks for protocol, then uses this protocol
383//to reduce the files in a list built by selecting files from the CAT window
384//did not get favorable reviews from users and may not be kept
385//
386Proc ReduceFilesInList()
387
388        String protocolName=""
389
390        //generate a list of valid path:file;ext items, comma separated as the input filenames for
391        //ExecuteProtocol(), their final destination
392       
393        String list = root:myGlobals:Protocols:gReduceList
394        Variable num = ItemsInList(list,"," )
395       
396        list = FullNameListFromFileList(list)
397       
398        //Print list
399       
400        //get protocolName in the same manner as "recallprotocol" button
401        //but remember to set a global for  Execute to use
402        SetDataFolder root:myGlobals:Protocols          //must be in protocols folder before executing this Proc       
403        Execute "PickAProtocol()"
404        //get the selected protocol wave choice through a global string variable
405        protocolName = root:myGlobals:Protocols:gProtoStr
406        //If "CreateNew" was selected, ask user to try again
407        if(cmpstr("CreateNew",protocolName) == 0)
408                Abort "CreateNew is for making a new Protocol. Select a previously saved Protocol"
409        Endif
410        SetDataFolder root:
411//      String/G root:myGlobals:Protocols:gMredProtoStr = "root:myGlobals:Protocols:"+protocolName
412       
413        //pass the full path to the protocol for ExecuteProtocol() later
414        //Print gMredProtoStr," protocol name"
415       
416        DoReduceList(list)
417       
418//      KillStrings/Z gMredProtoStr
419       
420//      SetDataFolder root:
421       
422End
423
424//displays the current contents of the FileList window, for multiple file reduction
425//little used function and may not be kept
426//
427Proc ShowList()
428       
429        DoWindow/F ListWin
430        If(V_Flag ==0)
431                NewNotebook/F=1/N=ListWin as "File List"
432        Endif
433        //clear old window contents, reset the path
434        Notebook ListWin,selection={startOfFile,EndOfFile}
435        Notebook ListWin,text="\r"
436       
437        //Write out each item of the comma-delimited list to the notebook
438        String list = root:myGlobals:Protocols:gReduceList
439        Variable index = 0
440        String theItem=""
441        Variable num = ItemsInList(list,"," )
442        do
443                theItem = StringFromList(index,list,",")        //COMMA separated list
444                if(strlen(theItem)!=0)
445                        Notebook ListWin,text=(theItem+"\r")            //null string items will be skipped
446                endif
447                index +=1
448        while(index<num)        //exit after all items are printed
449End
450
451
452//little used function to add the selected file from the CAT/SHORT window to the fileList
453//so that the list of files can be processed batchwise
454//
455Proc AddSelectionToList()
456
457        if(WinType("CatWin")==0)
458                Abort "There is no CAT/SHORT window. Use the CAT/SHORT button to create one."
459        Endif
460        GetSelection notebook,CatWin,3
461        //build a comma separated list of names
462        //does the global variable exist?
463        if(exists("root:myGlobals:Protocols:gReduceList")==2)           //a string exists
464                //do nothing extra
465        else
466                //create (initialize) the global string
467                String/G root:myGlobals:Protocols:gReduceList = ""
468        endif
469        String list = root:myGlobals:Protocols:gReduceList
470        list += S_Selection + ","
471        String/G root:myGlobals:Protocols:gReduceList = list            //reassign the global
472       
473       
474End
475
476//little used function to remove the selected file in the CAT/SHORT window from the fileList
477Proc RemoveFileFromList()
478        //if(WinType("CatWin")==0)
479                //Abort "There is no CAT/SHORT window. Use the CAT/SHORT button to create one."
480        //Endif
481        GetSelection notebook,ListWin,3
482        //remove the selected item from the list
483        String list = root:myGlobals:Protocols:gReduceList
484        list = RemoveFromList(S_selection,list,",")
485        String/G root:myGlobals:Protocols:gReduceList = list
486       
487        ShowList()
488End
489
490// based on WM PossiblyQuoteList(list, separator)
491//      Input is a list of names that may contain liberal names.
492//      Returns the list with liberal names quoted.
493//      Example:
494//              Input:          "wave0;wave 1;"
495//              Output:         "wave0;'wave 1';"
496//      The list is expected to be a standard separated list, like "wave0;wave1;wave2;".
497//*****unused*******
498Function/S PossiblyQuoteFileList(list, separator)
499        String list
500        String separator
501       
502        String item, outputList = ""
503        Variable ii= 0
504        Variable items= ItemsInList(list, separator)
505        do
506                if (ii >= items)                        // no more items?
507                        break
508                endif
509                item= StringFromList(ii, list, separator)
510                outputList += PossiblyQuoteName(item) + separator
511                ii += 1
512        while(1)
513        return outputList
514End
515
Note: See TracBrowser for help on using the repository browser.