1 | #pragma rtGlobals=1 // Use modern global access method. |
---|
2 | #pragma version=5.0 |
---|
3 | #pragma IgorVersion=6.1 |
---|
4 | |
---|
5 | //************************* |
---|
6 | // Vers. 1.2 092101 |
---|
7 | // |
---|
8 | // Procedures for the MRED panel to allow quick batch reduction of data files |
---|
9 | // -as of 8/01, use the new method of requiring only run numbers to select the datafiles |
---|
10 | // and these data failes need not be consecutively numbered |
---|
11 | // |
---|
12 | //****note that much of this file is becoming obsolete as improved methods for |
---|
13 | //reducing multiple files are introduced. Some of these procedures may not last long*** |
---|
14 | // |
---|
15 | //************************** |
---|
16 | |
---|
17 | //panel to allow reduction of a series of files using a selected protocol |
---|
18 | // |
---|
19 | //main entry procedure to open the panel, initializing if necessary |
---|
20 | Proc ReduceMultipleFiles() |
---|
21 | |
---|
22 | DoWindow/F Multiple_Reduce_Panel |
---|
23 | If(V_flag == 0) |
---|
24 | InitializeMultReducePanel() |
---|
25 | //draw panel |
---|
26 | Multiple_Reduce_Panel() |
---|
27 | //pop the protocol list |
---|
28 | MRProtoPopMenuProc("",1,"") |
---|
29 | Endif |
---|
30 | End |
---|
31 | |
---|
32 | //create the global variables needed to run the MReduce Panel |
---|
33 | //all are kept in root:myGlobals:MRED |
---|
34 | // |
---|
35 | Proc InitializeMultReducePanel() |
---|
36 | |
---|
37 | If(DataFolderExists("root:myGlobals:MRED")) |
---|
38 | //ok, do nothing |
---|
39 | else |
---|
40 | //no, create the folder and the globals |
---|
41 | NewDataFolder/O root:myGlobals:MRED |
---|
42 | // String/G root:myGlobals:MRED:gMRedMatchStr = "*" |
---|
43 | PathInfo catPathName |
---|
44 | If(V_flag==1) |
---|
45 | String dum = S_path |
---|
46 | String/G root:myGlobals:MRED:gCatPathStr = dum |
---|
47 | else |
---|
48 | String/G root:myGlobals:MRED:gCatPathStr = "no path selected" |
---|
49 | endif |
---|
50 | String/G root:myGlobals:MRED:gMRedList = "none" |
---|
51 | String/G root:myGlobals:MRED:gMRProtoList = "none" |
---|
52 | String/G root:myGlobals:MRED:gFileNumList="" |
---|
53 | // String/G root:myGlobals:MRED:gMRS1 = "no file selected" |
---|
54 | // String/G root:myGlobals:MRED:gMRS2 = "no file selected" |
---|
55 | // String/G root:myGlobals:MRED:gMRS3 = "no box selected" |
---|
56 | // Variable/G root:myGlobals:MRED:gMRV1 =0 |
---|
57 | // Variable/G root:myGlobals:MRED:gMRV2 = 999 |
---|
58 | Endif |
---|
59 | End |
---|
60 | |
---|
61 | //panel recreation macro for the MRED panel |
---|
62 | // |
---|
63 | Window Multiple_Reduce_Panel() |
---|
64 | PauseUpdate; Silent 1 // building window... |
---|
65 | NewPanel /W=(535,72,951,228) /K=1 as "Multiple File Reduction" |
---|
66 | ModifyPanel cbRGB=(65535,49151,29490) |
---|
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:myGlobals:MRED:gCatPathStr |
---|
73 | Button PathButton,pos={3,3},size={70,20},proc=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=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=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:myGlobals:MRED:gMRedList" |
---|
80 | SetVariable MRList,pos={3,48},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:myGlobals:MRED:gFileNumList |
---|
83 | Button ReduceAllButton,pos={3,128},size={180,20},proc=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 DoneButton,pos={280,128},size={110,20},proc=MRDoneButtonProc,title="Done Reducing" |
---|
86 | Button DoneButton,help={"When done reducing files, this will close this control panel."} |
---|
87 | // Button cat_short,pos={310,72},size={90,20},proc=DoCatShort,title="File Catalog" |
---|
88 | // Button cat_short,help={"Use this button to generate a table with file header information. Very useful for identifying files."} |
---|
89 | // Button show_cat_short,pos={280,98},size={120,20},proc=ShowCatShort_MRED,title="Show File Catalog" |
---|
90 | // Button show_cat_short,help={"Use this button to bring the File Catalog window to the front."} |
---|
91 | Button sddList,pos={280,72},size={120,20},proc=ScatteringAtSDDTableButton,title="Files at SDD List" |
---|
92 | Button sddList,help={"Use this button to generate a table of scattering files at a given ample to detector distance."} |
---|
93 | Button acceptList,pos={280,98},size={120,20},proc=AcceptMREDList,title="Accept List" |
---|
94 | Button acceptList,help={"Accept the list of files to reduce."} |
---|
95 | PopupMenu MRProto_pop,pos={3,98},size={119,19},proc=MRProtoPopMenuProc,title="Protocol " |
---|
96 | PopupMenu MRProto_pop,help={"All of the data files in the popup will be reduced using this protocol"} |
---|
97 | PopupMenu MRProto_pop,mode=1,popvalue="none",value= #"root:myGlobals:MRED:gMRProtoList" |
---|
98 | EndMacro |
---|
99 | |
---|
100 | //simple procedure to bring the CAT TABLE to the front if it is present |
---|
101 | //alerts user, but does nothing else if CAT TABLE is not present |
---|
102 | //called by several panels |
---|
103 | // |
---|
104 | Proc ShowCATWindow() |
---|
105 | DoWindow/F CatVSTable |
---|
106 | if(V_flag==0) |
---|
107 | DoAlert 0,"There is no File Catalog table. Use the File Catalog button to create one." |
---|
108 | Endif |
---|
109 | End |
---|
110 | |
---|
111 | |
---|
112 | //function takes a list of filenames (just the name, no path , no extension) |
---|
113 | //that is COMMA delimited, and creates a new list that is also COMMA delimited |
---|
114 | //and contains the full path:file;vers for each file in the list |
---|
115 | //and ensures that files in returned list are RAW data , and can be found on disk |
---|
116 | // |
---|
117 | Function/S FullNameListFromFileList(list) |
---|
118 | String list |
---|
119 | |
---|
120 | String newList="",pathStr="",sepStr="," |
---|
121 | PathInfo catPathName |
---|
122 | if(V_flag==0) |
---|
123 | Abort "CatPath does not exist - use Pick Path to select the data folder" |
---|
124 | else |
---|
125 | pathStr = S_Path |
---|
126 | Endif |
---|
127 | |
---|
128 | Variable ii,num,ok |
---|
129 | String fullName="",partialName="",tempName="",str |
---|
130 | |
---|
131 | num = ItemsInList(list,",") |
---|
132 | ii=0 |
---|
133 | do |
---|
134 | //take each item, and try to find the file (extensions for raw data should be ;1) |
---|
135 | partialName = StringFromList(ii,list,",") //COMMA separated list |
---|
136 | if(strlen(partialName)!=0) //null string items will be skipped |
---|
137 | tempName = FindValidFilename(partialName) //will add the version # if needed |
---|
138 | fullName = pathStr + tempName //prepend the path (CAT) |
---|
139 | |
---|
140 | //discard strings that are not filenames (print the non-files) |
---|
141 | //make sure the file is really a RAW data file |
---|
142 | ok = CheckIfRawData(fullName) // 1 if RAW, 0 if unknown type |
---|
143 | if (!ok) |
---|
144 | //write to cmd window that file was not a RAW SANS file |
---|
145 | str = "This file is not recognized as a RAW SANS data file: "+tempName+"\r" |
---|
146 | Print str |
---|
147 | else |
---|
148 | //yes, a valid file:path;ext that is RAW SANS |
---|
149 | //add the full path:file;ext +"," to the newList |
---|
150 | newList += fullName + sepStr |
---|
151 | Endif |
---|
152 | endif //partialName from original list != "" |
---|
153 | ii+=1 |
---|
154 | while(ii<num) //process all items in list |
---|
155 | |
---|
156 | Return(newList) |
---|
157 | End |
---|
158 | |
---|
159 | //takes a COMMA delimited list of files (full path:name;vers output of FullNameListFromFileList() |
---|
160 | //function and reduces each of the files in the list |
---|
161 | //the protocol is from the global string (wich is NOt in the MRED folder, but in the Protocols folder |
---|
162 | // |
---|
163 | Function DoReduceList(list) |
---|
164 | String list |
---|
165 | |
---|
166 | //selected protocol is in a temporary global variable so that it can be used with execute |
---|
167 | SVAR gMredProtoStr = root:myGlobals:Protocols:gMredProtoStr |
---|
168 | //input list is a comma delimited list of individual sample files to be reduced using the |
---|
169 | //given protocol - based on WM proc "ExecuteCmdOnList()" |
---|
170 | //input filenames must be full path:file;ext, so they can be found on disk |
---|
171 | |
---|
172 | String cmdTemplate = "ExecuteProtocol(\"" + gMredProtoStr + "\",\"%s\")" |
---|
173 | String theItem |
---|
174 | Variable index=0 |
---|
175 | String cmd |
---|
176 | Variable num = ItemsInList(list,",") |
---|
177 | do |
---|
178 | theItem = StringFromList(index,list,",") //COMMA separated list |
---|
179 | if(strlen(theItem)!=0) |
---|
180 | sprintf cmd,cmdTemplate,theItem //null string items will be skipped |
---|
181 | //Print "cmd = ",cmd |
---|
182 | Execute cmd |
---|
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) |
---|
189 | End |
---|
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 | // |
---|
194 | Function FileNumberListProc(ctrlName,varNum,varStr,varName) : SetVariableControl |
---|
195 | String ctrlName |
---|
196 | Variable varNum |
---|
197 | String varStr |
---|
198 | String varName |
---|
199 | |
---|
200 | MRedPopMenuProc("MRFilesPopup",0,"") |
---|
201 | End |
---|
202 | |
---|
203 | Proc ShowMRHelp(ctrlName) : ButtonControl |
---|
204 | String ctrlName |
---|
205 | |
---|
206 | DisplayHelpTopic/Z/K=1 "SANS Data Reduction Tutorial[Reduce Multiple Files]" |
---|
207 | if(V_flag !=0) |
---|
208 | DoAlert 0,"The SANS Data Reduction Tutorial Help file could not be found" |
---|
209 | endif |
---|
210 | End |
---|
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 | // |
---|
215 | Proc ShowCatShort_MRED(ctrlName) : ButtonControl |
---|
216 | String ctrlName |
---|
217 | |
---|
218 | ShowCATWindow() |
---|
219 | End |
---|
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 | // |
---|
225 | Function PickMRPathButton(PathButton) : ButtonControl |
---|
226 | String PathButton |
---|
227 | |
---|
228 | 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:myGlobals:MRED:gCatPathStr = "no folder selected" |
---|
236 | else |
---|
237 | String/G root:myGlobals: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 | MRedPopMenuProc("MRFilesPopup",1,"") |
---|
245 | End |
---|
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 | // |
---|
250 | Function MREDPopMenuProc(MRFilesPopup,popNum,popStr) : PopupMenuControl |
---|
251 | String MRFilesPopup |
---|
252 | Variable popNum |
---|
253 | String popStr |
---|
254 | |
---|
255 | String list = GetValidMRedPopupList() |
---|
256 | // |
---|
257 | String/G root:myGlobals:MRED:gMredList = list |
---|
258 | ControlUpdate MRFilesPopup |
---|
259 | |
---|
260 | End |
---|
261 | |
---|
262 | //parses the file number list to get valid raw data filenames for reduction |
---|
263 | // -if the numbers and full ranges can be translated to correspond to actual files |
---|
264 | // on disk, the popup list is updated - otherwise the offending number is reported |
---|
265 | // and the user must fix the problem before any reduction can be done |
---|
266 | // |
---|
267 | //ParseRunNumberList() does the work, as it does for the protocol panel |
---|
268 | // |
---|
269 | Function/S GetValidMRedPopupList() |
---|
270 | |
---|
271 | String commaList="",semiList="" |
---|
272 | SVAR numList=root:myGLobals:MRED:gFileNumList |
---|
273 | |
---|
274 | commaList = ParseRunNumberList(numList) |
---|
275 | //convert commaList to a semicolon delimited list |
---|
276 | Variable num=ItemsinList(commaList,","),ii |
---|
277 | for(ii=0;ii<num;ii+=1) |
---|
278 | semiList += StringFromList(ii, commaList ,",") + ";" |
---|
279 | endfor |
---|
280 | // print semiList |
---|
281 | //sort the list |
---|
282 | semiList = SortList(semiList,";",0) |
---|
283 | return(semiList) |
---|
284 | End |
---|
285 | |
---|
286 | //returns a list of the available protocol waves in the protocols folder |
---|
287 | //removes "CreateNew", "tempProtocol" and "fakeProtocol" from list (if they exist) |
---|
288 | //since these waves do not contain valid protocol instructions |
---|
289 | // |
---|
290 | Function MRProtoPopMenuProc(MRProto_pop,popNum,popStr) : PopupMenuControl |
---|
291 | String MRProto_pop |
---|
292 | Variable popNum |
---|
293 | String popStr |
---|
294 | |
---|
295 | //get list of currently valid protocols, and put it in the popup (the global list) |
---|
296 | //excluding "tempProtocol" and "CreateNew" if they exist |
---|
297 | SetDataFolder root:myGlobals:Protocols |
---|
298 | String list = WaveList("*",";","") |
---|
299 | SetDataFolder root: |
---|
300 | |
---|
301 | //remove items from the list (list is unchanged if the items are not present) |
---|
302 | list = RemoveFromList("CreateNew", list, ";") |
---|
303 | list = RemoveFromList("tempProtocol", list, ";") |
---|
304 | list = RemoveFromList("fakeProtocol", list, ";") |
---|
305 | |
---|
306 | String/G root:myGlobals:MRED:gMRProtoList = list |
---|
307 | ControlUpdate MRProto_pop |
---|
308 | |
---|
309 | End |
---|
310 | |
---|
311 | //button procedure to close the panel, and the SDD table if if was generated |
---|
312 | // |
---|
313 | Function MRDoneButtonProc(ctrlName) : ButtonControl |
---|
314 | String ctrlName |
---|
315 | |
---|
316 | // this button will make sure all files are closed |
---|
317 | //and close the panel |
---|
318 | |
---|
319 | Close/A |
---|
320 | DoWindow/K Multiple_Reduce_Panel |
---|
321 | |
---|
322 | DoWindow/K SDDTable |
---|
323 | KillDataFolder root:myGlobals:MRED |
---|
324 | End |
---|
325 | |
---|
326 | //button action function caled to reduce all of the files in the "file" popup |
---|
327 | //using the protocol specified in the "protocol" popup |
---|
328 | //converts list of files into comma delimited list of full path:filename;vers |
---|
329 | //that can be reduced as a list |
---|
330 | // also sets the current protocol to a global accessible to the list processing routine |
---|
331 | // |
---|
332 | Function ReduceAllPopupFiles(ctrlName) : ButtonControl |
---|
333 | String ctrlName |
---|
334 | |
---|
335 | //popup (and global list) is a semicolon separated list of files, WITHOUT extensions |
---|
336 | //transform this list into a COMMA delimited list of FULL filenames, and then they can be processed |
---|
337 | |
---|
338 | SVAR semiList = root:myGlobals:MRED:gMredList |
---|
339 | |
---|
340 | //process each item in the list, and generate commaList |
---|
341 | Variable num = ItemsInList(semiList,";" ) |
---|
342 | Variable ii=0 |
---|
343 | String commaList = "",item = "" |
---|
344 | do |
---|
345 | item = StringFromList(ii, semiList ,";" ) |
---|
346 | commaList += item + "," |
---|
347 | ii+=1 |
---|
348 | while(ii<num) |
---|
349 | //080601 - send only the comma list of filenames, not full path:name |
---|
350 | //commaList = FullNameListFromFileList(commaList) //gets the full file names (including extension) for each item in list |
---|
351 | |
---|
352 | //get the selected protocol, and pass as a global |
---|
353 | ControlInfo MRProto_pop |
---|
354 | String protocolNameStr = S_Value |
---|
355 | String/G root:myGlobals:Protocols:gMredProtoStr = "root:myGlobals:Protocols:"+protocolNameStr |
---|
356 | |
---|
357 | //also set this as the current protocol, for the function that writes the averaged waves |
---|
358 | String/G root:myGlobals:Protocols:gProtoStr = protocolNameStr |
---|
359 | |
---|
360 | //reduce all the files in the list here, using the global protocol(the full reference) |
---|
361 | //DoReduceList is found in MultipleReduce.ipf |
---|
362 | DoReduceList(commaList) |
---|
363 | |
---|
364 | Return 0 |
---|
365 | End |
---|
366 | |
---|
367 | |
---|
368 | //**************************** |
---|
369 | // below are very old procedures, not used (maybe of no value) |
---|
370 | |
---|
371 | |
---|
372 | //little used procedure - works only with menu selections of list processing |
---|
373 | // |
---|
374 | Proc ClearFileList() |
---|
375 | String/G root:myGlobals:Protocols:gReduceList="" |
---|
376 | DoAlert 0,"The file reduction list has been initialized" |
---|
377 | ShowList() |
---|
378 | End |
---|
379 | |
---|
380 | //old procedure, (not used) - data is saved to the catPathName folder, the same folder |
---|
381 | //where the data came from in the first place, avoiding extra paths |
---|
382 | Proc PickSaveFolder() |
---|
383 | NewPath/O/M="pick folder for averaged data" Save_path |
---|
384 | PathInfo/S Save_path |
---|
385 | if (V_flag == 0) |
---|
386 | //path does not exist - no folder selected |
---|
387 | Print "No destination path selected - save dialog will be presented" |
---|
388 | endif |
---|
389 | End |
---|
390 | |
---|
391 | //little used reduction procedure, asks for protocol, then uses this protocol |
---|
392 | //to reduce the files in a list built by selecting files from the CAT window |
---|
393 | //did not get favorable reviews from users and may not be kept |
---|
394 | // |
---|
395 | Proc ReduceFilesInList() |
---|
396 | |
---|
397 | String protocolName="" |
---|
398 | |
---|
399 | //generate a list of valid path:file;ext items, comma separated as the input filenames for |
---|
400 | //ExecuteProtocol(), their final destination |
---|
401 | |
---|
402 | String list = root:myGlobals:Protocols:gReduceList |
---|
403 | Variable num = ItemsInList(list,"," ) |
---|
404 | |
---|
405 | list = FullNameListFromFileList(list) |
---|
406 | |
---|
407 | //Print list |
---|
408 | |
---|
409 | //get protocolName in the same manner as "recallprotocol" button |
---|
410 | //but remember to set a global for Execute to use |
---|
411 | SetDataFolder root:myGlobals:Protocols //must be in protocols folder before executing this Proc |
---|
412 | Execute "PickAProtocol()" |
---|
413 | //get the selected protocol wave choice through a global string variable |
---|
414 | protocolName = root:myGlobals:Protocols:gProtoStr |
---|
415 | //If "CreateNew" was selected, ask user to try again |
---|
416 | if(cmpstr("CreateNew",protocolName) == 0) |
---|
417 | Abort "CreateNew is for making a new Protocol. Select a previously saved Protocol" |
---|
418 | Endif |
---|
419 | SetDataFolder root: |
---|
420 | // String/G root:myGlobals:Protocols:gMredProtoStr = "root:myGlobals:Protocols:"+protocolName |
---|
421 | |
---|
422 | //pass the full path to the protocol for ExecuteProtocol() later |
---|
423 | //Print gMredProtoStr," protocol name" |
---|
424 | |
---|
425 | DoReduceList(list) |
---|
426 | |
---|
427 | // KillStrings/Z gMredProtoStr |
---|
428 | |
---|
429 | // SetDataFolder root: |
---|
430 | |
---|
431 | End |
---|
432 | |
---|
433 | //displays the current contents of the FileList window, for multiple file reduction |
---|
434 | //little used function and may not be kept |
---|
435 | // |
---|
436 | Proc ShowList() |
---|
437 | |
---|
438 | DoWindow/F ListWin |
---|
439 | If(V_Flag ==0) |
---|
440 | NewNotebook/F=1/N=ListWin as "File List" |
---|
441 | Endif |
---|
442 | //clear old window contents, reset the path |
---|
443 | Notebook ListWin,selection={startOfFile,EndOfFile} |
---|
444 | Notebook ListWin,text="\r" |
---|
445 | |
---|
446 | //Write out each item of the comma-delimited list to the notebook |
---|
447 | String list = root:myGlobals:Protocols:gReduceList |
---|
448 | Variable index = 0 |
---|
449 | String theItem="" |
---|
450 | Variable num = ItemsInList(list,"," ) |
---|
451 | do |
---|
452 | theItem = StringFromList(index,list,",") //COMMA separated list |
---|
453 | if(strlen(theItem)!=0) |
---|
454 | Notebook ListWin,text=(theItem+"\r") //null string items will be skipped |
---|
455 | endif |
---|
456 | index +=1 |
---|
457 | while(index<num) //exit after all items are printed |
---|
458 | End |
---|
459 | |
---|
460 | |
---|
461 | //little used function to add the selected file from the CAT/SHORT window to the fileList |
---|
462 | //so that the list of files can be processed batchwise |
---|
463 | // |
---|
464 | Proc AddSelectionToList() |
---|
465 | |
---|
466 | if(WinType("CatWin")==0) |
---|
467 | Abort "There is no CAT/SHORT window. Use the CAT/SHORT button to create one." |
---|
468 | Endif |
---|
469 | GetSelection notebook,CatWin,3 |
---|
470 | //build a comma separated list of names |
---|
471 | //does the global variable exist? |
---|
472 | if(exists("root:myGlobals:Protocols:gReduceList")==2) //a string exists |
---|
473 | //do nothing extra |
---|
474 | else |
---|
475 | //create (initialize) the global string |
---|
476 | String/G root:myGlobals:Protocols:gReduceList = "" |
---|
477 | endif |
---|
478 | String list = root:myGlobals:Protocols:gReduceList |
---|
479 | list += S_Selection + "," |
---|
480 | String/G root:myGlobals:Protocols:gReduceList = list //reassign the global |
---|
481 | |
---|
482 | |
---|
483 | End |
---|
484 | |
---|
485 | //little used function to remove the selected file in the CAT/SHORT window from the fileList |
---|
486 | Proc RemoveFileFromList() |
---|
487 | //if(WinType("CatWin")==0) |
---|
488 | //Abort "There is no CAT/SHORT window. Use the CAT/SHORT button to create one." |
---|
489 | //Endif |
---|
490 | GetSelection notebook,ListWin,3 |
---|
491 | //remove the selected item from the list |
---|
492 | String list = root:myGlobals:Protocols:gReduceList |
---|
493 | list = RemoveFromList(S_selection,list,",") |
---|
494 | String/G root:myGlobals:Protocols:gReduceList = list |
---|
495 | |
---|
496 | ShowList() |
---|
497 | End |
---|
498 | |
---|
499 | // based on WM PossiblyQuoteList(list, separator) |
---|
500 | // Input is a list of names that may contain liberal names. |
---|
501 | // Returns the list with liberal names quoted. |
---|
502 | // Example: |
---|
503 | // Input: "wave0;wave 1;" |
---|
504 | // Output: "wave0;'wave 1';" |
---|
505 | // The list is expected to be a standard separated list, like "wave0;wave1;wave2;". |
---|
506 | //*****unused******* |
---|
507 | Function/S PossiblyQuoteFileList(list, separator) |
---|
508 | String list |
---|
509 | String separator |
---|
510 | |
---|
511 | String item, outputList = "" |
---|
512 | Variable ii= 0 |
---|
513 | Variable items= ItemsInList(list, separator) |
---|
514 | do |
---|
515 | if (ii >= items) // no more items? |
---|
516 | break |
---|
517 | endif |
---|
518 | item= StringFromList(ii, list, separator) |
---|
519 | outputList += PossiblyQuoteName(item) + separator |
---|
520 | ii += 1 |
---|
521 | while(1) |
---|
522 | return outputList |
---|
523 | End |
---|
524 | |
---|
525 | Function ScatteringAtSDDTableButton(ctrlName) |
---|
526 | String ctrlName |
---|
527 | |
---|
528 | Execute "CreateScatteringAtSDDTable()" |
---|
529 | return(0) |
---|
530 | End |
---|
531 | |
---|
532 | Function AcceptMREDList(ctrlName) |
---|
533 | String ctrlName |
---|
534 | |
---|
535 | SVAR/Z list = root:myGlobals:MRED:gFileNumList |
---|
536 | if(SVAR_Exists(list)==0) //check for myself |
---|
537 | DoAlert 0,"The Multiple Reduce Panel must be open for you to use this function" |
---|
538 | Return(1) |
---|
539 | endif |
---|
540 | |
---|
541 | // convert the wave to a comma-delimited List |
---|
542 | wave/Z numW = $"root:myGlobals:MRED:RunNumber" |
---|
543 | if(waveExists(numW)==0 || numpnts(numW)==0) |
---|
544 | DoAlert 0, "Generate a list of files at a specific detector distance using the Files at SDD List button" |
---|
545 | return(0) |
---|
546 | Endif |
---|
547 | |
---|
548 | list = NumWave2CommaList(numW) |
---|
549 | |
---|
550 | //force an update If the SVAR exists, then the panel does too - MRED cleans up after itself when done |
---|
551 | DoWindow/F Multiple_Reduce_Panel //bring to front |
---|
552 | MRedPopMenuProc("MRFilesPopup",0,"") //parse the list, pop the menu |
---|
553 | |
---|
554 | |
---|
555 | return(0) |
---|
556 | End |
---|
557 | |
---|
558 | // - to create a table of scattering runs at an input SDD |
---|
559 | Proc CreateScatteringAtSDDTable(SDD_to_Filter) |
---|
560 | Variable SDD_to_Filter |
---|
561 | |
---|
562 | NewDataFolder/O root:myGlobals:MRED |
---|
563 | DoWindow/F SDDTable |
---|
564 | |
---|
565 | Make/O/T/N=0 $"root:myGlobals:MRED:Filenames" |
---|
566 | Make/O/T/N=0 $"root:myGlobals:MRED:Suffix" |
---|
567 | Make/O/T/N=0 $"root:myGlobals:MRED:Labels" |
---|
568 | Make/O/D/N=0 $"root:myGlobals:MRED:SDD" |
---|
569 | Make/O/D/N=0 $"root:myGlobals:MRED:RunNumber" |
---|
570 | Make/O/D/N=0 $"root:myGlobals:MRED:IsTrans" |
---|
571 | |
---|
572 | If(V_Flag==0) |
---|
573 | SetDataFolder root:myGlobals:MRED |
---|
574 | Edit Labels, SDD, runNumber as "Scattering at SDD" |
---|
575 | DoWindow/C $"SDDTable" |
---|
576 | |
---|
577 | ModifyTable width(SDD)=40 |
---|
578 | ModifyTable width(Labels)=180 |
---|
579 | |
---|
580 | ModifyTable width(Point)=0 //JUN04, remove point numbers - confuses users since point != run |
---|
581 | SetDataFolder root: |
---|
582 | Endif |
---|
583 | |
---|
584 | //get a list of all files in the folder, some will be junk version numbers that don't exist |
---|
585 | String list,partialName,tempName,temp="" |
---|
586 | list = IndexedFile(catPathName,-1,"????") //get all files in folder |
---|
587 | Variable numitems,ii,ok |
---|
588 | |
---|
589 | //remove version numbers from semicolon-delimited list |
---|
590 | list = RemoveVersNumsFromList(list) |
---|
591 | numitems = ItemsInList(list,";") |
---|
592 | |
---|
593 | //loop through all of the files in the list, reading CAT/SHORT information if the file is RAW SANS |
---|
594 | //***version numbers have been removed*** |
---|
595 | String str,fullName |
---|
596 | Variable lastPoint |
---|
597 | ii=0 |
---|
598 | |
---|
599 | Make/T/O/N=0 notRAWlist |
---|
600 | do |
---|
601 | //get current item in the list |
---|
602 | partialName = StringFromList(ii, list, ";") |
---|
603 | //get a valid file based on this partialName and catPathName |
---|
604 | tempName = FindValidFilename(partialName) |
---|
605 | If(cmpstr(tempName,"")==0) //a null string was returned |
---|
606 | //write to notebook that file was not found |
---|
607 | //if string is not a number, report the error |
---|
608 | if(str2num(partialName) == NaN) |
---|
609 | str = "this file was not found: "+partialName+"\r\r" |
---|
610 | //Notebook CatWin,font="Times",fsize=12,text=str |
---|
611 | Endif |
---|
612 | else |
---|
613 | //prepend path to tempName for read routine |
---|
614 | PathInfo catPathName |
---|
615 | FullName = S_path + tempName |
---|
616 | //make sure the file is really a RAW data file |
---|
617 | ok = CheckIfRawData(fullName) |
---|
618 | if (!ok) |
---|
619 | //write to notebook that file was not a RAW SANS file |
---|
620 | lastPoint = numpnts(notRAWlist) |
---|
621 | InsertPoints lastPoint,1,notRAWlist |
---|
622 | notRAWlist[lastPoint]=tempname |
---|
623 | else |
---|
624 | //go write the header information to the Notebook |
---|
625 | GetHeaderInfoToSDDWave(fullName,tempName) |
---|
626 | Endif |
---|
627 | Endif |
---|
628 | ii+=1 |
---|
629 | while(ii<numitems) |
---|
630 | //Now sort them all based on the suffix data (orders them as collected) |
---|
631 | // SortCombineWaves() |
---|
632 | // sort by label |
---|
633 | // SortCombineByLabel() |
---|
634 | // remove the transmission waves |
---|
635 | // |
---|
636 | RemoveTransFilesFromSDDList() |
---|
637 | |
---|
638 | // Remove anything not at the desired SDD, then sort by run number |
---|
639 | RemoveWrongSDDFromSDDList(SDD_to_Filter) |
---|
640 | |
---|
641 | // remove anything named blocked, empty cell, etc. |
---|
642 | RemoveLabeledFromSDDList("EMPTY") //not case-sensitive |
---|
643 | RemoveLabeledFromSDDList("MT CELL") //not case-sensitive |
---|
644 | RemoveLabeledFromSDDList("BLOCKED BEAM") //not case-sensitive |
---|
645 | RemoveLabeledFromSDDList("BEAM BLOCKED") //not case-sensitive |
---|
646 | |
---|
647 | End |
---|
648 | |
---|
649 | // need fuzzy comparison, since SDD = 1.33 may actually be represented in FP as 1.33000004 !!! |
---|
650 | // |
---|
651 | Function RemoveLabeledFromSDDList(findThisStr) |
---|
652 | String findThisStr |
---|
653 | Wave/T filenames = $"root:myGlobals:MRED:Filenames" |
---|
654 | Wave/T suffix = $"root:myGlobals:MRED:Suffix" |
---|
655 | Wave/T labels = $"root:myGlobals:MRED:Labels" |
---|
656 | Wave sdd = $"root:myGlobals:MRED:SDD" |
---|
657 | Wave runnum = $"root:myGlobals:MRED:RunNumber" |
---|
658 | Wave isTrans = $"root:myGlobals:MRED:IsTrans" |
---|
659 | |
---|
660 | Variable num=numpnts(Labels),ii,loc |
---|
661 | ii=num-1 |
---|
662 | do |
---|
663 | loc = strsearch(labels[ii], findThisStr, 0 ,2) //2==case insensitive, but Igor 5 specific |
---|
664 | if(loc != -1) |
---|
665 | Print "Remove w[ii] = ",num," ",labels[ii] |
---|
666 | DeletePoints ii, 1, filenames,suffix,labels,sdd,runnum,isTrans |
---|
667 | endif |
---|
668 | ii-=1 |
---|
669 | while(ii>=0) |
---|
670 | return(0) |
---|
671 | End |
---|
672 | |
---|
673 | // need fuzzy comparison, since SDD = 1.33 may actually be represented in FP as 1.33000004 !!! |
---|
674 | // |
---|
675 | Function RemoveWrongSDDFromSDDList(tSDD) |
---|
676 | Variable tSDD |
---|
677 | |
---|
678 | Wave/T filenames = $"root:myGlobals:MRED:Filenames" |
---|
679 | Wave/T suffix = $"root:myGlobals:MRED:Suffix" |
---|
680 | Wave/T labels = $"root:myGlobals:MRED:Labels" |
---|
681 | Wave sdd = $"root:myGlobals:MRED:SDD" |
---|
682 | Wave runnum = $"root:myGlobals:MRED:RunNumber" |
---|
683 | Wave isTrans = $"root:myGlobals:MRED:IsTrans" |
---|
684 | |
---|
685 | Variable num=numpnts(sdd),ii,tol = 0.001 |
---|
686 | ii=num-1 |
---|
687 | do |
---|
688 | if(abs(sdd[ii] - tSDD) > tol) //if numerically more than 0.001 m different, they're not the same |
---|
689 | DeletePoints ii, 1, filenames,suffix,labels,sdd,runnum,isTrans |
---|
690 | endif |
---|
691 | ii-=1 |
---|
692 | while(ii>=0) |
---|
693 | |
---|
694 | // now sort |
---|
695 | Sort RunNum, filenames,suffix,labels,sdd,runnum,isTrans |
---|
696 | return(0) |
---|
697 | End |
---|
698 | |
---|
699 | |
---|
700 | Function RemoveTransFilesFromSDDList() |
---|
701 | Wave/T filenames = $"root:myGlobals:MRED:Filenames" |
---|
702 | Wave/T suffix = $"root:myGlobals:MRED:Suffix" |
---|
703 | Wave/T labels = $"root:myGlobals:MRED:Labels" |
---|
704 | Wave sdd = $"root:myGlobals:MRED:SDD" |
---|
705 | Wave runnum = $"root:myGlobals:MRED:RunNumber" |
---|
706 | Wave isTrans = $"root:myGlobals:MRED:IsTrans" |
---|
707 | |
---|
708 | Variable num=numpnts(isTrans),ii |
---|
709 | ii=num-1 |
---|
710 | do |
---|
711 | if(isTrans[ii] != 0) |
---|
712 | DeletePoints ii, 1, filenames,suffix,labels,sdd,runnum,isTrans |
---|
713 | endif |
---|
714 | ii-=1 |
---|
715 | while(ii>=0) |
---|
716 | return(0) |
---|
717 | End |
---|
718 | |
---|
719 | //reads header information and puts it in the appropriate waves for display in the table. |
---|
720 | //fname is the full path for opening (and reading) information from the file |
---|
721 | //which alreay was found to exist. sname is the file;vers to be written out, |
---|
722 | //avoiding the need to re-extract it from fname. |
---|
723 | Function GetHeaderInfoToSDDWave(fname,sname) |
---|
724 | String fname,sname |
---|
725 | |
---|
726 | String textstr,temp,lbl,date_time,suffix |
---|
727 | Variable ctime,lambda,sdd,detcnt,cntrate,refNum,trans,thick,xcenter,ycenter,numatten |
---|
728 | Variable lastPoint, beamstop |
---|
729 | |
---|
730 | Wave/T GFilenames = $"root:myGlobals:MRED:Filenames" |
---|
731 | Wave/T GSuffix = $"root:myGlobals:MRED:Suffix" |
---|
732 | Wave/T GLabels = $"root:myGlobals:MRED:Labels" |
---|
733 | Wave GSDD = $"root:myGlobals:MRED:SDD" |
---|
734 | Wave GRunNumber = $"root:myGlobals:MRED:RunNumber" |
---|
735 | Wave GIsTrans = $"root:myGlobals:MRED:IsTrans" |
---|
736 | |
---|
737 | lastPoint = numpnts(GLambda) |
---|
738 | |
---|
739 | InsertPoints lastPoint,1,GFilenames |
---|
740 | GFilenames[lastPoint]=sname |
---|
741 | |
---|
742 | //read the file suffix |
---|
743 | InsertPoints lastPoint,1,GSuffix |
---|
744 | GSuffix[lastPoint]=getSuffix(fname) |
---|
745 | |
---|
746 | // read the sample.label text field |
---|
747 | InsertPoints lastPoint,1,GLabels |
---|
748 | GLabels[lastPoint]=getSampleLabel(fname) |
---|
749 | |
---|
750 | //read in the SDD |
---|
751 | InsertPoints lastPoint,1,GSDD |
---|
752 | GSDD[lastPoint]= getSDD(fname) |
---|
753 | |
---|
754 | //the run number (not displayed in the table, but carried along) |
---|
755 | InsertPoints lastPoint,1,GRunNumber |
---|
756 | GRunNumber[lastPoint] = GetRunNumFromFile(sname) |
---|
757 | |
---|
758 | // 0 if the file is a scattering file, 1 (truth) if the file is a transmission file |
---|
759 | InsertPoints lastPoint,1,GIsTrans |
---|
760 | GIsTrans[lastPoint] = isTransFile(fname) //returns one if beamstop is "out" |
---|
761 | |
---|
762 | KillWaves/Z w |
---|
763 | return(0) |
---|
764 | End |
---|