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

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

added a few corrections to the reduction:

Added sample apertures to the patch panel so that they can be corrected

A flag is now written to the data files if the "flip" has been done, and it will refuse to flip again. This flag can be reset if something goes wrong.

Multiple reduce now allows run numbers to be entered as is for SANS,

Filtering of files for the protocol panel should be better behaved now.

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