1 | #pragma rtGlobals=1 // Use modern global access method. |
---|
2 | #pragma version=5.0 |
---|
3 | #pragma IgorVersion=6.0 |
---|
4 | |
---|
5 | //************************* |
---|
6 | // Vers. 1.2 092101 |
---|
7 | // |
---|
8 | // - procedures for (easier) caluclation of transmissions along with |
---|
9 | // simultaneous patching of the calculated transmission in designated |
---|
10 | // raw sans files. |
---|
11 | // - transmission and empty beam files are linked to the dataset by their "Annn" suffix |
---|
12 | // only (and their residence in the same data folder) |
---|
13 | // - unused (analysis) integer values are used to store these run numbers in the sample |
---|
14 | // file headers so that transmissions can be automatically calculated, once the xy box is set |
---|
15 | // in the empty beam file. |
---|
16 | // |
---|
17 | //*************************** |
---|
18 | |
---|
19 | //main entry procedure for displaying the Trans input panel |
---|
20 | //also initializes the globals as needed |
---|
21 | // |
---|
22 | Proc CalcTrans() |
---|
23 | |
---|
24 | DoWindow/F Trans_Panel |
---|
25 | If(V_flag == 0) |
---|
26 | InitializeTransPanel() |
---|
27 | //draw panel |
---|
28 | Trans_Panel() |
---|
29 | AutoPositionWindow/M=1/R=Main_Panel Trans_Panel |
---|
30 | Endif |
---|
31 | End |
---|
32 | |
---|
33 | // The BuildFileTables routine will build two tables: one containing the |
---|
34 | // data from the headers of transmission files in the folder and one |
---|
35 | // containing the header data from all other SANS data files. They will |
---|
36 | // each have the first column empty for, in the case of transmission files, |
---|
37 | // the empty beam file and, in the case of scattering files, the scattering |
---|
38 | // run file name. |
---|
39 | Proc BuildFileTables() |
---|
40 | |
---|
41 | Variable err |
---|
42 | PathInfo catPathName |
---|
43 | if(v_flag==0) |
---|
44 | err = PickPath()//sets the local path to the data (catPathName) |
---|
45 | if(err) |
---|
46 | Abort "no path to data was selected, no catalog can be made - use PickPath button" |
---|
47 | Endif |
---|
48 | Endif |
---|
49 | |
---|
50 | DoWindow/F ScatterFileTable |
---|
51 | CreateTransGlobals() |
---|
52 | If(V_Flag==0) |
---|
53 | BuildScatTableWindow() |
---|
54 | ModifyTable width(:myGlobals:TransHeaderInfo:S_SDD)=40 |
---|
55 | ModifyTable width(:myGlobals:TransHeaderInfo:S_Lambda)=40 |
---|
56 | ModifyTable width(:myGlobals:TransHeaderInfo:S_Transmission)=60 |
---|
57 | ModifyTable rgb(:myGlobals:TransHeaderInfo:S_Filenames)=(0,0,65535) |
---|
58 | ModifyTable width(Point)=0 |
---|
59 | Endif |
---|
60 | |
---|
61 | //open xml file |
---|
62 | variable fileID = getReport() |
---|
63 | if(fileID<=1) |
---|
64 | Abort "Cannot open experimental report file " + S_filename |
---|
65 | endif |
---|
66 | |
---|
67 | getFileAssociations(fileID) |
---|
68 | |
---|
69 | //close xml file without save |
---|
70 | XMLclosefile(fileID,0) |
---|
71 | |
---|
72 | //Read data from datafile into globals |
---|
73 | GetTransHeaderInfoToWave() |
---|
74 | |
---|
75 | //Sort entries based on date |
---|
76 | SortGlobals(0) |
---|
77 | |
---|
78 | //position the windows nicely |
---|
79 | AutoPositionWindow/M=1/R=ScatterFileTable |
---|
80 | DoWindow/F Trans_Panel |
---|
81 | End |
---|
82 | |
---|
83 | Function getReport() |
---|
84 | // Open the experiment report file(s) in this path |
---|
85 | variable refnum |
---|
86 | Open/D/R /M="Open experiment report file" /T=".xml" refnum |
---|
87 | if(cmpstr(S_filename,"")==0) |
---|
88 | Abort "No experimental report file selected" |
---|
89 | Endif |
---|
90 | variable fileID = XMLopenFile(S_filename) |
---|
91 | |
---|
92 | return fileID |
---|
93 | |
---|
94 | End |
---|
95 | |
---|
96 | Function getFileAssociations(fileID) |
---|
97 | variable fileID |
---|
98 | variable ii |
---|
99 | |
---|
100 | Wave/T S_Filenames = $"root:myGlobals:TransHeaderInfo:S_Filenames" |
---|
101 | Wave/T T_Filenames = $"root:myGlobals:TransHeaderInfo:T_Filenames" |
---|
102 | Wave/T EMP_Filenames = $"root:myGlobals:TransHeaderInfo:EMP_Filenames" |
---|
103 | |
---|
104 | string prefix = "QKK" |
---|
105 | string suffix = ".nx.hdf" |
---|
106 | string fname, full_fname, xpath, xpath_type, xpath_fname, xmlString |
---|
107 | variable nSamples |
---|
108 | |
---|
109 | //determine no. of samples |
---|
110 | xpath = "//result/sample" |
---|
111 | XMLWaveFmXpath(fileID,xpath,"","") |
---|
112 | nSamples = DimSize(W_xmlContentNodes,0) |
---|
113 | |
---|
114 | ii=1 |
---|
115 | do |
---|
116 | // sample must be of type="sample" |
---|
117 | xpath = "//result/sample[" + num2str(ii) + "]" |
---|
118 | xpath_type = xpath + "/@type" |
---|
119 | xmlString = XMLstrFmXpath(fileID,xpath_type,""," ") |
---|
120 | if(strsearch(xmlString,"sample",0)>=0) //allow for leading/trailing whitespace |
---|
121 | //scattering |
---|
122 | xpath_fname = xpath + "/config/scattering/@run" |
---|
123 | fname = XMLstrFmXpath(fileID,xpath_fname,"","") |
---|
124 | full_fname = prefix + fname + suffix |
---|
125 | //null string if file no specified |
---|
126 | if (cmpstr(fname,"")==0) |
---|
127 | full_fname = "" |
---|
128 | endif |
---|
129 | InsertPoints ii-1,1,S_Filenames |
---|
130 | S_Filenames[ii-1] = full_fname |
---|
131 | //transmission |
---|
132 | xpath_fname = xpath + "/config/transmission/@run" |
---|
133 | fname = XMLstrFmXpath(fileID,xpath_fname,"","") |
---|
134 | full_fname = prefix + fname + suffix |
---|
135 | //null string if file no specified |
---|
136 | if (cmpstr(fname,"")==0) |
---|
137 | full_fname = "" |
---|
138 | endif |
---|
139 | InsertPoints ii-1,1,T_Filenames |
---|
140 | T_Filenames[ii-1] = full_fname |
---|
141 | //empty beam transmission |
---|
142 | xpath_fname = xpath + "/config/emptyBeamTransmission/text()" |
---|
143 | fname = XMLstrFmXpath(fileID,xpath_fname,"","") |
---|
144 | full_fname = prefix + fname + suffix |
---|
145 | //null string if file no specified |
---|
146 | if (cmpstr(fname,"")==0) |
---|
147 | full_fname = "" |
---|
148 | endif |
---|
149 | InsertPoints ii-1,1,EMP_Filenames |
---|
150 | EMP_Filenames[ii-1] = full_fname |
---|
151 | endif |
---|
152 | ii+=1 |
---|
153 | while(ii<nSamples) |
---|
154 | |
---|
155 | //delete rows with blanks |
---|
156 | ii=0 |
---|
157 | do |
---|
158 | if(cmpstr(T_Filenames[ii],"")==0) |
---|
159 | DeletePoints ii,1,T_Filenames,S_Filenames,EMP_Filenames |
---|
160 | ii-=1 |
---|
161 | endif |
---|
162 | ii+=1 |
---|
163 | while (ii<DimSize(S_Filenames,0)) |
---|
164 | |
---|
165 | |
---|
166 | //Check if the files in the report file are available in the path. |
---|
167 | // |
---|
168 | |
---|
169 | //Put up a dialog of the number of missing files and their filenames. ABORT or CONTINUE |
---|
170 | // |
---|
171 | |
---|
172 | End |
---|
173 | |
---|
174 | //actually creates the table of scattering files |
---|
175 | // - the waves must exist |
---|
176 | // |
---|
177 | Function BuildScatTableWindow() |
---|
178 | Wave/T S_Filenames = $"root:myGlobals:TransHeaderInfo:S_Filenames" |
---|
179 | Wave/T T_Filenames = $"root:myGlobals:TransHeaderInfo:T_Filenames" |
---|
180 | Wave/T EMP_Filenames = $"root:myGlobals:TransHeaderInfo:EMP_Filenames" |
---|
181 | Wave/T S_Labels = $"root:myGlobals:TransHeaderInfo:S_Labels" |
---|
182 | Wave/T T_Labels = $"root:myGlobals:TransHeaderInfo:T_Labels" |
---|
183 | Wave S_SDD = $"root:myGlobals:TransHeaderInfo:S_SDD" |
---|
184 | Wave S_Lambda = $"root:myGlobals:TransHeaderInfo:S_Lambda" |
---|
185 | Wave S_Transmission = $"root:myGlobals:TransHeaderInfo:S_Transmission" |
---|
186 | Wave S_Whole= $"root:myGlobals:TransHeaderInfo:S_Whole" |
---|
187 | Wave T_SDD = $"root:myGlobals:TransHeaderInfo:T_SDD" |
---|
188 | Wave T_Lambda = $"root:myGlobals:TransHeaderInfo:T_Lambda" |
---|
189 | // Wave T_Transmission = $"root:myGlobals:TransHeaderInfo:T_Transmission" |
---|
190 | // Wave T_Whole= $"root:myGlobals:TransHeaderInfo:T_Whole" |
---|
191 | Wave EMP_x1= $"root:myGlobals:TransHeaderInfo:EMP_x1" |
---|
192 | Wave EMP_x2= $"root:myGlobals:TransHeaderInfo:EMP_x2" |
---|
193 | Wave EMP_y1= $"root:myGlobals:TransHeaderInfo:EMP_y1" |
---|
194 | Wave EMP_y2= $"root:myGlobals:TransHeaderInfo:EMP_y2" |
---|
195 | |
---|
196 | Edit/K=1/W=(50,50,520,270) S_Filenames, T_Filenames, EMP_Filenames, S_Labels, T_Labels, S_SDD, T_SDD, S_Lambda, T_Lambda, S_Transmission, S_Whole, EMP_x1, EMP_x2, EMP_y1, EMP_y2 as "ScatteringFiles" |
---|
197 | |
---|
198 | String name="ScatterFileTable" |
---|
199 | DoWindow/C $name |
---|
200 | |
---|
201 | End |
---|
202 | |
---|
203 | |
---|
204 | //sorts each of the tables by date - does this by using the suffix "Annn" |
---|
205 | // which is automatically supplied by the VAX (and can't be changed) |
---|
206 | // - only problem may be "Z999" -> "A001" rollover |
---|
207 | // |
---|
208 | // sorts files alphabetically byt the sample label |
---|
209 | // - consistent and descriptive sample labels really pay off here |
---|
210 | // |
---|
211 | Function SortGlobals(sortFlag) |
---|
212 | Variable sortFlag |
---|
213 | |
---|
214 | Wave/T EMP_Filenames = $"root:myGlobals:TransHeaderInfo:EMP_Filenames" |
---|
215 | Wave/T T_Filenames = $"root:myGlobals:TransHeaderInfo:T_Filenames" |
---|
216 | Wave/T T_Labels = $"root:myGlobals:TransHeaderInfo:T_Labels" |
---|
217 | Wave T_SDD = $"root:myGlobals:TransHeaderInfo:T_SDD" |
---|
218 | Wave T_Lambda = $"root:myGlobals:TransHeaderInfo:T_Lambda" |
---|
219 | // Wave T_Transmission = $"root:myGlobals:TransHeaderInfo:T_Transmission" |
---|
220 | // Wave T_Whole= $"root:myGlobals:TransHeaderInfo:T_Whole" |
---|
221 | |
---|
222 | Wave/T S_Filenames = $"root:myGlobals:TransHeaderInfo:S_Filenames" |
---|
223 | Wave/T S_Labels = $"root:myGlobals:TransHeaderInfo:S_Labels" |
---|
224 | Wave S_SDD = $"root:myGlobals:TransHeaderInfo:S_SDD" |
---|
225 | Wave S_Lambda = $"root:myGlobals:TransHeaderInfo:S_Lambda" |
---|
226 | Wave S_Transmission = $"root:myGlobals:TransHeaderInfo:S_Transmission" |
---|
227 | Wave S_Whole= $"root:myGlobals:TransHeaderInfo:S_Whole" |
---|
228 | |
---|
229 | Wave EMP_x1= $"root:myGlobals:TransHeaderInfo:EMP_x1" |
---|
230 | Wave EMP_x2= $"root:myGlobals:TransHeaderInfo:EMP_x2" |
---|
231 | Wave EMP_y1= $"root:myGlobals:TransHeaderInfo:EMP_y1" |
---|
232 | Wave EMP_y2= $"root:myGlobals:TransHeaderInfo:EMP_y2" |
---|
233 | |
---|
234 | if(sortFlag == 0) // by date |
---|
235 | Sort S_Filenames, S_Filenames, S_Labels, S_SDD, S_Lambda, S_Transmission, S_Whole, EMP_Filenames, T_Filenames, T_Labels, T_SDD, T_Lambda, EMP_x1, EMP_x2, EMP_y1, EMP_y2 |
---|
236 | else //by label |
---|
237 | Sort S_Labels, S_Labels, S_Filenames, S_SDD, S_Lambda, S_Transmission, S_Whole, EMP_Filenames, T_Filenames, T_Labels, T_SDD, T_Lambda, EMP_x1, EMP_x2, EMP_y1, EMP_y2 |
---|
238 | endif |
---|
239 | End |
---|
240 | |
---|
241 | //reads the file and assigns header information to globals, which are read by the ScatteringTable. |
---|
242 | //assumes that associations have been found in experiment report |
---|
243 | // |
---|
244 | //scat_fname - is the full path:name of the datafile (used by Open) |
---|
245 | // |
---|
246 | // takes care of all necessary open/close of file |
---|
247 | // |
---|
248 | Function GetTransHeaderInfoToWave() |
---|
249 | String s_fname,t_fname,emp_fname |
---|
250 | |
---|
251 | Variable lastPoint, ii, ok |
---|
252 | |
---|
253 | Wave/T S_Filenames = $"root:myGlobals:TransHeaderInfo:S_Filenames" |
---|
254 | Wave/T T_Filenames = $"root:myGlobals:TransHeaderInfo:T_Filenames" |
---|
255 | Wave/T EMP_Filenames = $"root:myGlobals:TransHeaderInfo:EMP_Filenames" |
---|
256 | Wave/T S_Labels = $"root:myGlobals:TransHeaderInfo:S_Labels" |
---|
257 | Wave/T T_Labels = $"root:myGlobals:TransHeaderInfo:T_Labels" |
---|
258 | Wave S_SDD = $"root:myGlobals:TransHeaderInfo:S_SDD" |
---|
259 | Wave S_Lambda = $"root:myGlobals:TransHeaderInfo:S_Lambda" |
---|
260 | Wave S_Transmission = $"root:myGlobals:TransHeaderInfo:S_Transmission" |
---|
261 | Wave S_Whole= $"root:myGlobals:TransHeaderInfo:S_Whole" |
---|
262 | Wave T_SDD = $"root:myGlobals:TransHeaderInfo:T_SDD" |
---|
263 | Wave T_Lambda = $"root:myGlobals:TransHeaderInfo:T_Lambda" |
---|
264 | // Wave T_Transmission = $"root:myGlobals:TransHeaderInfo:T_Transmission" |
---|
265 | // Wave T_Whole= $"root:myGlobals:TransHeaderInfo:T_Whole" |
---|
266 | |
---|
267 | Wave EMP_x1= $"root:myGlobals:TransHeaderInfo:EMP_x1" |
---|
268 | Wave EMP_x2= $"root:myGlobals:TransHeaderInfo:EMP_x2" |
---|
269 | Wave EMP_y1= $"root:myGlobals:TransHeaderInfo:EMP_y1" |
---|
270 | Wave EMP_y2= $"root:myGlobals:TransHeaderInfo:EMP_y2" |
---|
271 | |
---|
272 | lastPoint = numpnts(S_Filenames) |
---|
273 | PathInfo catPathName |
---|
274 | variable x1, x2, y1, y2 |
---|
275 | |
---|
276 | ii = 0 |
---|
277 | do |
---|
278 | s_fname = S_path + S_Filenames[ii] |
---|
279 | t_fname = S_path + T_Filenames[ii] |
---|
280 | emp_fname = S_path + EMP_Filenames[ii] |
---|
281 | |
---|
282 | InsertPoints ii,1,S_Labels |
---|
283 | InsertPoints ii,1,S_Transmission |
---|
284 | InsertPoints ii,1,S_Whole |
---|
285 | InsertPoints ii,1,S_SDD |
---|
286 | InsertPoints ii,1,S_Lambda |
---|
287 | InsertPoints ii,1,T_Labels |
---|
288 | // InsertPoints ii,1,T_Transmission |
---|
289 | // InsertPoints ii,1,T_Whole |
---|
290 | InsertPoints ii,1,T_SDD |
---|
291 | InsertPoints ii,1,T_Lambda |
---|
292 | InsertPoints ii,1,EMP_x1 |
---|
293 | InsertPoints ii,1,EMP_x2 |
---|
294 | InsertPoints ii,1,EMP_y1 |
---|
295 | InsertPoints ii,1,EMP_y2 |
---|
296 | |
---|
297 | ok = CheckIfRawData(s_fname) |
---|
298 | if (ok) |
---|
299 | // read the sample.label text field - OK |
---|
300 | S_Labels[ii]=getSampleLabel(s_fname) |
---|
301 | |
---|
302 | //Transmission - OK as long as it has been patched in ??? |
---|
303 | S_Transmission[ii]=getSampleTrans(s_fname) |
---|
304 | |
---|
305 | //Whole detector Transmission - Don't know where this will be in the file. Need help from epg ??? |
---|
306 | S_Whole[ii]=getSampleTransWholeDetector(s_fname) |
---|
307 | |
---|
308 | //SDD - OK |
---|
309 | S_SDD[ii]=getSDD(s_fname) |
---|
310 | |
---|
311 | //wavelength - OK |
---|
312 | S_Lambda[ii]=getWavelength(s_fname) |
---|
313 | endif |
---|
314 | |
---|
315 | ok = CheckIfRawData(t_fname) |
---|
316 | if (ok) |
---|
317 | // read the sample.label text field - OK |
---|
318 | T_Labels[ii]=getSampleLabel(t_fname) |
---|
319 | |
---|
320 | //Transmission - OK as long as it has been patched in ??? |
---|
321 | //T_Transmission[ii]=getSampleTrans(t_fname) |
---|
322 | |
---|
323 | //Whole detector Transmission - Don't know where this will be in the file. Need help from epg ??? |
---|
324 | //T_Whole[ii]=getSampleTransWholeDetector(t_fname) |
---|
325 | |
---|
326 | //SDD - OK |
---|
327 | T_SDD[ii]=getSDD(t_fname) |
---|
328 | |
---|
329 | //wavelength - OK |
---|
330 | T_Lambda[ii]=getWavelength(t_fname) |
---|
331 | endif |
---|
332 | |
---|
333 | ok = CheckIfRawData(emp_fname) |
---|
334 | if (ok) |
---|
335 | getXYBoxFromFile(emp_fname,x1,x2,y1,y2) |
---|
336 | EMP_x1[ii] = x1 |
---|
337 | EMP_x2[ii] = x2 |
---|
338 | EMP_y1[ii] = y1 |
---|
339 | EMP_y2[ii] = y2 |
---|
340 | endif |
---|
341 | |
---|
342 | ii+=1 |
---|
343 | while(ii<lastPoint) |
---|
344 | |
---|
345 | return(0) |
---|
346 | End |
---|
347 | |
---|
348 | //initialize data folder and globals for the Trans panel as needed |
---|
349 | //since this operation is somewhat tangled with the Patch Panel, keep all of the |
---|
350 | //globals in the Patch subfolder (make sure both panels are simultaneously initialized) |
---|
351 | //do not create a separate Trans folder |
---|
352 | // |
---|
353 | Proc InitializeTransPanel() |
---|
354 | //create the global variables needed to run the Trans Panel |
---|
355 | //all are kept in root:myGlobals:TransHeaderInfo |
---|
356 | If( ! (DataFolderExists("root:myGlobals:TransHeaderInfo")) ) |
---|
357 | //create the data folder and the clobals for BOTH the Patch and Trans Panels |
---|
358 | NewDataFolder/O root:myGlobals:TransHeaderInfo |
---|
359 | CreateTransGlobals() |
---|
360 | Endif |
---|
361 | End |
---|
362 | |
---|
363 | |
---|
364 | // |
---|
365 | Proc CreateTransGlobals() |
---|
366 | |
---|
367 | PathInfo catPathName |
---|
368 | If(V_flag==1) |
---|
369 | String dum = S_path |
---|
370 | String/G root:myGlobals:TransHeaderInfo:gCatPathStr = dum |
---|
371 | else |
---|
372 | String/G root:myGlobals:TransHeaderInfo:gCatPathStr = "no path selected" |
---|
373 | endif |
---|
374 | |
---|
375 | String/G root:myGlobals:TransHeaderInfo:gEMP = "no file selected" |
---|
376 | String/G root:myGlobals:TransHeaderInfo:gBox = "" |
---|
377 | Make/O/T/N=0 $"root:myGlobals:TransHeaderInfo:EMP_Filenames" |
---|
378 | Make/O/T/N=0 $"root:myGlobals:TransHeaderInfo:T_Filenames" |
---|
379 | Make/O/T/N=0 $"root:myGlobals:TransHeaderInfo:T_Labels" |
---|
380 | Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:T_SDD" |
---|
381 | Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:T_Lambda" |
---|
382 | // Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:T_Transmission" |
---|
383 | // Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:T_Whole" |
---|
384 | |
---|
385 | Make/O/T/N=0 $"root:myGlobals:TransHeaderInfo:S_Filenames" |
---|
386 | Make/O/T/N=0 $"root:myGlobals:TransHeaderInfo:S_Labels" |
---|
387 | Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:S_SDD" |
---|
388 | Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:S_Lambda" |
---|
389 | Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:S_Transmission" |
---|
390 | Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:S_Whole" |
---|
391 | |
---|
392 | Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:EMP_x1" |
---|
393 | Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:EMP_x2" |
---|
394 | Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:EMP_y1" |
---|
395 | Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:EMP_y2" |
---|
396 | End |
---|
397 | |
---|
398 | //given a selection of scattering files, calculates the transmission |
---|
399 | //and writes the new transmission to the file header |
---|
400 | // |
---|
401 | //given the full path;name;vers (= filenmame), of a raw binary SANS file, |
---|
402 | //the transmission of the sample is calculated (if possible) from information |
---|
403 | //in the file header. empty beam and sample transmision run numbers are extracted |
---|
404 | //and the files are located from the run number (if possible) |
---|
405 | //from the header of the empty beam file, the XY box coordinates and "empty" |
---|
406 | //counts are determined |
---|
407 | //once all information is located, the transmission is calculated and the |
---|
408 | //transmission field of the sample file is automatically "Patched" |
---|
409 | // - updates the global variable that is displayed in the panel |
---|
410 | //can be run in batch mode, sequentially passing each item from a list of filenames |
---|
411 | //this is the single step of the batch mode |
---|
412 | // |
---|
413 | //in batch mode: execution will proceed through all of the files, reporting |
---|
414 | //results to the history window. If no trans could be successfully calculated |
---|
415 | //(for a blocked beam, for example), then that is displayed as well, and the |
---|
416 | //raw data is not modified |
---|
417 | // |
---|
418 | // now takes the attenuation of the sample trans and empty beam trans into account, (normally this == 1) |
---|
419 | // and rescales the transmission as appropriate |
---|
420 | // 3/31/04 SRK |
---|
421 | // |
---|
422 | Function CalcSelTransFromHeader(startRow,endRow) |
---|
423 | Variable startRow,endRow |
---|
424 | // GetSelection table,ScatterFileTable,1 |
---|
425 | |
---|
426 | String filename |
---|
427 | Wave/T EMP_Filenames = $"root:myGlobals:TransHeaderInfo:EMP_Filenames" |
---|
428 | Wave/T T_Filenames = $"root:myGlobals:TransHeaderInfo:T_Filenames" |
---|
429 | Wave/T S_Filenames = $"root:myGlobals:TransHeaderInfo:S_Filenames" |
---|
430 | |
---|
431 | Wave S_Transmission = $"root:myGlobals:TransHeaderInfo:S_Transmission" |
---|
432 | |
---|
433 | Variable num_s_files, num_t_files, ii, jj |
---|
434 | Variable refnum, transCts, emptyCts,attenRatio,lambda,trans |
---|
435 | Variable x1,x2,y1,y2,err,attenEmp,attenSam |
---|
436 | String suffix = "",pathName,textStr,abortStr,emptyFile,transFile,samFileStr |
---|
437 | String GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=2/W=1/Q" |
---|
438 | String strToExecute |
---|
439 | |
---|
440 | num_t_files = numpnts(T_Filenames) |
---|
441 | |
---|
442 | PathInfo catPathName |
---|
443 | pathname = S_path |
---|
444 | |
---|
445 | ii= startRow |
---|
446 | do |
---|
447 | if (cmpstr(T_Filenames[ii],"")!=0) //if there is a sample trans file assigned |
---|
448 | if (cmpstr(EMP_Filenames[ii],"")!=0) //if empty beam file assigned, proceed with the calculation |
---|
449 | |
---|
450 | //full path+name to access all 3 files |
---|
451 | filename=pathname+S_Filenames[ii] |
---|
452 | emptyFile = pathname+EMP_Filenames[ii] |
---|
453 | transFile = pathname+T_Filenames[ii] |
---|
454 | |
---|
455 | // check the empty beam file for previously selected coordinates |
---|
456 | //if they exist, set the xy string , save the normalized counts somewhere |
---|
457 | GetXYBoxFromFile(emptyFile,x1,x2,y1,y2) |
---|
458 | |
---|
459 | //read the real count value |
---|
460 | emptyCts = getBoxCounts(emptyFile) |
---|
461 | |
---|
462 | // read the attenuator number of the empty beam file |
---|
463 | attenEmp = getAttenNumber(emptyFile) |
---|
464 | // |
---|
465 | if( ((x1-x2)==0) || ((y1-y2)==0) ) //zero width marquee in either direction |
---|
466 | //no region selected -- prompt user to select box w/marquee |
---|
467 | DoWindow/F ScatterFileTable |
---|
468 | Abort "Use \"Set BCENT File\", then \"SetXYBox\" to select XY range in empty beam file "+EMP_Filenames[ii] |
---|
469 | //from here the Marquee menu selection must handle the task of setting the box and updating the information in the file header |
---|
470 | Endif |
---|
471 | |
---|
472 | //read in trans file then add to SAM |
---|
473 | ReadHeaderAndData(transFile) |
---|
474 | //adds to SAM |
---|
475 | err = Raw_to_work("SAM") |
---|
476 | //sum region in SAM |
---|
477 | transCts = SumCountsInBox(x1,x2,y1,y2,"SAM") |
---|
478 | // get the attenuator, lambda, and sample string (to get the instrument) |
---|
479 | WAVE/T samText = $"root:SAM:textRead" |
---|
480 | WAVE samReals = $"root:SAM:realsRead" |
---|
481 | // samfileStr = samText[3] |
---|
482 | lambda = samReals[26] |
---|
483 | attenSam = samReals[3] |
---|
484 | //calculate the ratio of attenuation factors - assumes that same instrument used for each, AND same lambda |
---|
485 | AttenRatio = AttenuationFactor("",lambda,attenEmp)/AttenuationFactor("",lambda,attenSam) |
---|
486 | //calculate trans based on empty beam value and rescale by attenuation ratio |
---|
487 | trans= transCts/emptyCts * AttenRatio |
---|
488 | |
---|
489 | //write out counts and transmission to history window, showing the attenuator ratio, if it is not unity |
---|
490 | If(attenRatio==1) |
---|
491 | Printf "%s\t\tTrans Counts = %g\tTrans = %g\r",S_Filenames[ii], transCts,trans |
---|
492 | else |
---|
493 | Printf "%s\t\tTrans Counts = %g\tTrans = %g\tAttenuatorRatio = %g\r",S_Filenames[ii], transCts,trans,attenRatio |
---|
494 | endif |
---|
495 | //write the trans to the file header of the raw data (open/close done in function) |
---|
496 | WriteTransmissionToHeader(filename,trans) |
---|
497 | |
---|
498 | //then update the global that is displayed |
---|
499 | S_Transmission[ii] = trans |
---|
500 | |
---|
501 | else // There is no empty assigned |
---|
502 | abortStr = "Empty beam file not assigned properly for " + T_Filenames[ii] |
---|
503 | Print abortStr |
---|
504 | //Abort abortStr |
---|
505 | return(1) |
---|
506 | endif |
---|
507 | |
---|
508 | else //no transmission file |
---|
509 | abortStr = "Transmission beam file not assigned properly for " + S_Filenames[ii] |
---|
510 | Print abortStr |
---|
511 | endif |
---|
512 | ii+=1 |
---|
513 | while(ii<=endRow) |
---|
514 | print "done" |
---|
515 | return(0) |
---|
516 | End |
---|
517 | |
---|
518 | // |
---|
519 | // For the calculation of the Transmission using only the Trans Files screen |
---|
520 | // Uses only the information on the transmissionFiles screen to calculate |
---|
521 | // a "box" Transmission for comparison with the Whole Transmission |
---|
522 | // updated 5/11/2006 by Bryan Greenwald |
---|
523 | Function CalcTotalTrans(startRow,endRow) |
---|
524 | Variable startRow,endRow |
---|
525 | // GetSelection table,ScatterFileTable,1 |
---|
526 | |
---|
527 | String filename |
---|
528 | Wave/T EMP_Filenames = $"root:myGlobals:TransHeaderInfo:EMP_Filenames" |
---|
529 | Wave/T T_Filenames = $"root:myGlobals:TransHeaderInfo:T_Filenames" |
---|
530 | // Wave T_GTransmission = $"root:myGlobals:TransHeaderInfo:T_Transmission" |
---|
531 | |
---|
532 | Wave/T S_Filenames = $"root:myGlobals:TransHeaderInfo:S_Filenames" |
---|
533 | // Wave/T S_GFilenames = $"root:myGlobals:TransHeaderInfo:S_Filenames" |
---|
534 | // Wave S_GTransmission = $"root:myGlobals:TransHeaderInfo:S_Transmission" |
---|
535 | // Wave GWhole= $"root:myGlobals:TransHeaderInfo:T_Whole" |
---|
536 | |
---|
537 | Variable num_t_files, ii, jj |
---|
538 | Variable refnum, transCts, emptyCts,attenRatio,lambda,trans |
---|
539 | Variable x1,x2,y1,y2,err,attenEmp,attenSam |
---|
540 | String suffix = "",pathName,textStr,abortStr,emptyFile,transFile,samFileStr |
---|
541 | String GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=2/W=1/Q" |
---|
542 | String strToExecute |
---|
543 | |
---|
544 | // num_t_files = numpnts(T_Filenames) |
---|
545 | |
---|
546 | PathInfo catPathName |
---|
547 | pathname = S_path |
---|
548 | |
---|
549 | ii= startRow |
---|
550 | do |
---|
551 | if (cmpstr(T_Filenames[ii],"")!=0) //if there is a sample trans file assigned |
---|
552 | if (cmpstr(EMP_Filenames[ii],"")!=0) //if empty beam file assigned, proceed with the calculation |
---|
553 | |
---|
554 | //full path+name to access all 3 files |
---|
555 | filename=pathname+S_Filenames[ii] |
---|
556 | emptyFile = pathname+ EMP_Filenames[ii] |
---|
557 | transFile = pathname+T_Filenames[ii] |
---|
558 | ////////// |
---|
559 | // check the empty beam file for previously selected coordinates |
---|
560 | //if they exist, set the xy string , save the normalized counts somewhere |
---|
561 | //the value was written to an unused r*4 header analysis.factor (@b494) |
---|
562 | getXYBoxFromFile(emptyFile,x1,x2,y1,y2) |
---|
563 | |
---|
564 | //read the real count value |
---|
565 | emptyCts = getBoxCounts(emptyFile) |
---|
566 | // read the attenuator number of the empty beam file |
---|
567 | attenEmp = getAttenNumber(emptyFile) |
---|
568 | // |
---|
569 | if( ((x1-x2)==0) || ((y1-y2)==0) ) //zero width marquee in either direction |
---|
570 | //no region selected -- prompt user to select box w/marquee |
---|
571 | DoWindow/F TransFileTable |
---|
572 | Abort "Use \"Set BCENT File\", then \"SetXYBox\" to select XY range in empty beam file "+EMP_Filenames[ii] |
---|
573 | //from here the Marquee menu selection must handle the task of setting the box and updating the information in the file header |
---|
574 | Endif |
---|
575 | |
---|
576 | //read in trans file then add to SAM |
---|
577 | ReadHeaderAndData(transFile) |
---|
578 | //adds to SAM |
---|
579 | err = Raw_to_work("SAM") |
---|
580 | //sum region in SAM |
---|
581 | transCts = SumCountsInBox(x1,x2,y1,y2,"SAM") |
---|
582 | // get the attenuator, lambda, and sample string (to get the instrument) |
---|
583 | WAVE/T samText = $"root:SAM:textRead" |
---|
584 | WAVE samReals = $"root:SAM:realsRead" |
---|
585 | samfileStr = samText[3] |
---|
586 | lambda = samReals[26] |
---|
587 | attenSam = samReals[3] |
---|
588 | //calculate the ratio of attenuation factors - assumes that same instrument used for each, AND same lambda |
---|
589 | AttenRatio = AttenuationFactor("",lambda,attenEmp)/AttenuationFactor("",lambda,attenSam) |
---|
590 | //calculate trans based on empty beam value and rescale by attenuation ratio |
---|
591 | trans= transCts/emptyCts * AttenRatio |
---|
592 | |
---|
593 | //write out counts and transmission to history window, showing the attenuator ratio, if it is not unity |
---|
594 | If(attenRatio==1) |
---|
595 | //Printf "%s\t\tTrans Counts = %g\t Actual Trans = %g\r",T_GFilenames[ii], transCts,trans |
---|
596 | Printf "%s\t\tBox Counts = %g\t Trans = %g\r",T_Filenames[ii], transCts,trans |
---|
597 | else |
---|
598 | //Printf "%s\t\tTrans Counts = %g\t Trans = %g\tAttenuatorRatio = %g\r",T_GFilenames[ii], transCts,trans,attenRatio |
---|
599 | Printf "%s\t\tBox Counts = %g\t Trans = %g\t AttenuatorRatio = %g\r",T_Filenames[ii], transCts,trans,attenRatio |
---|
600 | endif |
---|
601 | //write the trans to the file header of the raw data (open/close done in function) |
---|
602 | WriteTransmissionToHeader(filename,trans) //transmission start byte is 158 |
---|
603 | |
---|
604 | //then update the global that is displayed |
---|
605 | // T_GTransmission[ii] = trans |
---|
606 | |
---|
607 | else // There is no empty assigned |
---|
608 | abortStr = "Empty beam file not assigned properly for " + S_Filenames[jj] |
---|
609 | Print abortStr |
---|
610 | //Abort abortStr |
---|
611 | return(1) |
---|
612 | endif |
---|
613 | else //no transmission file |
---|
614 | abortStr = "Transmission beam file not assigned properly for " + S_Filenames[ii] |
---|
615 | Print abortStr |
---|
616 | endif |
---|
617 | ii+=1 |
---|
618 | while(ii<=endRow) |
---|
619 | //print "done" |
---|
620 | return(0) |
---|
621 | End |
---|
622 | |
---|
623 | // |
---|
624 | // For the calculation of the Transmission using only the whole detector |
---|
625 | // Used to compute the transmission for the TransmissionFiles table using |
---|
626 | // the entire detector. For comparison with the "box" trans |
---|
627 | // updated: 5/11/2006 by Bryan Greenwald |
---|
628 | Function CalcWholeTrans(startRow,endRow) |
---|
629 | Variable startRow,endRow |
---|
630 | // GetSelection table,ScatterFileTable,1 |
---|
631 | |
---|
632 | NVAR pixelsX = root:myGlobals:gNPixelsX |
---|
633 | NVAR pixelsY = root:myGlobals:gNPixelsY |
---|
634 | |
---|
635 | String filename |
---|
636 | Wave/T EMP_Filenames = $"root:myGlobals:TransHeaderInfo:EMP_Filenames" |
---|
637 | |
---|
638 | Wave/T T_Filenames = $"root:myGlobals:TransHeaderInfo:T_Filenames" |
---|
639 | // Wave T_GTransmission = $"root:myGlobals:TransHeaderInfo:T_Transmission" |
---|
640 | |
---|
641 | Wave/T S_Filenames = $"root:myGlobals:TransHeaderInfo:S_Filenames" |
---|
642 | // Wave/T S_GFilenames = $"root:myGlobals:TransHeaderInfo:S_Filenames" |
---|
643 | Wave S_Transmission = $"root:myGlobals:TransHeaderInfo:S_Transmission" |
---|
644 | Wave S_Whole= $"root:myGlobals:TransHeaderInfo:S_Whole" |
---|
645 | |
---|
646 | Variable num_t_files, ii, jj |
---|
647 | Variable refnum, transCts, emptyCts,attenRatio,lambda,trans |
---|
648 | Variable x1,x2,y1,y2,err,attenEmp,attenSam |
---|
649 | String suffix = "",pathName,textStr,abortStr,emptyFile,transFile,samFileStr |
---|
650 | String GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=2/W=1/Q" |
---|
651 | String strToExecute |
---|
652 | |
---|
653 | // num_t_files = numpnts(T_GFilenames) |
---|
654 | |
---|
655 | PathInfo catPathName |
---|
656 | pathname = S_path |
---|
657 | |
---|
658 | ii= startRow |
---|
659 | do |
---|
660 | if (cmpstr(T_Filenames[ii],"")!=0) //if there is a sample trans file assigned |
---|
661 | if (cmpstr(EMP_Filenames[ii],"")!=0) //if empty beam file assigned, proceed with the calculation |
---|
662 | //full path+name to access all 3 files |
---|
663 | filename=pathname+ S_Filenames[ii] |
---|
664 | emptyFile = pathname+EMP_Filenames[ii] |
---|
665 | transFile = pathname+T_Filenames[ii] |
---|
666 | ////////// |
---|
667 | // check the empty beam file for previously selected coordinates |
---|
668 | //if they exist, set the xy string , save the normalized counts somewhere |
---|
669 | //the value was written to an unused r*4 header analysis.factor (@b494) |
---|
670 | |
---|
671 | getXYBoxFromFile(emptyFile,x1,x2,y1,y2) |
---|
672 | //read the real count value |
---|
673 | emptyCts = getBoxCounts(emptyFile) |
---|
674 | // read the attenuator number of the empty beam file |
---|
675 | attenEmp = getAttenNumber(emptyFile) |
---|
676 | // |
---|
677 | if( ((x1-x2)==0) || ((y1-y2)==0) ) //zero width marquee in either direction |
---|
678 | //no region selected -- prompt user to select box w/marquee |
---|
679 | DoWindow/F TransFileTable |
---|
680 | Abort "Use \"Set BCENT File\", then \"SetXYBox\" to select XY range in empty beam file "+EMP_Filenames[ii] |
---|
681 | //from here the Marquee menu selection must handle the task of setting the box and updating the information in the file header |
---|
682 | Endif |
---|
683 | |
---|
684 | //read in trans file then add to SAM |
---|
685 | ReadHeaderAndData(transFile) |
---|
686 | //adds to SAM |
---|
687 | err = Raw_to_work("SAM") |
---|
688 | //sum region in SAM |
---|
689 | transCts = SumCountsInBox(0,pixelsX-1,0,pixelsY-1,"SAM") |
---|
690 | // get the attenuator, lambda, and sample string (to get the instrument) |
---|
691 | WAVE/T samText = $"root:SAM:textRead" |
---|
692 | WAVE samReals = $"root:SAM:realsRead" |
---|
693 | samfileStr = samText[3] |
---|
694 | lambda = samReals[26] |
---|
695 | attenSam = samReals[3] |
---|
696 | //calculate the ratio of attenuation factors - assumes that same instrument used for each, AND same lambda |
---|
697 | AttenRatio = AttenuationFactor("",lambda,attenEmp)/AttenuationFactor("",lambda,attenSam) |
---|
698 | //calculate trans based on empty beam value and rescale by attenuation ratio |
---|
699 | trans= transCts/emptyCts * AttenRatio |
---|
700 | |
---|
701 | //write out counts and transmission to history window, showing the attenuator ratio, if it is not unity |
---|
702 | If(attenRatio==1) |
---|
703 | //Printf "%s\t\tTrans Counts = %g\tTrans using whole detector = %g\t Tbox/Twhole = %g\r",T_GFilenames[ii], transCts,trans,T_GTransmission[ii]/trans |
---|
704 | Printf "%s\t\tTotal Counts = %g\t Trans using whole detector = %g\t",T_Filenames[ii], transCts,trans |
---|
705 | else |
---|
706 | //Printf "%s\t\tTrans Counts = %g\tTrans = %g\tAttenuatorRatio = %g, Tbox/Twhole = %g\r",T_GFilenames[ii], transCts,trans,attenRatio, T_GTransmission[ii]/trans |
---|
707 | Printf "%s\t\tTotal Counts = %g\t Trans using whole detector = %g\t AttenuatorRatio = %g",T_Filenames[ii], transCts,trans,attenRatio |
---|
708 | endif |
---|
709 | If(S_Transmission[ii]/trans > 0.97) |
---|
710 | printf " Tbox/Twhole = %g\r",S_Transmission[ii]/trans |
---|
711 | else |
---|
712 | printf " !!! Tbox/Twhole is low !!! = %g\r",S_Transmission[ii]/trans |
---|
713 | endif |
---|
714 | //write the trans to the file header of the raw data (open/close done in function) |
---|
715 | WriteWholeTransToHeader(filename,trans) |
---|
716 | |
---|
717 | //then update the global that is displayed |
---|
718 | S_Whole[ii] = trans |
---|
719 | |
---|
720 | else // There is no empty assigned |
---|
721 | abortStr = "Empty beam file not assigned properly for " + S_Filenames[ii] |
---|
722 | Print abortStr |
---|
723 | //Abort abortStr |
---|
724 | return(1) |
---|
725 | endif |
---|
726 | |
---|
727 | else //no transmission file |
---|
728 | abortStr = "Transmission beam file not assigned properly for " + S_Filenames[ii] |
---|
729 | Print abortStr |
---|
730 | endif |
---|
731 | ii+=1 |
---|
732 | while(ii<=endRow) |
---|
733 | print "done" |
---|
734 | return(0) |
---|
735 | End |
---|
736 | |
---|
737 | Function PickEMPTransButton(ctrlName) : ButtonControl |
---|
738 | String ctrlName |
---|
739 | |
---|
740 | Variable ScatFileTableExists |
---|
741 | ScatFileTableExists = WinType("ScatterFileTable") |
---|
742 | //??BUG?? V_flag returns 1 even if no selection? |
---|
743 | //check manually for null selection |
---|
744 | //Print "local v_flag = ",num2str(V_flag) |
---|
745 | Wave/T LocFilenames = $"root:myGlobals:TransHeaderInfo:EMP_Filenames" |
---|
746 | if (ScatFileTableExists != 0) |
---|
747 | String/G root:myGlobals:TransHeaderInfo:gEMP = "" |
---|
748 | GetSelection table,ScatterFileTable,7 |
---|
749 | //Print S_Selection |
---|
750 | if(strsearch(S_selection,"EMP_Filenames",0) == 0) |
---|
751 | //selection OK, add to list |
---|
752 | Duplicate/O/R=[V_startRow,V_endRow] LocFilenames, filenames |
---|
753 | Wave/T selectedFiles = $"filenames" |
---|
754 | |
---|
755 | SVAR temp = root:myGlobals:TransHeaderInfo:gEMP |
---|
756 | // |
---|
757 | temp = temp+selectedFiles[0] //take just the first file |
---|
758 | UpdateBoxCoordinates() |
---|
759 | Else |
---|
760 | DoWindow/F ScatterFileTable |
---|
761 | DoAlert 0,"Invalid selection from the Scattering file table. You must select a file from the EMP_Filenames column" |
---|
762 | Endif |
---|
763 | else |
---|
764 | //no selection |
---|
765 | DoAlert 0,"No file selected from Scattering file table or no Scattering file table available" |
---|
766 | Endif |
---|
767 | End |
---|
768 | |
---|
769 | |
---|
770 | //window recreation macro for the Trans Panel |
---|
771 | // |
---|
772 | Proc Trans_Panel() |
---|
773 | PauseUpdate; Silent 1 // building window... |
---|
774 | NewPanel /W=(173,197,540,424)/K=1 as "Calculate Transmissions" |
---|
775 | DoWindow/C Trans_Panel |
---|
776 | ModifyPanel cbRGB=(49807,47186,38011) |
---|
777 | ModifyPanel fixedSize=1 |
---|
778 | SetDrawLayer UserBack |
---|
779 | DrawLine 0,56,368,56 |
---|
780 | DrawLine 0,125,368,125 |
---|
781 | Button pick_emp,pos={4,65},size={105,20},proc=PickEMPTransButton,title="set BCENT file" |
---|
782 | Button pick_emp,help={"This button will set the file selected in the Transmission file table to be the empty beam file."} |
---|
783 | SetVariable empStr,pos={114,67},size={250,17},title="file:" |
---|
784 | SetVariable empStr,help={"Filename of the empty beam file(s) to be used in the transmission calculation"} |
---|
785 | SetVariable empStr,fSize=10 |
---|
786 | SetVariable empStr,limits={-Inf,Inf,0},value= root:myGlobals:TransHeaderInfo:gEMP |
---|
787 | Button Trn_button_1,pos={5,101},size={90,20},proc=Trn_SetXYBoxButton,title="Set XY Box" |
---|
788 | Button Trn_button_1,help={"Sets the XY box to sum over"} |
---|
789 | Button Trn_button_2,pos={174,139},size={110,20},proc=Trn_SortFilesByDate,title="Sort by Date" |
---|
790 | Button Trn_button_2,help={"Sort the scattering and transmission files by creation date."} |
---|
791 | Button Trn_button_3,pos={174,169},size={110,20},proc=Trn_SortFilesByLabel,title="Sort by Label" |
---|
792 | Button Trn_button_3,help={"Sort the scattering and transmission files by label."} |
---|
793 | Button Trn_button_4,pos={295,139},size={67,20},proc=Trn_ShowHelpProc,title="Help" |
---|
794 | Button Trn_button_4,help={"Show a help notebook for calculating transmissions."} |
---|
795 | SetVariable Trn_setvar_1,pos={135,100},size={227,17},title="Box is " |
---|
796 | SetVariable Trn_setvar_1,help={"Box coordinates to sum over"},fSize=10 |
---|
797 | SetVariable Trn_setvar_1,limits={-Inf,Inf,0},value= root:myGlobals:TransHeaderInfo:gBox |
---|
798 | Button Trn_button_0,pos={1,1},size={70,20},proc=Trn_PickPathButton,title="Pick Path" |
---|
799 | Button Trn_button_0,help={"Select the folder containing the SANS data files"} |
---|
800 | Button Trn_button_9,pos={335,1},size={25,20},proc=ShowTransHelp,title="?" |
---|
801 | Button Trn_button_9,help={"Show the help file for calculating sample transmissions"} |
---|
802 | SetVariable Trn_setvar_0,pos={80,4},size={250,17},title="Path" |
---|
803 | SetVariable Trn_setvar_0,help={"Currently selected data path"},fSize=10 |
---|
804 | SetVariable Trn_setvar_0,limits={-Inf,Inf,0},value= root:myGlobals:TransHeaderInfo:gCatPathStr |
---|
805 | Button Trn_button_5,pos={5,169},size={161,20},proc=Trn_CalcAllFilesButton,title="Calculate All Files" |
---|
806 | Button Trn_button_5,help={"Calculate transmission and patch headers of ALL files in the Scattering File Table."} |
---|
807 | Button Trn_button_6,pos={295,198},size={67,20},proc=Trn_PanelDoneButtonProc,title="Done" |
---|
808 | Button Trn_button_6,help={"Close the panel when done calculating transmissions"} |
---|
809 | Button Trn_button_7,pos={67,32},size={214,20},proc=Trn_RefreshProc,title="List Files" |
---|
810 | Button Trn_button_7,help={"Generate or refresh the tables of files."} |
---|
811 | Button Trn_button_8,pos={5,139},size={161,20},proc=Trn_CalcSelectedFilesButton,title="Calculate Selected Files" |
---|
812 | Button Trn_button_8,help={"Calculate transmission and patch headers of selected files in the Scattering File Table."} |
---|
813 | Button Trn_button_10,pos={5,198}, size={161,20},proc=TotalTransButtonProc |
---|
814 | Button Trn_button_10 title="Calculate Total Trans" |
---|
815 | Button Trn_button_10 help={"Calculate transmission over the whole detector and patch headers of ALL files in the data folder."} |
---|
816 | EndMacro |
---|
817 | |
---|
818 | |
---|
819 | Function TotalTransButtonProc(ctrlName) : ButtonControl |
---|
820 | String ctrlName |
---|
821 | TotalTrans(ctrlName) |
---|
822 | End |
---|
823 | |
---|
824 | |
---|
825 | Proc ShowTransHelp(ctrlName) : ButtonControl |
---|
826 | String ctrlName |
---|
827 | DisplayHelpTopic/K=1 "SANS Data Reduction Tutorial[Calculate Transmissions]" |
---|
828 | if(V_flag !=0) |
---|
829 | DoAlert 0,"The SANS Data Reduction Tutorial Help file could not be found" |
---|
830 | endif |
---|
831 | End |
---|
832 | |
---|
833 | |
---|
834 | //generates the file tables of scattering files and transmission files |
---|
835 | // |
---|
836 | // if the tables already exist, they will be updated |
---|
837 | // |
---|
838 | Proc Trn_RefreshProc(ctrlName) : ButtonControl |
---|
839 | String ctrlName |
---|
840 | BuildFileTables() |
---|
841 | End |
---|
842 | |
---|
843 | //shows a noteboox of help text describing how to calculate transmissions |
---|
844 | // - better that the user read the igor or pdf file, but it's a victory to get |
---|
845 | //users to read anything at all |
---|
846 | // |
---|
847 | Proc Trn_ShowHelpProc(ctrlName) : ButtonControl |
---|
848 | String ctrlName |
---|
849 | DisplayTransHelp() |
---|
850 | End |
---|
851 | |
---|
852 | //sorts the tables by date |
---|
853 | // |
---|
854 | Proc Trn_SortFilesByDate(ctrlName) : ButtonControl |
---|
855 | String ctrlName |
---|
856 | SortGlobals(0) |
---|
857 | End |
---|
858 | |
---|
859 | //sorts the tables alphabetically by the sample label field |
---|
860 | // |
---|
861 | Proc Trn_SortFilesByLabel(ctrlName) : ButtonControl |
---|
862 | String ctrlName |
---|
863 | SortGlobals(1) |
---|
864 | End |
---|
865 | |
---|
866 | //button action procedure to select the local path to the |
---|
867 | //folder containing the RAW SANS data files |
---|
868 | // - once the data folder is selected, all of the popup file menus are |
---|
869 | //forced to update with fresh file lists |
---|
870 | // |
---|
871 | Function Trn_PickPathButton(PathButton) : ButtonControl |
---|
872 | String PathButton |
---|
873 | |
---|
874 | //set the global string to the selected pathname |
---|
875 | Variable err |
---|
876 | err = PickPath() |
---|
877 | if(err) |
---|
878 | return(1) //some problem with path or user cancelled, get out |
---|
879 | endif |
---|
880 | |
---|
881 | PathInfo/S catPathName |
---|
882 | String path = S_path |
---|
883 | if (V_flag == 0) |
---|
884 | //path does not exist - no folder selected |
---|
885 | String/G root:myGlobals:TransHeaderInfo:gCatPathStr = "no folder selected" |
---|
886 | else |
---|
887 | String/G root:myGlobals:TransHeaderInfo:gCatPathStr = path |
---|
888 | endif |
---|
889 | |
---|
890 | //Update the pathStr variable box |
---|
891 | ControlUpdate/W=Trans_Panel $"Trn_setvar_0" |
---|
892 | //Generate tables |
---|
893 | Execute "BuildFileTables()" |
---|
894 | |
---|
895 | End |
---|
896 | |
---|
897 | //button action function that asks the user to set the XY box to sum over |
---|
898 | //for all transmission calculations |
---|
899 | // |
---|
900 | // requires the user to set the box coordinates with the marquee popup |
---|
901 | //that wil properly set the keyword string, and write the values to the empty beam header |
---|
902 | // |
---|
903 | Function Trn_SetXYBoxButton(ctrlName) : ButtonControl |
---|
904 | String ctrlName |
---|
905 | |
---|
906 | String msgStr = "Select the Empty Beam File" |
---|
907 | String filename="" |
---|
908 | |
---|
909 | //get the filename from the popup menu |
---|
910 | //and construct a full path to it |
---|
911 | SVAR partialName = root:myGlobals:TransHeaderInfo:gEMP |
---|
912 | print partialName |
---|
913 | //get a valid file based on this partialName and catPathName |
---|
914 | String tempName = FindValidFilename(partialName) |
---|
915 | if(cmpstr(tempName,"")==0) |
---|
916 | //file not found, get out |
---|
917 | Abort "Empty beam file not found Trn_SetXYBoxButton(ctrlName)" |
---|
918 | Endif |
---|
919 | //name is ok, prepend path to tempName for read routine |
---|
920 | PathInfo catPathName |
---|
921 | filename = S_path + tempName |
---|
922 | |
---|
923 | //read the file in - check for previous coordinates |
---|
924 | ReadHeaderAndData(filename) |
---|
925 | //data is displayed here (go through the normal display steps, so all is created properly |
---|
926 | String/G root:myGlobals:gDataDisplayType="RAW" |
---|
927 | fRawWindowHook() |
---|
928 | |
---|
929 | // check the empty beam file for previously selected coordinates |
---|
930 | //if they exist, set the xy string , save the normalized counts somewhere |
---|
931 | //the value was written to an unused r*4 header analysis.factor (@b494) |
---|
932 | Variable refnum,x1,x2,y1,y2,err |
---|
933 | getXYBoxFromFile(filename,x1,x2,y1,y2) |
---|
934 | |
---|
935 | //read the real count value, assign to a global |
---|
936 | Variable/G root:myGlobals:gTransCts = getBoxCounts(filename) //***NOTE this is NOT in the Trans sub-folder |
---|
937 | // |
---|
938 | if( ((x1-x2)==0) || ((y1-y2)==0) ) //zero width marquee in either direction |
---|
939 | //no region selected |
---|
940 | |
---|
941 | //add the empty beam file to work.SAM |
---|
942 | err = Raw_to_work("SAM") |
---|
943 | |
---|
944 | //the calling macro must change the display type |
---|
945 | String/G root:myGlobals:gDataDisplayType="SAM" //displayed data type is sam |
---|
946 | |
---|
947 | //data is displayed here |
---|
948 | fRawWindowHook() |
---|
949 | |
---|
950 | //prompt user to select box w/marquee |
---|
951 | DoAlert 0,"Select the region to sum with the Marquee" |
---|
952 | |
---|
953 | //from here the Marquee menu selection must handle the task of setting the box |
---|
954 | //and updating the information in the file header |
---|
955 | else |
---|
956 | // region already selected, just put up the values from the file header |
---|
957 | //allow user the option of overriding the current box region |
---|
958 | msgStr = "X1="+num2str(x1)+";" |
---|
959 | msgStr += "X2="+num2str(x2)+";" |
---|
960 | msgStr += "Y1="+num2str(y1)+";" |
---|
961 | msgStr += "Y2="+num2str(y2)+";" |
---|
962 | String textStr |
---|
963 | textStr = "Override current box "+msgStr+" ?" |
---|
964 | DoAlert 1,textStr |
---|
965 | If((V_flag)==1) |
---|
966 | //get new box coordinates, same procedure as above |
---|
967 | //add the empty beam file to work.SAM |
---|
968 | err = Raw_to_work("SAM") |
---|
969 | |
---|
970 | //the calling macro must change the display type |
---|
971 | String/G root:myGlobals:gDataDisplayType="SAM" //displayed data type is sam |
---|
972 | |
---|
973 | //data is displayed here |
---|
974 | fRawWindowHook() |
---|
975 | |
---|
976 | //prompt user to select box w/marquee |
---|
977 | DoAlert 0,"Select the region to sum with the Marquee" |
---|
978 | |
---|
979 | //from here the Marquee menu selection must handle the task of setting the box |
---|
980 | //and updating the information in the file header |
---|
981 | else |
---|
982 | String/G root:myGlobals:TransHeaderInfo:gBox = msgStr |
---|
983 | Endif |
---|
984 | Endif |
---|
985 | |
---|
986 | UpdateBoxCoordinates() |
---|
987 | Return (0) |
---|
988 | End |
---|
989 | |
---|
990 | |
---|
991 | //button action function that assigns the selected empty beam file (run number only) |
---|
992 | //and the sample trnansmissionfile (run number only) to the popup list of sample scattering |
---|
993 | //files (ALL of the list items). Assignment is done by writing the integer run numbers of |
---|
994 | //trans files to the header of each of the scattering files, in a batchwise processing |
---|
995 | //of the popup list |
---|
996 | // |
---|
997 | //transmission are not calculated here - only the file numbers are set |
---|
998 | // |
---|
999 | //*********unused*********** |
---|
1000 | //Function Trn_AssignAllFilesButton(ctrlName) : ButtonControl |
---|
1001 | // String ctrlName |
---|
1002 | // |
---|
1003 | // AssignTransFilesToData() |
---|
1004 | // |
---|
1005 | //End |
---|
1006 | |
---|
1007 | //button action procedure to calculate the transmission of all of the sample files in the |
---|
1008 | //sample popup list, based on the information in EACH sample header and in the empty beam file |
---|
1009 | //the box must be set properly in the empty beam file, AND the empty and trans |
---|
1010 | //run number must also be set properly in EACH scattering file, |
---|
1011 | //If run numbers are not properly assigned, no trans is calculated and the |
---|
1012 | //header is not modified |
---|
1013 | // |
---|
1014 | //The RAW data header of EACH sample file IS modified, with the newly calculated transmission |
---|
1015 | // |
---|
1016 | //not very friendly, but forces users to assign the files before continuing |
---|
1017 | // |
---|
1018 | Function Trn_CalcAllFilesButton(ctrlName) : ButtonControl |
---|
1019 | String ctrlName |
---|
1020 | |
---|
1021 | //calculate the transmission and Patch the header (if possible) |
---|
1022 | Wave/T S_Filenames = $"root:myGlobals:TransHeaderInfo:S_Filenames" |
---|
1023 | Variable num_s_files = numpnts(S_Filenames) |
---|
1024 | CalcSelTransFromHeader(0,num_s_files-1) |
---|
1025 | |
---|
1026 | End |
---|
1027 | |
---|
1028 | //for selected scattering files in the scattering table, |
---|
1029 | // the "Annn" association of trans file is written to the data file, |
---|
1030 | // the the transmission is actually calculated |
---|
1031 | // |
---|
1032 | Function Trn_CalcSelectedFilesButton(ctrlName) : ButtonControl |
---|
1033 | String ctrlName |
---|
1034 | |
---|
1035 | Variable scatterTableExists |
---|
1036 | scatterTableExists = WinType("ScatterFileTable") |
---|
1037 | if (scatterTableExists != 0) |
---|
1038 | GetSelection table,ScatterFileTable,1 |
---|
1039 | if(V_Flag != 0) |
---|
1040 | //AssignSelTransFilesToData(V_StartRow,V_EndRow) |
---|
1041 | //calculate the transmission and Patch the header (if possible) |
---|
1042 | CalcSelTransFromHeader(V_StartRow,V_EndRow) |
---|
1043 | Else |
---|
1044 | DoAlert 0,"No selection from Scattering Files table" |
---|
1045 | Endif |
---|
1046 | Else |
---|
1047 | DoAlert 0,"No file selected from Scattering Files table or no Scattering Files table available" |
---|
1048 | Endif |
---|
1049 | End |
---|
1050 | |
---|
1051 | // |
---|
1052 | // I am not sure what the difference is inthe function of CalcTotalTrans and CalcWholeTrans ? |
---|
1053 | // do they really do anything different? |
---|
1054 | // is it a useful calculation at all? |
---|
1055 | // |
---|
1056 | Function TotalTrans(ctrlName) : ButtonControl |
---|
1057 | String ctrlName |
---|
1058 | |
---|
1059 | Variable scatTableExists |
---|
1060 | scatTableExists = WinType("ScatterFileTable") |
---|
1061 | if (scatTableExists != 0) |
---|
1062 | GetSelection table,ScatterFileTable,1 |
---|
1063 | if(V_Flag != 0) |
---|
1064 | //AssignTotalTransFilesToData(V_StartRow,V_EndRow) |
---|
1065 | //calculate the transmission and Patch the header (if possible) |
---|
1066 | CalcTotalTrans(V_StartRow,V_EndRow) |
---|
1067 | CalcWholeTrans(V_StartRow,V_EndRow) |
---|
1068 | Else |
---|
1069 | DoAlert 0,"No selection from Trans Files table" |
---|
1070 | Endif |
---|
1071 | Else |
---|
1072 | DoAlert 0,"No file selected from Trans Files table or no Trans Files table available" |
---|
1073 | Endif |
---|
1074 | End |
---|
1075 | |
---|
1076 | |
---|
1077 | //simple button procedure to close the trans panel |
---|
1078 | // - automatically kills the two tables as well |
---|
1079 | // |
---|
1080 | Function Trn_PanelDoneButtonProc(ctrlName) : ButtonControl |
---|
1081 | String ctrlName |
---|
1082 | |
---|
1083 | // this button will make sure all files are closed |
---|
1084 | //and close the panel |
---|
1085 | |
---|
1086 | Close/A |
---|
1087 | DoWindow/K Trans_Panel |
---|
1088 | DoWindow/K ScatterFileTable |
---|
1089 | DoWindow/K TransFileTable |
---|
1090 | End |
---|
1091 | |
---|
1092 | |
---|
1093 | //function to update the box coordinates of the file selected as the |
---|
1094 | //empty beam file - takes the file that is currently popped from the list |
---|
1095 | //reads the 4 "analysis" integers that hold the box coordinates |
---|
1096 | //resets the globals string that is displayed with the new values |
---|
1097 | //should be called whenever the "empty" popup is popped, to ensure |
---|
1098 | //that current header information is displayed |
---|
1099 | // |
---|
1100 | Function UpdateBoxCoordinates() |
---|
1101 | |
---|
1102 | //construct a full name, and read in the label from the file |
---|
1103 | //and set the global |
---|
1104 | String textstr="" |
---|
1105 | ControlInfo empStr |
---|
1106 | SVAR item = root:myGlobals:TransHeaderInfo:gEMP |
---|
1107 | String tempName = FindValidFilename(item) |
---|
1108 | if(cmpstr(tempName,"")==0) |
---|
1109 | //file not found, get out |
---|
1110 | Abort "Empty beam file not found UpdateBoxCoordinates(ctrlName)" |
---|
1111 | Endif |
---|
1112 | //name is ok, prepend path to tempName for read routine |
---|
1113 | PathInfo catPathName |
---|
1114 | String filename = S_path + tempName |
---|
1115 | |
---|
1116 | Variable refnum,x1,x2,y1,y2,err |
---|
1117 | GetXYBoxFromFile(filename,x1,x2,y1,y2) |
---|
1118 | |
---|
1119 | //and update the global string |
---|
1120 | String msgStr="" |
---|
1121 | msgStr = "X1="+num2str(x1)+";" |
---|
1122 | msgStr += "X2="+num2str(x2)+";" |
---|
1123 | msgStr += "Y1="+num2str(y1)+";" |
---|
1124 | msgStr += "Y2="+num2str(y2)+";" |
---|
1125 | |
---|
1126 | String/G root:myGlobals:TransHeaderInfo:gBox = msgStr |
---|
1127 | |
---|
1128 | ControlUpdate/W=Trans_panel Trn_setvar_1 |
---|
1129 | End |
---|
1130 | |
---|
1131 | //crude procedure to display a notebook of help information for users |
---|
1132 | // |
---|
1133 | Proc DisplayTransHelp() |
---|
1134 | String nb = "Notebook0" |
---|
1135 | NewNotebook/N=$nb/F=1/V=1/W=(342,302,868,674) as "Notebook0:Transmission Help" |
---|
1136 | Notebook $nb defaultTab=36, statusWidth=238, pageMargins={36,72,36,72} |
---|
1137 | Notebook $nb showRuler=1, rulerUnits=1, updating={1, 3600} |
---|
1138 | Notebook $nb newRuler=Normal, justification=0, margins={0,0,468}, spacing={0,0,0}, tabs={}, rulerDefaults={"Geneva",10,0,(0,0,0)} |
---|
1139 | Notebook $nb ruler=Normal; Notebook $nb justification=1, fSize=14, fStyle=1, text="Transmission Help\r" |
---|
1140 | Notebook $nb ruler=Normal, fSize=-1, fStyle=-1, text="\r" |
---|
1141 | Notebook $nb text="This panel allows quick and easy calculation of sample transmission. The neutron transmission of a sampl" |
---|
1142 | Notebook $nb text="e must be calculated and entered into the header of each sample scattering file before proper background" |
---|
1143 | Notebook $nb text=" corrections or absolute scaling can be done.\r" |
---|
1144 | Notebook $nb text="\r" |
---|
1145 | Notebook $nb text="During data collection, you measured an empty beam - that is a measurement with heavy attenuation of th" |
---|
1146 | Notebook $nb text="e neutron beam and the beamstop mover out of line with the direct beam. Then without changing the attenu" |
---|
1147 | Notebook $nb text="ation or replacing the beamstop, you put a sample in the beam, and repeated the measurement (a sample tr" |
---|
1148 | Notebook $nb text="ansmission measurement). The neutron transmission of the sample is simply the ratio of the number of neu" |
---|
1149 | Notebook $nb text="tron counts from the sample transmission measurement normalized by the number of neutron counts from the" |
---|
1150 | Notebook $nb text=" empty beam measurement. In this way, each sample transmission file is \"linked\" to the same empty beam t" |
---|
1151 | Notebook $nb text="ransmission file.\r" |
---|
1152 | Notebook $nb text="\r" |
---|
1153 | Notebook $nb text="This calculated transmission value must be entered into the header of the sample scattering measurement " |
---|
1154 | Notebook $nb text="- that is the measurement of the sample with the beamstop covering the primary (transmitted) beam, and n" |
---|
1155 | Notebook $nb text="o (or few) attenuators in place. In this way, the sample transmission file is \"linked\" to its correspond" |
---|
1156 | Notebook $nb text="ing sample scattering file. This panel allows you to set up the links and calculate the transmission.Tra" |
---|
1157 | Notebook $nb text="nsmisison values are automatically patched to the scattering file headers as they are calculated.\r" |
---|
1158 | Notebook $nb text="\r" |
---|
1159 | Notebook $nb text="To Calculate Transmissions:\r" |
---|
1160 | Notebook $nb text="\r" |
---|
1161 | Notebook $nb text="1) Click \"List Files\" to get two lists (tables) - one of all the sample scattering files in the folder, " |
---|
1162 | Notebook $nb text="and one of the transmission files.\r" |
---|
1163 | Notebook $nb text="\r" |
---|
1164 | Notebook $nb text="2) Select the region of the detector to sum over from the empty beam transmission file. Do theis by clic" |
---|
1165 | Notebook $nb text="king on the filename of the empty beam transmision file (from the TransmissionFiles window, in the blue " |
---|
1166 | Notebook $nb text="\"T_Filenames\" column). Return to the panel, and click the \"set EMP file\" button\", and the filename shoul" |
---|
1167 | Notebook $nb text="d appear in the file box. The \"Box is\" field should have zeros for the x and y coordinates. Click the \"S" |
---|
1168 | Notebook $nb text="et XY Box\" button. The empty beam file will be displayed, and you will be instructed to select the regio" |
---|
1169 | Notebook $nb text="n to sum with the marquee. On the data, click and drag a rectangle that encompasses the primary beam. Mo" |
---|
1170 | Notebook $nb text="ve the cursor inside the selection, to get an \"upside-down hat\" cursor. Click to get a menu, and near th" |
---|
1171 | Notebook $nb text="e bottom, select \"Set XY Box Coords\". The pixel values should be updated to the Transmission panel, and " |
---|
1172 | Notebook $nb text="are written to the empty beam header for future calculations. Note that the marquee selection can also b" |
---|
1173 | Notebook $nb text="e used to measure the beam center, or centroid of any selected region.\r" |
---|
1174 | Notebook $nb text="\r" |
---|
1175 | Notebook $nb text="3) Now you need to \"link\" the ", fStyle=2, text="sample", fStyle=-1, text=" transmission files to the " |
---|
1176 | Notebook $nb fStyle=2, text="empty", fStyle=-1, text=" ", fStyle=2, text="beam", fStyle=-1 |
---|
1177 | Notebook $nb text=" transmission file. Do this in the TransmissionFiles window by selecting the filename (in the blue T_Fil" |
---|
1178 | Notebook $nb text="enames column) and pasing it to the corresponding row(s) in the T_EMP_Filenames column. This links the e" |
---|
1179 | Notebook $nb text="mpty beam transmission with the sample transmission file. Do this for every sample transmission file.\r" |
---|
1180 | Notebook $nb text="\r" |
---|
1181 | Notebook $nb text="4) Now you need to link the sample ", fStyle=2, text="transmission", fStyle=-1 |
---|
1182 | Notebook $nb text=" file to the sample ", fStyle=2, text="scattering", fStyle=-1 |
---|
1183 | Notebook $nb text=" file. Do this by selecting the name of the transmission file (from the blue T_Filenames column) and pas" |
---|
1184 | Notebook $nb text="ting it into the corresponding row of the S_TRANS_Filenames column of the ScatteringFiles window. This l" |
---|
1185 | Notebook $nb text="inks the scattering file to its corresponding sample transmission file. This for all of the sample scatt" |
---|
1186 | Notebook $nb text="ering files.\r" |
---|
1187 | Notebook $nb text="\r" |
---|
1188 | Notebook $nb text="5) Calculate the transmissions (and automatically write the transmission value to the satterng file head" |
---|
1189 | Notebook $nb text="er) by clicking \"Calculate All Files\" from the Transmission Panel. The results will be printed to the co" |
---|
1190 | Notebook $nb text="mmand window at the bottom of the screen. Any improperly assigned files will be listed. For example, blo" |
---|
1191 | Notebook $nb text="cked beam scattering files will return an error, since the transmssion known to be zero, and is not meas" |
---|
1192 | Notebook $nb text="ured (and no files are \"linked\"). Rather than calculating the transmission of all of the files, a range" |
---|
1193 | Notebook $nb text=" of S_Filenames can be selected, then calculated by clicking \"Calculate Selected Files\".\r" |
---|
1194 | Notebook $nb text="\r" |
---|
1195 | Notebook $nb text="By default the lists are sorted by run number (= chronological). In some cases it may be easier to sort " |
---|
1196 | Notebook $nb text="by the sample label to group several of the same sample scattering files collected at different sample-t" |
---|
1197 | Notebook $nb text="o-detector distances. Its utility depends, of course, on how consistent and unique your sample labels ar" |
---|
1198 | Notebook $nb text="e.\r" |
---|
1199 | Notebook $nb text="\r" |
---|
1200 | Notebook $nb text="The \"links\" are stored in the corresponding files, and wil be re-generated when the lists are re-generat" |
---|
1201 | Notebook $nb text="ed. Unassigned links will appear as blank elements in the T_EMP_Filenames or S_TRANS_Filenames columns.\r" |
---|
1202 | Notebook $nb text="\r" |
---|
1203 | Notebook $nb, selection={startOfFile,startOfFile} |
---|
1204 | Notebook $nb text="\r" |
---|
1205 | End |
---|
1206 | |
---|
1207 | |
---|
1208 | |
---|
1209 | //******************* |
---|
1210 | //************ |
---|
1211 | // A simple panel to allow users of the NG1 SANS instrument to make their |
---|
1212 | // transmission files "look" like a transmission measurement to the data reduction |
---|
1213 | // program. Transmission files are designated by an x-position of the beamstop of |
---|
1214 | // < -5 (cm). this simple procedure sets xpos=-10 for individual files. files |
---|
1215 | // con be "un-converted", which set the xpos=0. |
---|
1216 | // 1/30/01 SRK |
---|
1217 | //************ |
---|
1218 | |
---|
1219 | Proc TransformToTransFile() |
---|
1220 | Variable/G root:myGlobals:gConvTrans=1 |
---|
1221 | DoWindow/F Convert_to_Trans |
---|
1222 | if(V_flag==0) |
---|
1223 | Convert2Trans() |
---|
1224 | endif |
---|
1225 | End |
---|
1226 | |
---|
1227 | //fname must be the full path and name for the file |
---|
1228 | Function ChangeBSXPos(fname,xpos) |
---|
1229 | String fname |
---|
1230 | Variable xpos |
---|
1231 | |
---|
1232 | Variable start |
---|
1233 | //x-position starts after byte 368 in VAX files |
---|
1234 | WriteBSXPosToHeader(fname,xpos) |
---|
1235 | return(0) |
---|
1236 | End |
---|
1237 | |
---|
1238 | //sets the beamstop position to zero NOT the original position |
---|
1239 | Function UnConvertButtonProc(ctrlName) : ButtonControl |
---|
1240 | String ctrlName |
---|
1241 | |
---|
1242 | //Print "UnConvert" |
---|
1243 | String fullname="" |
---|
1244 | ControlInfo fileNum |
---|
1245 | Variable num = V_Value //run number to find |
---|
1246 | |
---|
1247 | fullname = FindFileFromRunNumber(num) |
---|
1248 | Print fullname |
---|
1249 | //report error or change the file |
---|
1250 | if(cmpstr(fullname,"")==0) |
---|
1251 | Print "Unconvert - file not found" |
---|
1252 | else |
---|
1253 | //Print "Unconvert",fullname |
---|
1254 | ChangeBSXPos(fullName,0) |
---|
1255 | Endif |
---|
1256 | return(0) |
---|
1257 | End |
---|
1258 | |
---|
1259 | //button procedure to do the conversion |
---|
1260 | // writes fake beamstop position to the data file |
---|
1261 | // |
---|
1262 | Function ConvertButtonProc(ctrlName) : ButtonControl |
---|
1263 | String ctrlName |
---|
1264 | |
---|
1265 | String fullname="" |
---|
1266 | ControlInfo fileNum |
---|
1267 | Variable num = V_Value //run number to find |
---|
1268 | |
---|
1269 | fullname = FindFileFromRunNumber(num) |
---|
1270 | print fullname |
---|
1271 | //report error or change the file |
---|
1272 | if(cmpstr(fullname,"")==0) |
---|
1273 | Print "Convert - file not found" |
---|
1274 | else |
---|
1275 | //Print "Convert",fullname |
---|
1276 | ChangeBSXPos(fullName,-10) |
---|
1277 | Endif |
---|
1278 | return(0) |
---|
1279 | End |
---|
1280 | |
---|
1281 | //simple panel recreation macro |
---|
1282 | // |
---|
1283 | Proc Convert2Trans() |
---|
1284 | PauseUpdate; Silent 1 // building window... |
---|
1285 | NewPanel /W=(434,74,671,216) /K=1 |
---|
1286 | DoWindow/C Convert_to_Trans |
---|
1287 | SetDrawLayer UserBack |
---|
1288 | DrawText 18,22,"Convert files to be recognized" |
---|
1289 | DrawText 43,39,"as transmission files" |
---|
1290 | SetVariable fileNum,pos={43,58},size={130,15},title="File Number" |
---|
1291 | SetVariable fileNum,limits={1,Inf,1},value=root:myGlobals:gConvTrans |
---|
1292 | SetVariable fileNum,help={"Sets the run number of the file that is to be converted"} |
---|
1293 | Button ConvButton,pos={73,79},size={80,20},proc=ConvertButtonProc,title="Convert" |
---|
1294 | Button ConvButton,help={"Converts the chosen file to appear as a transmission file"} |
---|
1295 | Button UndoButton,pos={68,105},size={90,20},proc=UnConvertButtonProc,title="Un-Convert" |
---|
1296 | Button UndoButton,help={"Converts the chosen file to appear as a scattering file"} |
---|
1297 | EndMacro |
---|
1298 | |
---|
1299 | |
---|
1300 | ///// |
---|
1301 | // A quick way to fill all the T_EMP_Filenames with the selected empty beam file |
---|
1302 | // Note that you must go back and clear or reassign any files that are special cases |
---|
1303 | // |
---|
1304 | // IMPORTANT - this will overwrite any other file assignments (typically not a problem |
---|
1305 | // if you are using only one wavelength) |
---|
1306 | // |
---|
1307 | ///// |
---|
1308 | Function FillEMPFilenameWSelection() |
---|
1309 | |
---|
1310 | GetSelection table,TransFileTable,3 |
---|
1311 | Variable row=V_startRow //ony need the selected row, we know the column names and location |
---|
1312 | Wave/T fw = root:myGlobals:TransHeaderInfo:T_FileNames //trans files |
---|
1313 | Wave/T ew = root:myGlobals:TransHeaderInfo:T_EMP_FileNames //empty beam reference files |
---|
1314 | |
---|
1315 | ew[] = fw[row] |
---|
1316 | |
---|
1317 | return(0) |
---|
1318 | End |
---|
1319 | |
---|
1320 | //given a selection of the SAMPLE files, try to find the corresponding transmission file |
---|
1321 | // |
---|
1322 | Function GuessTransFile(charsToUse,row) |
---|
1323 | Variable charsToUse,row //number of characers to use from the beginning of the label, and the row of the sample file |
---|
1324 | |
---|
1325 | // GetSelection table,ScatterFileTable,3 |
---|
1326 | // Variable row=V_startRow //ony need the selected row, we know the column names and location |
---|
1327 | Wave/T sw = root:myGlobals:TransHeaderInfo:S_Labels //Sample file labels |
---|
1328 | Wave/T tw = root:myGlobals:TransHeaderInfo:T_Labels //trans file labels |
---|
1329 | Wave/T tnam = root:myGlobals:TransHeaderInfo:T_FileNames //trans file names |
---|
1330 | Wave/T snam = root:myGlobals:TransHeaderInfo:S_TRANS_FileNames //Scattering - trans correspondence |
---|
1331 | |
---|
1332 | Variable num,ii,found |
---|
1333 | String samStr = "",testStr="" |
---|
1334 | |
---|
1335 | samStr = (sw[row])[0,charsToUse-1] //string to try and match |
---|
1336 | samStr += "*" |
---|
1337 | // Print samStr |
---|
1338 | num=numpnts(tw) |
---|
1339 | ii=0 |
---|
1340 | do |
---|
1341 | testStr=tw[ii] |
---|
1342 | found = stringmatch(testStr, samStr ) |
---|
1343 | if(found == 1) |
---|
1344 | Print "Match Found at: ",samStr,tnam[ii],tw[ii] |
---|
1345 | snam[row] = tnam[ii] //write the file name into the table |
---|
1346 | return(0) |
---|
1347 | endif |
---|
1348 | ii+=1 |
---|
1349 | while(ii<num) |
---|
1350 | |
---|
1351 | //method 2 |
---|
1352 | // samStr = (sw[row])[0,charsToUse-1] //string to try and match |
---|
1353 | //// Print samStr |
---|
1354 | // num=numpnts(tw) |
---|
1355 | // ii=0 |
---|
1356 | // do |
---|
1357 | // testStr=tw[ii] |
---|
1358 | // found = strsearch(testStr,samStr,0) //start from zero, Need Igor 5 to allow 4th parameter to ignore case |
---|
1359 | // if(found != -1) |
---|
1360 | // Print "Match Found at: ",samStr,tnam[ii],tw[ii] |
---|
1361 | // snam[row] = tnam[ii] //write the file name into the table |
---|
1362 | // return(0) |
---|
1363 | // endif |
---|
1364 | // ii+=1 |
---|
1365 | // while(ii<num) |
---|
1366 | |
---|
1367 | Print "No Match found" |
---|
1368 | return(0) |
---|
1369 | End |
---|
1370 | |
---|
1371 | //given a single transmission file, try to find the corresponding scattering file(s) |
---|
1372 | // |
---|
1373 | // apply TWO criteria |
---|
1374 | // (1) the label must match "well enough" |
---|
1375 | // (2) the wavelength must be the same |
---|
1376 | // |
---|
1377 | // passes the matching rows in the sample table back |
---|
1378 | // |
---|
1379 | Function GuessTransToScattFiles(charsToUse,row,matchRows) |
---|
1380 | Variable charsToUse,row //number of characers to use from the beginning of the label, and the row of the transmission file |
---|
1381 | Wave matchRows //rows where (potential) matches found. initially zero points |
---|
1382 | |
---|
1383 | Wave/T sw = root:myGlobals:TransHeaderInfo:S_Labels //Sample file labels |
---|
1384 | Wave/T tw = root:myGlobals:TransHeaderInfo:T_Labels //trans file labels |
---|
1385 | Wave/T tnam = root:myGlobals:TransHeaderInfo:T_FileNames //trans file names |
---|
1386 | Wave/T snam = root:myGlobals:TransHeaderInfo:S_TRANS_FileNames //Scattering - trans correspondence |
---|
1387 | Wave sLam = root:myGlobals:TransHeaderInfo:S_Lambda //Scattering file wavelength |
---|
1388 | Wave tLam = root:myGlobals:TransHeaderInfo:T_Lambda //Transmission file wavelength |
---|
1389 | |
---|
1390 | Variable num,ii,found |
---|
1391 | String transStr = "",testStr="" |
---|
1392 | |
---|
1393 | transStr = (tw[row])[0,charsToUse-1] //string to try and match |
---|
1394 | transStr += "*" |
---|
1395 | |
---|
1396 | //loop over ALL sample files |
---|
1397 | num=numpnts(sw) |
---|
1398 | ii=0 |
---|
1399 | do |
---|
1400 | testStr=sw[ii] |
---|
1401 | found = stringmatch(testStr, transStr ) |
---|
1402 | if( (found == 1) && (sLam[ii] == tLam[row]) ) // both must match |
---|
1403 | Print "Match Found at: ",transStr,snam[ii],sw[ii] |
---|
1404 | InsertPoints numpnts(matchRows), 1, matchRows |
---|
1405 | matchRows[numpnts(matchRows)-1] = ii |
---|
1406 | endif |
---|
1407 | ii+=1 |
---|
1408 | while(ii<num) |
---|
1409 | |
---|
1410 | //method 2 *UNTESTED* |
---|
1411 | // transStr = (tw[row])[0,charsToUse-1] //string to try and match |
---|
1412 | // num=numpnts(sw) |
---|
1413 | // ii=0 |
---|
1414 | // do |
---|
1415 | // testStr=sw[ii] |
---|
1416 | // found = strsearch(testStr,transStr,0,2) //start from zero, ignore case |
---|
1417 | // if(found != -1) |
---|
1418 | // Print "Match Found at: ",transStr,snam[ii],sw[ii] |
---|
1419 | // InsertPoints numpnts(matchRows), 1, matchRows |
---|
1420 | // matchRows[numpnts(matchRows)-1] = ii |
---|
1421 | //// snam[ii] = tnam[row] //write the file name into the table |
---|
1422 | // endif |
---|
1423 | // ii+=1 |
---|
1424 | // while(ii<num) |
---|
1425 | |
---|
1426 | // Print "No Match found" |
---|
1427 | return(0) |
---|
1428 | End |
---|
1429 | |
---|
1430 | //get a single selection from the Trans table |
---|
1431 | // find all of the matching scattering files (rows) |
---|
1432 | // ask the user if the selections are OK |
---|
1433 | // if NOT OK, do nothing |
---|
1434 | // if OK: make the assignments, and immediately calculate the transmission |
---|
1435 | // |
---|
1436 | Function fGuessTransToScattFiles(numChars) |
---|
1437 | Variable numChars |
---|
1438 | |
---|
1439 | Variable ii,row |
---|
1440 | Variable transTableExists |
---|
1441 | Make/O/D/N=0 root:myGlobals:TransHeaderInfo:matchRows |
---|
1442 | Wave matchRows=root:myGlobals:TransHeaderInfo:matchRows |
---|
1443 | |
---|
1444 | transTableExists = WinType("TransFileTable") |
---|
1445 | if (transTableExists != 0) |
---|
1446 | GetSelection table,transFileTable,1 |
---|
1447 | row = V_startRow |
---|
1448 | GuessTransToScattFiles(numChars,row,matchRows) |
---|
1449 | else |
---|
1450 | Print "Transmission->Scattering File table is not open" |
---|
1451 | return (1) |
---|
1452 | endif |
---|
1453 | |
---|
1454 | Wave/T sw = root:myGlobals:TransHeaderInfo:S_Labels //Sample file labels |
---|
1455 | Wave/T tw = root:myGlobals:TransHeaderInfo:T_Labels //trans file labels |
---|
1456 | Wave/T tnam = root:myGlobals:TransHeaderInfo:T_FileNames //trans file names |
---|
1457 | Wave/T snam = root:myGlobals:TransHeaderInfo:S_TRANS_FileNames //Scattering - trans correspondence |
---|
1458 | Wave/T samfile = root:myGlobals:TransHeaderInfo:S_FileNames //Scattering file name |
---|
1459 | |
---|
1460 | // can do fancy formatted string with ... |
---|
1461 | //"asdf* matches file: \\f01filen\\f00 \\K(52428,1,1)\\f01afdsfdd\\f00\\K(0,0,0)asdfasdfs" |
---|
1462 | Variable num=numpnts(matchRows) |
---|
1463 | String result="",tmpStr |
---|
1464 | for(ii=0;ii<num;ii+=1) |
---|
1465 | sprintf tmpStr,"\\f01\\K(52428,1,1)%s\\K(0,0,0)\\f00* Matches file: \\f01%s\\f00 | \\K(52428,1,1)\\f01%s\\f00\\K(0,0,0)%s\r",(tw[row])[0,numChars-1],samfile[matchRows[ii]],(sw[matchRows[ii]])[0,numchars-1],(sw[matchRows[ii]])[numchars,59] |
---|
1466 | result += tmpStr |
---|
1467 | endfor |
---|
1468 | |
---|
1469 | if(cmpstr(result,"")==0) |
---|
1470 | result = "No match found for "+ (tw[row])[0,numChars-1] |
---|
1471 | endif |
---|
1472 | |
---|
1473 | // Print result |
---|
1474 | Print "*******" |
---|
1475 | |
---|
1476 | String/G root:myGlobals:TransHeaderInfo:gResultStr = result |
---|
1477 | |
---|
1478 | DoWindow/F ConfirmGuess //it really shouldn't exist... |
---|
1479 | if(V_flag==1) |
---|
1480 | TitleBox title0,pos={9,5},variable=root:myGlobals:TransHeaderInfo:gResultStr |
---|
1481 | else |
---|
1482 | NewPanel /W=(578,44,1263,214) as "Confirm Guess" |
---|
1483 | DoWindow/C ConfirmGuess |
---|
1484 | TitleBox title0,pos={9,5},size={501,32} |
---|
1485 | TitleBox title0,variable= root:myGlobals:TransHeaderInfo:gResultStr |
---|
1486 | Button button0,pos={9,107},size={190,20},proc=DoAssignTransButtonProc,title="Assign Transmission Files" |
---|
1487 | Button button2,pos={341,108},size={90,20},proc=DoTryAgainButtonProc,title="Try Again" |
---|
1488 | ToolsGrid snap=1,visible=1 |
---|
1489 | endif |
---|
1490 | |
---|
1491 | PauseForUser ConfirmGuess |
---|
1492 | |
---|
1493 | // figure out from the return code what the user did... |
---|
1494 | // 1 = OK, accept guess (assign, and calculate immediately) |
---|
1495 | // 2 = try again |
---|
1496 | // 0 = cancel, don't do anything (not used, simply try again) |
---|
1497 | NVAR guessOK = root:myGlobals:TransHeaderInfo:GuessOK |
---|
1498 | |
---|
1499 | // switch here... |
---|
1500 | switch(guessOK) // numeric switch |
---|
1501 | case 1: |
---|
1502 | // accept guess (assign, and calculate immediately) |
---|
1503 | for(ii=0;ii<num;ii+=1) |
---|
1504 | snam[matchRows[ii]] = tnam[row] |
---|
1505 | //AssignSelTransFilesToData(matchRows[ii],matchRows[ii]) |
---|
1506 | CalcSelTransFromHeader(matchRows[ii],matchRows[ii]) //does only that sample file |
---|
1507 | endfor |
---|
1508 | break |
---|
1509 | case 2: //try again (with more / fewer characters?) |
---|
1510 | // does nothing right now |
---|
1511 | break |
---|
1512 | case 0: |
---|
1513 | // do nothing |
---|
1514 | break |
---|
1515 | default: |
---|
1516 | // do nothing |
---|
1517 | endswitch |
---|
1518 | |
---|
1519 | return(0) |
---|
1520 | End |
---|
1521 | |
---|
1522 | // a hook attached to the Transmission Files Table |
---|
1523 | // given a single selected Trans File, popup gives choices |
---|
1524 | // to guess using "n" characters, then dispatch accordingly |
---|
1525 | Function GuessFromTableHook(infoStr) |
---|
1526 | String infoStr |
---|
1527 | String event= StringByKey("EVENT",infoStr) |
---|
1528 | // Print "EVENT= ",event |
---|
1529 | |
---|
1530 | String menuStr="" |
---|
1531 | menuStr += "Guess using 3 characters;" |
---|
1532 | menuStr += "Guess using 6 characters;" |
---|
1533 | menuStr += "Guess using 9 characters;" |
---|
1534 | menuStr += "Guess using 12 characters;" |
---|
1535 | menuStr += "Guess using 15 characters;" |
---|
1536 | menuStr += "Guess using 18 characters;" |
---|
1537 | menuStr += "Guess using 21 characters;" |
---|
1538 | menuStr += "Guess using 24 characters;" |
---|
1539 | |
---|
1540 | strswitch(event) |
---|
1541 | case "mousedown": |
---|
1542 | Variable xpix= NumberByKey("MOUSEX",infoStr) |
---|
1543 | Variable ypix= NumberByKey("MOUSEY",infoStr) |
---|
1544 | Variable modif= NumberByKey("MODIFIERS",infoStr) |
---|
1545 | //print modif |
---|
1546 | if(modif & 2^1) //bit 1 set, shift key is down |
---|
1547 | PopupContextualMenu/C=(xpix, ypix) menuStr |
---|
1548 | strswitch(S_selection) |
---|
1549 | case "Guess using 3 characters": |
---|
1550 | fGuessTransToScattFiles(3) |
---|
1551 | break |
---|
1552 | case "Guess using 6 characters": |
---|
1553 | fGuessTransToScattFiles(6) |
---|
1554 | break |
---|
1555 | case "Guess using 9 characters": |
---|
1556 | fGuessTransToScattFiles(9) |
---|
1557 | break |
---|
1558 | case "Guess using 12 characters": |
---|
1559 | fGuessTransToScattFiles(12) |
---|
1560 | break |
---|
1561 | case "Guess using 15 characters": |
---|
1562 | fGuessTransToScattFiles(15) |
---|
1563 | break |
---|
1564 | case "Guess using 18 characters": |
---|
1565 | fGuessTransToScattFiles(18) |
---|
1566 | break |
---|
1567 | case "Guess using 21 characters": |
---|
1568 | fGuessTransToScattFiles(21) |
---|
1569 | break |
---|
1570 | case "Guess using 24 characters": |
---|
1571 | fGuessTransToScattFiles(24) |
---|
1572 | break |
---|
1573 | endswitch //on selection |
---|
1574 | endif |
---|
1575 | endswitch // on event |
---|
1576 | |
---|
1577 | return 0 |
---|
1578 | End |
---|
1579 | |
---|
1580 | // sets a flag if the user thinks that the guess was correct, and wants to use the |
---|
1581 | // identified files for the transmission |
---|
1582 | Function DoAssignTransButtonProc(ba) : ButtonControl |
---|
1583 | STRUCT WMButtonAction &ba |
---|
1584 | |
---|
1585 | switch( ba.eventCode ) |
---|
1586 | case 2: // mouse up |
---|
1587 | // click code here |
---|
1588 | //Print "Assigned stuff, and left." |
---|
1589 | Variable/G root:myGlobals:TransHeaderInfo:GuessOK= 1 |
---|
1590 | DoWindow/K ConfirmGuess |
---|
1591 | break |
---|
1592 | endswitch |
---|
1593 | |
---|
1594 | |
---|
1595 | return 0 |
---|
1596 | End |
---|
1597 | |
---|
1598 | // files are wrong, let the user try it again |
---|
1599 | // sets a flag, nothing else |
---|
1600 | Function DoTryAgainButtonProc(ba) : ButtonControl |
---|
1601 | STRUCT WMButtonAction &ba |
---|
1602 | |
---|
1603 | switch( ba.eventCode ) |
---|
1604 | case 2: // mouse up |
---|
1605 | // click code here |
---|
1606 | Variable/G root:myGlobals:TransHeaderInfo:GuessOK= 2 |
---|
1607 | DoWindow/K ConfirmGuess |
---|
1608 | //Print "Try Again" |
---|
1609 | break |
---|
1610 | endswitch |
---|
1611 | |
---|
1612 | return 0 |
---|
1613 | End |
---|
1614 | |
---|
1615 | // not used |
---|
1616 | Function DoCancelGuessButtonProc(ba) : ButtonControl |
---|
1617 | STRUCT WMButtonAction &ba |
---|
1618 | |
---|
1619 | switch( ba.eventCode ) |
---|
1620 | case 2: // mouse up |
---|
1621 | // click code here |
---|
1622 | //just kill the panel, don't do anything |
---|
1623 | Variable/G root:myGlobals:TransHeaderInfo:GuessOK= 0 |
---|
1624 | DoWindow/K ConfirmGuess |
---|
1625 | break |
---|
1626 | endswitch |
---|
1627 | |
---|
1628 | return 0 |
---|
1629 | End |
---|
1630 | |
---|
1631 | Function GuessAllTransFiles(numChars) |
---|
1632 | Variable numChars |
---|
1633 | |
---|
1634 | if(WinType("ScatterFileTable") ==0 ) |
---|
1635 | return(1) |
---|
1636 | endif |
---|
1637 | |
---|
1638 | Wave/T sw = root:myGlobals:TransHeaderInfo:S_Labels //Sample file labels |
---|
1639 | Variable ii,num=numpnts(sw) |
---|
1640 | |
---|
1641 | for(ii=0;ii<num;ii+=1) |
---|
1642 | GuessTransFile(numChars,ii) |
---|
1643 | endfor |
---|
1644 | |
---|
1645 | return(0) |
---|
1646 | End |
---|
1647 | |
---|
1648 | Function fGuessSelectedTransFiles(numChars) |
---|
1649 | Variable numChars |
---|
1650 | |
---|
1651 | Variable ii |
---|
1652 | Variable scatterTableExists |
---|
1653 | scatterTableExists = WinType("ScatterFileTable") |
---|
1654 | if (scatterTableExists != 0) |
---|
1655 | GetSelection table,ScatterFileTable,1 |
---|
1656 | for(ii=V_StartRow;ii<=V_EndRow;ii+=1) |
---|
1657 | GuessTransFile(numChars,ii) |
---|
1658 | endfor |
---|
1659 | else |
---|
1660 | Print "Transmission->Scattering File table is not open" |
---|
1661 | endif |
---|
1662 | return(0) |
---|
1663 | End |
---|
1664 | |
---|
1665 | Function ClearSelectedAssignments() |
---|
1666 | |
---|
1667 | // String winStr = WinList("*", ";", "WIN:" ) //returns the target window |
---|
1668 | // Variable scatterTableExists, transTableExists |
---|
1669 | // Print winStr |
---|
1670 | // scatterTableExists = cmpstr(winStr,"ScatterFileTable;") |
---|
1671 | // if (scatterTableExists == 0) |
---|
1672 | // GetSelection table,ScatterFileTable,1 |
---|
1673 | // fClearSelectedAssignments(V_startRow,V_endRow,1) |
---|
1674 | // endif |
---|
1675 | // |
---|
1676 | // transTableExists = cmpstr(winStr,"TransFileTable;") |
---|
1677 | // if (transTableExists == 0) |
---|
1678 | // GetSelection table,TransFileTable,1 |
---|
1679 | // fClearSelectedAssignments(V_startRow,V_endRow,2) |
---|
1680 | // endif |
---|
1681 | |
---|
1682 | // return(0) |
---|
1683 | End |
---|