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

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

lots of changes here:
many little fixes to clean up TODO items and marke them DONE

changed the handling of the panel "gap" to split the gap evenly. Q-calculations have been re-verified with this change.

re-named the list of "bin Type" values, and added a few more choices. Streamlined how the averaging and plotting works with this list so that it can be more easily modified as different combinations of binning are envisioned. This resulted in a lot of excess code being cut out and replaced with cleaner logic. This change has also been verified to work as intended.

Attenuation is now always calculated from the table. The table also by (NEW) definition has values for the white beam (one waelength) and graphite (multiple possible wavelengths) where the wavelengths are artificially scaled (*1000) or *1e6) so that the interpolations can be done internally without the need for multiple attenuator tables.

File size: 14.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,44},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,72},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: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,72},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//
256Function/S V_GetValidMRedPopupList()
257
258        String semiList = V_GetSAMList()
259
260        return(semiList)
261End
262
263//returns a list of the available protocol waves in the protocols folder
264//removes "CreateNew", "tempProtocol" and "fakeProtocol" from list (if they exist)
265//since these waves do not contain valid protocol instructions
266//
267Function V_MRProtoPopMenuProc(MRProto_pop,popNum,popStr) : PopupMenuControl
268        String MRProto_pop
269        Variable popNum
270        String popStr
271
272        //get list of currently valid protocols, and put it in the popup (the global list)
273        //excluding "tempProtocol" and "CreateNew" if they exist
274        SetDataFolder root:Packages:NIST:VSANS:Globals:Protocols
275        String list = WaveList("*",";","")
276        SetDataFolder root:
277       
278        //remove items from the list (list is unchanged if the items are not present)
279        list = RemoveFromList("CreateNew", list, ";")
280        list = RemoveFromList("tempProtocol", list, ";")
281        list = RemoveFromList("fakeProtocol", list, ";")
282        list = RemoveFromList("PanelNameW", list, ";")
283        list = RemoveFromList("Beg_pts", list, ";")
284        list = RemoveFromList("End_pts", list, ";")
285        list = RemoveFromList("trimUpdate", list, ";")
286       
287        String/G root:Packages:NIST:VSANS:Globals:MRED:gMRProtoList = list
288        ControlUpdate MRProto_pop
289
290End
291
292//button procedure to close the panel, and the SDD table if if was generated
293//
294Function V_MRDoneButtonProc(ctrlName) : ButtonControl
295        String ctrlName
296
297        // this button will make sure all files are closed
298        //and close the panel
299
300        Close/A
301        DoWindow/K V_Multiple_Reduce_Panel
302       
303        DoWindow/K SDDTable     
304        KillDataFolder root:Packages:NIST:VSANS:Globals:MRED
305End
306
307//button action function caled to reduce all of the files in the "file" popup
308//using the protocol specified in the "protocol" popup
309//converts list of files into comma delimited list of full path:filename;vers
310//that can be reduced as a list
311// also sets the current protocol to a global accessible to the list processing routine
312//
313Function V_ReduceAllPopupFiles(ctrlName) : ButtonControl
314        String ctrlName
315       
316        //popup (and global list) is a semicolon separated list of files, WITHOUT extensions
317        //transform this list into a COMMA delimited list of FULL filenames, and then they can be processed
318       
319        SVAR semiList = root:Packages:NIST:VSANS:Globals:MRED:gMredList
320       
321        //process each item in the list, and generate commaList
322        Variable num = ItemsInList(semiList,";" )
323        Variable ii=0
324        String commaList = "",item = ""
325        do
326                item = StringFromList(ii, semiList  ,";" )
327                commaList += item + ","
328                ii+=1
329        while(ii<num)
330        //080601 - send only the comma list of filenames, not full path:name   
331        //commaList = FullNameListFromFileList(commaList)               //gets the full file names (including extension) for each item in list
332
333        //get the selected protocol, and pass as a global
334        ControlInfo MRProto_pop
335        String protocolNameStr = S_Value
336        String/G root:Packages:NIST:VSANS:Globals:Protocols:gMredProtoStr = "root:Packages:NIST:VSANS:Globals:Protocols:"+protocolNameStr
337       
338        //also set this as the current protocol, for the function that writes the averaged waves
339        String/G root:Packages:NIST:VSANS:Globals:Protocols:gProtoStr = protocolNameStr
340       
341        //reduce all the files in the list here, using the global protocol(the full reference)
342        //DoReduceList is found in MultipleReduce.ipf
343        V_DoReduceList(commaList)
344       
345        Return 0
346End
347
348
349//
350// reduce just the top file on the popup
351//
352Function V_ReduceTopPopupFile(ctrlName) : ButtonControl
353        String ctrlName
354
355        // get just the top file from the popup
356        ControlInfo MRFilesPopup
357        String commaList = S_Value + ","
358
359        //get the selected protocol, and pass as a global
360        ControlInfo MRProto_pop
361        String protocolNameStr = S_Value
362        String/G root:Packages:NIST:VSANS:Globals:Protocols:gMredProtoStr = "root:Packages:NIST:VSANS:Globals:Protocols:"+protocolNameStr
363       
364        //also set this as the current protocol, for the function that writes the averaged waves
365        String/G root:Packages:NIST:VSANS:Globals:Protocols:gProtoStr = protocolNameStr
366       
367        //reduce all the files in the list here, using the global protocol(the full reference)
368        //DoReduceList is found in MultipleReduce.ipf
369        V_DoReduceList(commaList)
370       
371        Return 0
372End
373
Note: See TracBrowser for help on using the repository browser.