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

Last change on this file was 1246, checked in by srkline, 2 years ago

A large number of changes to the size of panels to enable "Laptop Mode" where all of the panels and controls are scaled down so that they fit on screen and are still in correct proportion. For the laptop I'm using for testing, the resolution is 1920x1080. For this, a scaling of 0.7 seems to work. The on/off of the "laptop Mode" is controlled by a checkbox in the preference panel (under the General tab).

There are still more panels to update in the next commit.

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