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

Last change on this file since 418 was 412, checked in by ajj, 14 years ago

More reorg.

File size: 18.0 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma version=5.0
3#pragma IgorVersion=6.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]"
203        if(V_flag !=0)
204                DoAlert 0,"The SANS Data Reduction Tutorial Help file could not be found"
205        endif
206End
207
208//button procedure for bringing File Catalog window to front, if it exists
209//so that the user can see what's going on
210//
211Proc ShowCatShort_MRED(ctrlName) : ButtonControl
212        String ctrlName
213
214        ShowCATWindow()
215End
216
217//allows the user to set the path to the local folder that contains the SANS data
218//2 global strings are reset after the path "catPathName" is reset in the function PickPath()
219// this path is the only one, the globals are simply for convenience
220//
221Function PickMRPathButton(PathButton) : ButtonControl
222        String PathButton
223       
224        PickPath()              //sets the main global path string for catPathName
225       
226        //then update the "local" copy in the MRED subfolder
227        PathInfo/S catPathName
228        String dum = S_path
229        if (V_flag == 0)
230                //path does not exist - no folder selected
231                String/G root:myGlobals:MRED:gCatPathStr = "no folder selected"
232        else
233                String/G root:myGlobals:MRED:gCatPathStr = dum
234        endif
235       
236        //Update the pathStr variable box
237        ControlUpdate/W=Multiple_Reduce_Panel $"PathDisplay"
238       
239        //then update the popup list
240        MRedPopMenuProc("MRFilesPopup",1,"")
241End
242
243// changes the contents of the popup list of files to be reduced based on the
244// range of file numbers entered in the text box
245//
246Function MREDPopMenuProc(MRFilesPopup,popNum,popStr) : PopupMenuControl
247        String MRFilesPopup
248        Variable popNum
249        String popStr
250
251        String list = GetValidMRedPopupList()
252//     
253        String/G root:myGlobals:MRED:gMredList = list
254        ControlUpdate MRFilesPopup
255
256End
257
258//parses the file number list to get valid raw data filenames for reduction
259// -if the numbers and full ranges can be translated to correspond to actual files
260// on disk, the popup list is updated - otherwise the offending number is reported
261// and the user must fix the problem before any reduction can be done
262//
263//ParseRunNumberList() does the work, as it does for the protocol panel
264//
265Function/S GetValidMRedPopupList()
266
267        String commaList="",semiList=""
268        SVAR numList=root:myGLobals:MRED:gFileNumList
269       
270        commaList = ParseRunNumberList(numList)
271        //convert commaList to a semicolon delimited list
272        Variable num=ItemsinList(commaList,","),ii
273        for(ii=0;ii<num;ii+=1)
274                semiList += StringFromList(ii, commaList  ,",") + ";"
275        endfor
276//      print semiList
277//sort the list
278        semiList = SortList(semiList,";",0)
279        return(semiList)
280End
281
282//returns a list of the available protocol waves in the protocols folder
283//removes "CreateNew", "tempProtocol" and "fakeProtocol" from list (if they exist)
284//since these waves do not contain valid protocol instructions
285//
286Function MRProtoPopMenuProc(MRProto_pop,popNum,popStr) : PopupMenuControl
287        String MRProto_pop
288        Variable popNum
289        String popStr
290
291        //get list of currently valid protocols, and put it in the popup (the global list)
292        //excluding "tempProtocol" and "CreateNew" if they exist
293        SetDataFolder root:myGlobals:Protocols
294        String list = WaveList("*",";","")
295        SetDataFolder root:
296       
297        //remove items from the list (list is unchanged if the items are not present)
298        list = RemoveFromList("CreateNew", list, ";")
299        list = RemoveFromList("tempProtocol", list, ";")
300        list = RemoveFromList("fakeProtocol", list, ";")
301       
302        String/G root:myGlobals:MRED:gMRProtoList = list
303        ControlUpdate MRProto_pop
304
305End
306
307//button procedure to close the panel
308//
309Function MRDoneButtonProc(ctrlName) : ButtonControl
310        String ctrlName
311
312        // this button will make sure all files are closed
313        //and close the panel
314
315        Close/A
316        DoWindow/K Multiple_Reduce_Panel
317        KillDataFolder root:myGlobals:MRED
318End
319
320//button action function caled to reduce all of the files in the "file" popup
321//using the protocol specified in the "protocol" popup
322//converts list of files into comma delimited list of full path:filename;vers
323//that can be reduced as a list
324// also sets the current protocol to a global accessible to the list processing routine
325//
326Function ReduceAllPopupFiles(ctrlName) : ButtonControl
327        String ctrlName
328       
329        //popup (and global list) is a semicolon separated list of files, WITHOUT extensions
330        //transform this list into a COMMA delimited list of FULL filenames, and then they can be processed
331       
332        SVAR semiList = root:myGlobals:MRED:gMredList
333       
334        //process each item in the list, and generate commaList
335        Variable num = ItemsInList(semiList,";" )
336        Variable ii=0
337        String commaList = "",item = ""
338        do
339                item = StringFromList(ii, semiList  ,";" )
340                commaList += item + ","
341                ii+=1
342        while(ii<num)
343        //080601 - send only the comma list of filenames, not full path:name   
344        //commaList = FullNameListFromFileList(commaList)               //gets the full file names (including extension) for each item in list
345
346        //get the selected protocol, and pass as a global
347        ControlInfo MRProto_pop
348        String protocolNameStr = S_Value
349        String/G root:myGlobals:Protocols:gMredProtoStr = "root:myGlobals:Protocols:"+protocolNameStr
350       
351        //also set this as the current protocol, for the function that writes the averaged waves
352        String/G root:myGlobals:Protocols:gProtoStr = protocolNameStr
353       
354        //reduce all the files in the list here, using the global protocol(the full reference)
355        //DoReduceList is found in MultipleReduce.ipf
356        DoReduceList(commaList)
357       
358        Return 0
359End
360
361
362//****************************
363// below are very old procedures, not used (maybe of no value)
364
365
366//little used procedure - works only with menu selections of list processing
367//
368Proc ClearFileList()
369        String/G root:myGlobals:Protocols:gReduceList=""
370        DoAlert 0,"The file reduction list has been initialized"
371        ShowList()
372End
373
374//old procedure, (not used) - data is saved to the catPathName folder, the same folder
375//where the data came from in the first place, avoiding extra paths
376Proc PickSaveFolder()
377        NewPath/O/M="pick folder for averaged data" Save_path
378        PathInfo/S Save_path
379        if (V_flag == 0)
380                //path does not exist - no folder selected
381                Print "No destination path selected - save dialog will be presented"
382        endif
383End
384
385//little used reduction procedure, asks for protocol, then uses this protocol
386//to reduce the files in a list built by selecting files from the CAT window
387//did not get favorable reviews from users and may not be kept
388//
389Proc ReduceFilesInList()
390
391        String protocolName=""
392
393        //generate a list of valid path:file;ext items, comma separated as the input filenames for
394        //ExecuteProtocol(), their final destination
395       
396        String list = root:myGlobals:Protocols:gReduceList
397        Variable num = ItemsInList(list,"," )
398       
399        list = FullNameListFromFileList(list)
400       
401        //Print list
402       
403        //get protocolName in the same manner as "recallprotocol" button
404        //but remember to set a global for  Execute to use
405        SetDataFolder root:myGlobals:Protocols          //must be in protocols folder before executing this Proc       
406        Execute "PickAProtocol()"
407        //get the selected protocol wave choice through a global string variable
408        protocolName = root:myGlobals:Protocols:gProtoStr
409        //If "CreateNew" was selected, ask user to try again
410        if(cmpstr("CreateNew",protocolName) == 0)
411                Abort "CreateNew is for making a new Protocol. Select a previously saved Protocol"
412        Endif
413        SetDataFolder root:
414//      String/G root:myGlobals:Protocols:gMredProtoStr = "root:myGlobals:Protocols:"+protocolName
415       
416        //pass the full path to the protocol for ExecuteProtocol() later
417        //Print gMredProtoStr," protocol name"
418       
419        DoReduceList(list)
420       
421//      KillStrings/Z gMredProtoStr
422       
423//      SetDataFolder root:
424       
425End
426
427//displays the current contents of the FileList window, for multiple file reduction
428//little used function and may not be kept
429//
430Proc ShowList()
431       
432        DoWindow/F ListWin
433        If(V_Flag ==0)
434                NewNotebook/F=1/N=ListWin as "File List"
435        Endif
436        //clear old window contents, reset the path
437        Notebook ListWin,selection={startOfFile,EndOfFile}
438        Notebook ListWin,text="\r"
439       
440        //Write out each item of the comma-delimited list to the notebook
441        String list = root:myGlobals:Protocols:gReduceList
442        Variable index = 0
443        String theItem=""
444        Variable num = ItemsInList(list,"," )
445        do
446                theItem = StringFromList(index,list,",")        //COMMA separated list
447                if(strlen(theItem)!=0)
448                        Notebook ListWin,text=(theItem+"\r")            //null string items will be skipped
449                endif
450                index +=1
451        while(index<num)        //exit after all items are printed
452End
453
454
455//little used function to add the selected file from the CAT/SHORT window to the fileList
456//so that the list of files can be processed batchwise
457//
458Proc AddSelectionToList()
459
460        if(WinType("CatWin")==0)
461                Abort "There is no CAT/SHORT window. Use the CAT/SHORT button to create one."
462        Endif
463        GetSelection notebook,CatWin,3
464        //build a comma separated list of names
465        //does the global variable exist?
466        if(exists("root:myGlobals:Protocols:gReduceList")==2)           //a string exists
467                //do nothing extra
468        else
469                //create (initialize) the global string
470                String/G root:myGlobals:Protocols:gReduceList = ""
471        endif
472        String list = root:myGlobals:Protocols:gReduceList
473        list += S_Selection + ","
474        String/G root:myGlobals:Protocols:gReduceList = list            //reassign the global
475       
476       
477End
478
479//little used function to remove the selected file in the CAT/SHORT window from the fileList
480Proc RemoveFileFromList()
481        //if(WinType("CatWin")==0)
482                //Abort "There is no CAT/SHORT window. Use the CAT/SHORT button to create one."
483        //Endif
484        GetSelection notebook,ListWin,3
485        //remove the selected item from the list
486        String list = root:myGlobals:Protocols:gReduceList
487        list = RemoveFromList(S_selection,list,",")
488        String/G root:myGlobals:Protocols:gReduceList = list
489       
490        ShowList()
491End
492
493// based on WM PossiblyQuoteList(list, separator)
494//      Input is a list of names that may contain liberal names.
495//      Returns the list with liberal names quoted.
496//      Example:
497//              Input:          "wave0;wave 1;"
498//              Output:         "wave0;'wave 1';"
499//      The list is expected to be a standard separated list, like "wave0;wave1;wave2;".
500//*****unused*******
501Function/S PossiblyQuoteFileList(list, separator)
502        String list
503        String separator
504       
505        String item, outputList = ""
506        Variable ii= 0
507        Variable items= ItemsInList(list, separator)
508        do
509                if (ii >= items)                        // no more items?
510                        break
511                endif
512                item= StringFromList(ii, list, separator)
513                outputList += PossiblyQuoteName(item) + separator
514                ii += 1
515        while(1)
516        return outputList
517End
518
Note: See TracBrowser for help on using the repository browser.