source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_MultipleReduce.ipf @ 1070

Last change on this file since 1070 was 1050, checked in by srkline, 5 years ago

cleaning up a lot of the TODO items from the code.

File size: 14.6 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma version=5.0
3#pragma IgorVersion=6.1
4
5//*************************
6//
7// Procedures for the MRED panel to allow quick batch reduction of data files
8// -as of 8/01, use the new method of requiring only run numbers to select the datafiles
9//              and these data failes need not be consecutively numbered
10//
11//****note that much of this file is becoming obsolete as improved methods for
12//reducing multiple files are introduced. Some of these procedures may not last long***
13//
14//**************************
15
16//
17// TODO
18// -- these procedures are in the process of being updated for VSANS
19//    and are highly susceptible to change as user preferences bocome apparent
20
21
22//panel to allow reduction of a series of files using a selected  protocol
23//
24//main entry procedure to open the panel, initializing if necessary
25Proc V_ReduceMultipleFiles()
26       
27        DoWindow/F V_Multiple_Reduce_Panel
28        If(V_flag == 0)
29                V_InitializeMultReducePanel()
30                //draw panel
31                V_Multiple_Reduce_Panel()
32                //pop the protocol list
33                V_MRProtoPopMenuProc("",1,"")
34        Endif
35End
36
37//create the global variables needed to run the MReduce Panel
38//all are kept in root:Packages:NIST:VSANS:Globals:MRED
39//
40Proc V_InitializeMultReducePanel()
41
42        If(DataFolderExists("root:Packages:NIST:VSANS:Globals:MRED"))
43                //ok, do nothing
44        else
45                //no, create the folder and the globals
46                NewDataFolder/O root:Packages:NIST:VSANS:Globals:MRED
47//              String/G root:Packages:NIST:VSANS:Globals:MRED:gMRedMatchStr = "*"
48                PathInfo catPathName
49                If(V_flag==1)
50                        String dum = S_path
51                        String/G root:Packages:NIST:VSANS:Globals:MRED:gCatPathStr = dum
52                else
53                        String/G root:Packages:NIST:VSANS:Globals:MRED:gCatPathStr = "no path selected"
54                endif
55                String/G root:Packages:NIST:VSANS:Globals:MRED:gMRedList = "none"
56                String/G root:Packages:NIST:VSANS:Globals:MRED:gMRProtoList = "none"
57                String/G root:Packages:NIST:VSANS:Globals:MRED:gFileNumList=""
58
59
60        Endif
61End
62
63//panel recreation macro for the MRED panel
64//
65Window V_Multiple_Reduce_Panel()
66        PauseUpdate; Silent 1           // building window...
67        NewPanel /W=(535,72,951,228) /K=1 as "Multiple VSANS File Reduction"
68        ModifyPanel cbRGB=(64535,49151,48490)
69        ModifyPanel fixedSize=1
70        SetDrawLayer UserBack
71        DrawLine 7,30,422,30
72        SetVariable PathDisplay,pos={77,7},size={300,13},title="Path"
73        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"}
74        SetVariable PathDisplay,limits={-Inf,Inf,0},value= root:Packages:NIST:VSANS:Globals:MRED:gCatPathStr
75        Button PathButton,pos={3,3},size={70,20},proc=V_PickMRPathButton,title="Pick Path"
76        Button PathButton,help={"Select the folder containing the raw SANS data files"}
77        Button helpButton,pos={385,3},size={25,20},proc=V_ShowMRHelp,title="?"
78        Button helpButton,help={"Show the help file for reducing multiple files using the same protocol"}
79        PopupMenu MRFilesPopup,pos={3,44},size={167,19},proc=V_MRedPopMenuProc,title="File(s) to Reduce"
80        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."}
81        PopupMenu MRFilesPopup,mode=1,popvalue="none",value= #"root:Packages:NIST:VSANS:Globals:MRED:gMRedList"
82//      SetVariable MRList,pos={3,72},size={350,13},proc=FileNumberListProc,title="File number list: "
83//      SetVariable MRList,help={"Enter a comma delimited list of file numbers to reduce. Ranges can be entered using a dash."}
84//      SetVariable MRList,limits={-Inf,Inf,1},value= root:Packages:NIST:VSANS:Globals:MRED:gFileNumList
85        Button ReduceAllButton,pos={3,128},size={180,20},proc=V_ReduceAllPopupFiles,title="Reduce All Files in Popup"
86        Button ReduceAllButton,help={"This will reduce ALL of the files in the popup list, not just the top file."}
87        Button ReduceOneButton,pos={3,98},size={180,20},proc=V_ReduceTopPopupFile,title="Reduce Top File in Popup"
88        Button ReduceOneButton,help={"This will reduce TOP files in the popup list, not all of the files."}
89        Button DoneButton,pos={290,128},size={110,20},proc=V_MRDoneButtonProc,title="Done Reducing"
90        Button DoneButton,help={"When done reducing files, this will close this control panel."}
91        Button cat_short,pos={310,72},size={90,20},proc=V_ShowCatShort_MRED,title="File Catalog"
92        Button cat_short,help={"Use this button to generate a table with file header information. Very useful for identifying files."}
93//      Button show_cat_short,pos={280,98},size={120,20},proc=ShowCatShort_MRED,title="Show File Catalog"
94//      Button show_cat_short,help={"Use this button to bring the File Catalog window to the front."}
95//      Button sddList,pos={280,72},size={120,20},proc=ScatteringAtSDDTableButton,title="Files at SDD List"
96//      Button sddList,help={"Use this button to generate a table of scattering files at a given ample to detector distance."}
97//      Button acceptList,pos={280,98},size={120,20},proc=AcceptMREDList,title="Accept List"
98//      Button acceptList,help={"Accept the list of files to reduce."}
99        PopupMenu MRProto_pop,pos={3,72},size={119,19},proc=V_MRProtoPopMenuProc,title="Protocol "
100        PopupMenu MRProto_pop,help={"All of the data files in the popup will be reduced using this protocol"}
101        PopupMenu MRProto_pop,mode=1,popvalue="none",value= #"root:Packages:NIST:VSANS:Globals:MRED:gMRProtoList"
102EndMacro
103
104////simple procedure to bring the CAT TABLE to the front if it is present
105////alerts user, but does nothing else if CAT TABLE is not present
106////called by several panels
107////
108//Proc ShowCATWindow()
109//      DoWindow/F CatVSTable
110//      if(V_flag==0)
111//              DoAlert 0,"There is no File Catalog table. Use the File Catalog button to create one."
112//      Endif
113//End
114
115
116//function takes a list of filenames (just the name, no path , no extension)
117//that is COMMA delimited, and creates a new list that is also COMMA delimited
118//and contains the full path:file;vers for each file in the list
119//and ensures that files in returned list are RAW data , and can be found on disk
120//
121Function/S  V_FullNameListFromFileList(list)
122        String list
123       
124        String newList="",pathStr="",sepStr=","
125        PathInfo catPathName
126        if(V_flag==0)
127                Abort "CatPath does not exist - use Pick Path to select the data folder"
128        else
129                pathStr = S_Path
130        Endif
131       
132        Variable ii,num,ok
133        String fullName="",partialName="",tempName="",str
134         
135        num = ItemsInList(list,",")
136        ii=0
137        do
138                //take each item, and try to find the file (extensions for raw data should be ;1)
139                partialName = StringFromList(ii,list,",")       //COMMA separated list
140                if(strlen(partialName)!=0)              //null string items will be skipped
141                        tempName = V_FindValidFilename(partialName)             //will add the version # if needed     
142                        fullName = pathStr + tempName                                           //prepend the path (CAT)
143                       
144                        //discard strings that are not filenames (print the non-files)
145                        //make sure the file is really a RAW data file
146                        ok = V_CheckIfRawData(fullName)         // 1 if RAW, 0 if unknown type
147                        if (!ok)
148                                //write to cmd window that file was not a RAW SANS file
149                                str = "This file is not recognized as a RAW SANS data file: "+tempName+"\r"
150                                Print str
151                        else
152                                //yes, a valid file:path;ext that is RAW SANS
153                                //add the full path:file;ext +"," to the newList
154                                newList += fullName + sepStr
155                        Endif
156                endif           //partialName from original list != ""
157                ii+=1
158        while(ii<num)   //process all items in list
159       
160        Return(newList)
161End
162
163//takes a COMMA delimited list of files (full path:name;vers output of FullNameListFromFileList()
164//function and reduces each of the files in the list
165//the protocol is from the global string (wich is NOt in the MRED folder, but in the Protocols folder
166//
167Function V_DoReduceList(list)
168        String list
169       
170        //selected protocol is in a temporary global variable so that it can be used with execute
171        SVAR gMredProtoStr = root:Packages:NIST:VSANS:Globals:Protocols:gMredProtoStr
172        //input list is a comma delimited list of individual sample files to be reduced using the
173        //given protocol - based on WM proc "ExecuteCmdOnList()"
174        //input filenames must be full path:file;ext, so they can be found on disk
175       
176        String cmdTemplate = "V_ExecuteProtocol(\"" + gMredProtoStr + "\",\"%s\")"
177        String theItem
178        Variable index=0
179        String cmd
180        Variable num = ItemsInList(list,",")
181        do
182                theItem = StringFromList(index,list,",")        //COMMA separated list
183                if(strlen(theItem)!=0)
184                        sprintf cmd,cmdTemplate,theItem         //null string items will be skipped
185                        //Print "cmd = ",cmd
186                        Execute cmd
187                endif
188                index +=1
189        while(index<num)        //exit after all items have been processed
190       
191        //will continue until all files in list are reduced, according to gMredProtoStr protocol
192        return(0)
193End
194
195//executed when a list of filenumbers is entered in the box
196//responds as if the file popup was hit, to update the popup list contents
197//
198Function V_FileNumberListProc(ctrlName,varNum,varStr,varName) : SetVariableControl
199        String ctrlName
200        Variable varNum
201        String varStr
202        String varName
203               
204        V_MRedPopMenuProc("MRFilesPopup",0,"")
205End
206
207Proc V_ShowMRHelp(ctrlName) : ButtonControl
208        String ctrlName
209
210        DisplayHelpTopic/Z/K=1 "VSANS Data Reduction Tutorial[Reduce Multiple Files]"
211        if(V_flag !=0)
212                DoAlert 0,"The VSANS Data Reduction Tutorial Help file could not be found"
213        endif
214End
215
216//button procedure for bringing File Catalog window to front, if it exists
217//so that the user can see what's going on
218//
219Proc V_ShowCatShort_MRED(ctrlName) : ButtonControl
220        String ctrlName
221
222        V_BuildCatVeryShortTable()
223End
224
225//allows the user to set the path to the local folder that contains the SANS data
226//2 global strings are reset after the path "catPathName" is reset in the function PickPath()
227// this path is the only one, the globals are simply for convenience
228//
229Function V_PickMRPathButton(PathButton) : ButtonControl
230        String PathButton
231       
232        V_PickPath()            //sets the main global path string for catPathName
233       
234        //then update the "local" copy in the MRED subfolder
235        PathInfo/S catPathName
236        String dum = S_path
237        if (V_flag == 0)
238                //path does not exist - no folder selected
239                String/G root:Packages:NIST:VSANS:Globals:MRED:gCatPathStr = "no folder selected"
240        else
241                String/G root:Packages:NIST:VSANS:Globals:MRED:gCatPathStr = dum
242        endif
243       
244        //Update the pathStr variable box
245        ControlUpdate/W=Multiple_Reduce_Panel $"PathDisplay"
246       
247        //then update the popup list
248        V_MRedPopMenuProc("MRFilesPopup",1,"")
249End
250
251// changes the contents of the popup list of files to be reduced based on the
252// range of file numbers entered in the text box
253//
254Function V_MREDPopMenuProc(MRFilesPopup,popNum,popStr) : PopupMenuControl
255        String MRFilesPopup
256        Variable popNum
257        String popStr
258
259        String list = V_GetValidMRedPopupList()
260//     
261        String/G root:Packages:NIST:VSANS:Globals:MRED:gMredList = list
262        ControlUpdate MRFilesPopup
263
264End
265
266// get a  list of all of the sample files, based on intent
267//
268Function/S V_GetValidMRedPopupList()
269
270        String semiList = V_GetSAMList()
271
272        return(semiList)
273End
274
275//returns a list of the available protocol waves in the protocols folder
276//removes "CreateNew", "tempProtocol" and "fakeProtocol" from list (if they exist)
277//since these waves do not contain valid protocol instructions
278//
279Function V_MRProtoPopMenuProc(MRProto_pop,popNum,popStr) : PopupMenuControl
280        String MRProto_pop
281        Variable popNum
282        String popStr
283
284        //get list of currently valid protocols, and put it in the popup (the global list)
285        //excluding "tempProtocol" and "CreateNew" if they exist
286        SetDataFolder root:Packages:NIST:VSANS:Globals:Protocols
287        String list = WaveList("*",";","")
288        SetDataFolder root:
289       
290        //remove items from the list (list is unchanged if the items are not present)
291        list = RemoveFromList("CreateNew", list, ";")
292        list = RemoveFromList("tempProtocol", list, ";")
293        list = RemoveFromList("fakeProtocol", list, ";")
294        list = RemoveFromList("PanelNameW", list, ";")
295        list = RemoveFromList("Beg_pts", list, ";")
296        list = RemoveFromList("End_pts", list, ";")
297        list = RemoveFromList("trimUpdate", list, ";")
298       
299        String/G root:Packages:NIST:VSANS:Globals:MRED:gMRProtoList = list
300        ControlUpdate MRProto_pop
301
302End
303
304//button procedure to close the panel, and the SDD table if if was generated
305//
306Function V_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 V_Multiple_Reduce_Panel
314       
315        DoWindow/K SDDTable     
316        KillDataFolder root:Packages:NIST:VSANS:Globals:MRED
317End
318
319//button action function caled to reduce all of the files in the "file" popup
320//using the protocol specified in the "protocol" popup
321//converts list of files into comma delimited list of full path:filename;vers
322//that can be reduced as a list
323// also sets the current protocol to a global accessible to the list processing routine
324//
325Function V_ReduceAllPopupFiles(ctrlName) : ButtonControl
326        String ctrlName
327       
328        //popup (and global list) is a semicolon separated list of files, WITHOUT extensions
329        //transform this list into a COMMA delimited list of FULL filenames, and then they can be processed
330       
331        SVAR semiList = root:Packages:NIST:VSANS:Globals:MRED:gMredList
332       
333        //process each item in the list, and generate commaList
334        Variable num = ItemsInList(semiList,";" )
335        Variable ii=0
336        String commaList = "",item = ""
337        do
338                item = StringFromList(ii, semiList  ,";" )
339                commaList += item + ","
340                ii+=1
341        while(ii<num)
342        //080601 - send only the comma list of filenames, not full path:name   
343        //commaList = FullNameListFromFileList(commaList)               //gets the full file names (including extension) for each item in list
344
345        //get the selected protocol, and pass as a global
346        ControlInfo MRProto_pop
347        String protocolNameStr = S_Value
348        String/G root:Packages:NIST:VSANS:Globals:Protocols:gMredProtoStr = "root:Packages:NIST:VSANS:Globals:Protocols:"+protocolNameStr
349       
350        //also set this as the current protocol, for the function that writes the averaged waves
351        String/G root:Packages:NIST:VSANS:Globals:Protocols:gProtoStr = protocolNameStr
352       
353        //reduce all the files in the list here, using the global protocol(the full reference)
354        //DoReduceList is found in MultipleReduce.ipf
355        V_DoReduceList(commaList)
356       
357        Return 0
358End
359
360
361//
362// reduce just the top file on the popup
363//
364Function V_ReduceTopPopupFile(ctrlName) : ButtonControl
365        String ctrlName
366
367        // get just the top file from the popup
368        ControlInfo MRFilesPopup
369        String commaList = S_Value + ","
370
371        //get the selected protocol, and pass as a global
372        ControlInfo MRProto_pop
373        String protocolNameStr = S_Value
374        String/G root:Packages:NIST:VSANS:Globals:Protocols:gMredProtoStr = "root:Packages:NIST:VSANS:Globals:Protocols:"+protocolNameStr
375       
376        //also set this as the current protocol, for the function that writes the averaged waves
377        String/G root:Packages:NIST:VSANS:Globals:Protocols:gProtoStr = protocolNameStr
378       
379        //reduce all the files in the list here, using the global protocol(the full reference)
380        //DoReduceList is found in MultipleReduce.ipf
381        V_DoReduceList(commaList)
382       
383        Return 0
384End
385
Note: See TracBrowser for help on using the repository browser.