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 |
---|
23 | Proc 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 |
---|
33 | End |
---|
34 | |
---|
35 | //create the global variables needed to run the MReduce Panel |
---|
36 | //all are kept in root:Packages:NIST:VSANS:Globals:MRED |
---|
37 | // |
---|
38 | Proc 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 |
---|
59 | End |
---|
60 | |
---|
61 | //panel recreation macro for the MRED panel |
---|
62 | // |
---|
63 | Window 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" |
---|
100 | EndMacro |
---|
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 | // |
---|
109 | Function/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) |
---|
149 | End |
---|
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 | // |
---|
155 | Function 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 | V_ExecuteProtocol(gMredProtoStr,theItem) |
---|
176 | endif |
---|
177 | index +=1 |
---|
178 | while(index<num) //exit after all items have been processed |
---|
179 | |
---|
180 | //will continue until all files in list are reduced, according to gMredProtoStr protocol |
---|
181 | return(0) |
---|
182 | End |
---|
183 | |
---|
184 | //executed when a list of filenumbers is entered in the box |
---|
185 | //responds as if the file popup was hit, to update the popup list contents |
---|
186 | // |
---|
187 | Function V_FileNumberListProc(ctrlName,varNum,varStr,varName) : SetVariableControl |
---|
188 | String ctrlName |
---|
189 | Variable varNum |
---|
190 | String varStr |
---|
191 | String varName |
---|
192 | |
---|
193 | V_MRedPopMenuProc("MRFilesPopup",0,"") |
---|
194 | End |
---|
195 | |
---|
196 | Proc V_ShowMRHelp(ctrlName) : ButtonControl |
---|
197 | String ctrlName |
---|
198 | |
---|
199 | DisplayHelpTopic/Z/K=1 "VSANS Data Reduction Tutorial[Reduce Multiple Files]" |
---|
200 | if(V_flag !=0) |
---|
201 | DoAlert 0,"The VSANS Data Reduction Tutorial Help file could not be found" |
---|
202 | endif |
---|
203 | End |
---|
204 | |
---|
205 | //button procedure for bringing File Catalog window to front, if it exists |
---|
206 | //so that the user can see what's going on |
---|
207 | // |
---|
208 | Proc V_ShowCatShort_MRED(ctrlName) : ButtonControl |
---|
209 | String ctrlName |
---|
210 | |
---|
211 | V_BuildCatVeryShortTable() |
---|
212 | End |
---|
213 | |
---|
214 | //allows the user to set the path to the local folder that contains the SANS data |
---|
215 | //2 global strings are reset after the path "catPathName" is reset in the function PickPath() |
---|
216 | // this path is the only one, the globals are simply for convenience |
---|
217 | // |
---|
218 | Function V_PickMRPathButton(PathButton) : ButtonControl |
---|
219 | String PathButton |
---|
220 | |
---|
221 | V_PickPath() //sets the main global path string for catPathName |
---|
222 | |
---|
223 | //then update the "local" copy in the MRED subfolder |
---|
224 | PathInfo/S catPathName |
---|
225 | String dum = S_path |
---|
226 | if (V_flag == 0) |
---|
227 | //path does not exist - no folder selected |
---|
228 | String/G root:Packages:NIST:VSANS:Globals:MRED:gCatPathStr = "no folder selected" |
---|
229 | else |
---|
230 | String/G root:Packages:NIST:VSANS:Globals:MRED:gCatPathStr = dum |
---|
231 | endif |
---|
232 | |
---|
233 | //Update the pathStr variable box |
---|
234 | ControlUpdate/W=Multiple_Reduce_Panel $"PathDisplay" |
---|
235 | |
---|
236 | //then update the popup list |
---|
237 | V_MRedPopMenuProc("MRFilesPopup",1,"") |
---|
238 | End |
---|
239 | |
---|
240 | // changes the contents of the popup list of files to be reduced based on the |
---|
241 | // range of file numbers entered in the text box |
---|
242 | // |
---|
243 | Function V_MREDPopMenuProc(MRFilesPopup,popNum,popStr) : PopupMenuControl |
---|
244 | String MRFilesPopup |
---|
245 | Variable popNum |
---|
246 | String popStr |
---|
247 | |
---|
248 | String list = V_GetValidMRedPopupList() |
---|
249 | // |
---|
250 | String/G root:Packages:NIST:VSANS:Globals:MRED:gMredList = list |
---|
251 | ControlUpdate MRFilesPopup |
---|
252 | |
---|
253 | End |
---|
254 | |
---|
255 | // get a list of all of the sample files, based on intent |
---|
256 | // |
---|
257 | //parses the file number list to get valid raw data filenames for reduction |
---|
258 | // -if the numbers and full ranges can be translated to correspond to actual files |
---|
259 | // on disk, the popup list is updated - otherwise the offending number is reported |
---|
260 | // and the user must fix the problem before any reduction can be done |
---|
261 | // |
---|
262 | // V_ParseRunNumberList() does the work |
---|
263 | // |
---|
264 | // only accepts files in the list that are purpose=scattering |
---|
265 | // |
---|
266 | Function/S V_GetValidMRedPopupList() |
---|
267 | |
---|
268 | |
---|
269 | String commaList="",semiList="",fname="",purpose="" |
---|
270 | SVAR numList=root:Packages:NIST:VSANS:Globals:MRED:gFileNumList |
---|
271 | |
---|
272 | // if a "*" is entered, return all of the SAMPLE+SCATTERING files |
---|
273 | if(cmpstr(numList,"*") == 0) |
---|
274 | semiList = V_GetSAMList() |
---|
275 | return(semiList) |
---|
276 | endif |
---|
277 | |
---|
278 | commaList = V_ParseRunNumberList(numList) |
---|
279 | //convert commaList to a semicolon delimited list, checking that files are SCATTERING |
---|
280 | Variable num=ItemsinList(commaList,","),ii |
---|
281 | for(ii=0;ii<num;ii+=1) |
---|
282 | fname = StringFromList(ii, commaList ,",") |
---|
283 | purpose = V_getReduction_Purpose(fname) |
---|
284 | if(cmpstr(purpose,"SCATTERING") == 0) |
---|
285 | semiList += StringFromList(ii, commaList ,",") + ";" |
---|
286 | endif |
---|
287 | endfor |
---|
288 | // print semiList |
---|
289 | //sort the list |
---|
290 | semiList = SortList(semiList,";",0) |
---|
291 | return(semiList) |
---|
292 | |
---|
293 | |
---|
294 | return(semiList) |
---|
295 | End |
---|
296 | |
---|
297 | //returns a list of the available protocol waves in the protocols folder |
---|
298 | //removes "CreateNew", "tempProtocol" and "fakeProtocol" from list (if they exist) |
---|
299 | //since these waves do not contain valid protocol instructions |
---|
300 | // |
---|
301 | Function V_MRProtoPopMenuProc(MRProto_pop,popNum,popStr) : PopupMenuControl |
---|
302 | String MRProto_pop |
---|
303 | Variable popNum |
---|
304 | String popStr |
---|
305 | |
---|
306 | //get list of currently valid protocols, and put it in the popup (the global list) |
---|
307 | //excluding "tempProtocol" and "CreateNew" if they exist |
---|
308 | SetDataFolder root:Packages:NIST:VSANS:Globals:Protocols |
---|
309 | String list = WaveList("*",";","") |
---|
310 | SetDataFolder root: |
---|
311 | |
---|
312 | //remove items from the list (list is unchanged if the items are not present) |
---|
313 | list = RemoveFromList("CreateNew", list, ";") |
---|
314 | list = RemoveFromList("tempProtocol", list, ";") |
---|
315 | list = RemoveFromList("fakeProtocol", list, ";") |
---|
316 | list = RemoveFromList("PanelNameW", list, ";") |
---|
317 | list = RemoveFromList("Beg_pts", list, ";") |
---|
318 | list = RemoveFromList("End_pts", list, ";") |
---|
319 | list = RemoveFromList("trimUpdate", list, ";") |
---|
320 | |
---|
321 | String/G root:Packages:NIST:VSANS:Globals:MRED:gMRProtoList = list |
---|
322 | ControlUpdate MRProto_pop |
---|
323 | |
---|
324 | End |
---|
325 | |
---|
326 | //button procedure to close the panel, and the SDD table if if was generated |
---|
327 | // |
---|
328 | Function V_MRDoneButtonProc(ctrlName) : ButtonControl |
---|
329 | String ctrlName |
---|
330 | |
---|
331 | // this button will make sure all files are closed |
---|
332 | //and close the panel |
---|
333 | |
---|
334 | Close/A |
---|
335 | DoWindow/K V_Multiple_Reduce_Panel |
---|
336 | |
---|
337 | DoWindow/K SDDTable |
---|
338 | KillDataFolder root:Packages:NIST:VSANS:Globals:MRED |
---|
339 | End |
---|
340 | |
---|
341 | //button action function caled to reduce all of the files in the "file" popup |
---|
342 | //using the protocol specified in the "protocol" popup |
---|
343 | //converts list of files into comma delimited list of full path:filename;vers |
---|
344 | //that can be reduced as a list |
---|
345 | // also sets the current protocol to a global accessible to the list processing routine |
---|
346 | // |
---|
347 | Function V_ReduceAllPopupFiles(ctrlName) : ButtonControl |
---|
348 | String ctrlName |
---|
349 | |
---|
350 | //popup (and global list) is a semicolon separated list of files, WITHOUT extensions |
---|
351 | //transform this list into a COMMA delimited list of FULL filenames, and then they can be processed |
---|
352 | |
---|
353 | SVAR semiList = root:Packages:NIST:VSANS:Globals:MRED:gMredList |
---|
354 | |
---|
355 | //process each item in the list, and generate commaList |
---|
356 | Variable num = ItemsInList(semiList,";" ) |
---|
357 | Variable ii=0 |
---|
358 | String commaList = "",item = "" |
---|
359 | do |
---|
360 | item = StringFromList(ii, semiList ,";" ) |
---|
361 | commaList += item + "," |
---|
362 | ii+=1 |
---|
363 | while(ii<num) |
---|
364 | //080601 - send only the comma list of filenames, not full path:name |
---|
365 | //commaList = FullNameListFromFileList(commaList) //gets the full file names (including extension) for each item in list |
---|
366 | |
---|
367 | //get the selected protocol, and pass as a global |
---|
368 | ControlInfo MRProto_pop |
---|
369 | String protocolNameStr = S_Value |
---|
370 | String/G root:Packages:NIST:VSANS:Globals:Protocols:gMredProtoStr = "root:Packages:NIST:VSANS:Globals:Protocols:"+protocolNameStr |
---|
371 | |
---|
372 | //also set this as the current protocol, for the function that writes the averaged waves |
---|
373 | String/G root:Packages:NIST:VSANS:Globals:Protocols:gProtoStr = protocolNameStr |
---|
374 | |
---|
375 | //reduce all the files in the list here, using the global protocol(the full reference) |
---|
376 | //DoReduceList is found in MultipleReduce.ipf |
---|
377 | V_DoReduceList(commaList) |
---|
378 | |
---|
379 | Return 0 |
---|
380 | End |
---|
381 | |
---|
382 | |
---|
383 | // |
---|
384 | // reduce just the top file on the popup |
---|
385 | // |
---|
386 | Function V_ReduceTopPopupFile(ctrlName) : ButtonControl |
---|
387 | String ctrlName |
---|
388 | |
---|
389 | // get just the top file from the popup |
---|
390 | ControlInfo MRFilesPopup |
---|
391 | String commaList = S_Value + "," |
---|
392 | |
---|
393 | //get the selected protocol, and pass as a global |
---|
394 | ControlInfo MRProto_pop |
---|
395 | String protocolNameStr = S_Value |
---|
396 | String/G root:Packages:NIST:VSANS:Globals:Protocols:gMredProtoStr = "root:Packages:NIST:VSANS:Globals:Protocols:"+protocolNameStr |
---|
397 | |
---|
398 | //also set this as the current protocol, for the function that writes the averaged waves |
---|
399 | String/G root:Packages:NIST:VSANS:Globals:Protocols:gProtoStr = protocolNameStr |
---|
400 | |
---|
401 | //reduce all the files in the list here, using the global protocol(the full reference) |
---|
402 | //DoReduceList is found in MultipleReduce.ipf |
---|
403 | V_DoReduceList(commaList) |
---|
404 | |
---|
405 | Return 0 |
---|
406 | End |
---|
407 | |
---|