1 | #pragma rtGlobals=1 // Use modern global access method. |
---|
2 | #pragma version=5.0 |
---|
3 | #pragma IgorVersion=6.0 |
---|
4 | |
---|
5 | |
---|
6 | //************************* |
---|
7 | // Vers. 1.2 092101 |
---|
8 | // |
---|
9 | // - procedures for (easier) caluclation of transmissions along with |
---|
10 | // simultaneous patching of the calculated transmission in designated |
---|
11 | // raw sans files. |
---|
12 | // - transmission and empty beam files are linked to the dataset by their "Annn" suffix |
---|
13 | // only (and their residence in the same data folder) |
---|
14 | // - unused (analysis) integer values are used to store these run numbers in the sample |
---|
15 | // file headers so that transmissions can be automatically calculated, once the xy box is set |
---|
16 | // in the empty beam file. |
---|
17 | // |
---|
18 | //*************************** |
---|
19 | |
---|
20 | //main entry procedure for displaying the Trans input panel |
---|
21 | //also initializes the globals as needed |
---|
22 | // |
---|
23 | Proc CalcTrans() |
---|
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) // PathInfo returns path doesn't exist |
---|
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 | CreateTransGlobals() |
---|
51 | Variable ScatFileTableExists |
---|
52 | ScatFileTableExists = WinType("ScatterFileTable") |
---|
53 | //if(v_flag==0) |
---|
54 | If(!ScatFileTableExists) |
---|
55 | BuildScatTableWindow() |
---|
56 | ModifyTable width(Point)=18 |
---|
57 | |
---|
58 | ModifyTable width(root:myGlobals:TransHeaderInfo:S_SDD) = 40 |
---|
59 | ModifyTable width(root:myGlobals:TransHeaderInfo:S_Lambda) = 40 |
---|
60 | ModifyTable width(root:myGlobals:TransHeaderInfo:S_Transmission) = 60 |
---|
61 | |
---|
62 | ModifyTable rgb(root:myGlobals:TransHeaderInfo:S_Filenames) = (0,0,65535) |
---|
63 | ModifyTable width(root:myGlobals:TransHeaderInfo:S_Filenames) = 105 |
---|
64 | ModifyTable width(root:myGlobals:TransHeaderInfo:T_Filenames) = 105 |
---|
65 | ModifyTable width(root:myGlobals:TransHeaderInfo:EMP_Filenames) = 105 |
---|
66 | |
---|
67 | ModifyTable width(root:myGlobals:TransHeaderInfo:S_Labels) = 140 |
---|
68 | ModifyTable width(root:myGlobals:TransHeaderInfo:T_Labels) = 140 |
---|
69 | Endif |
---|
70 | |
---|
71 | DoWindow/F ScatterFileTable //bring window to front |
---|
72 | |
---|
73 | //open xml file |
---|
74 | variable fileID = getReport() |
---|
75 | if(fileID<=1) |
---|
76 | Abort "Cannot open experimental report file " + S_filename |
---|
77 | endif |
---|
78 | |
---|
79 | //currently have 2 function to read the 2 types of report files, with and without sample environment |
---|
80 | //trying to merge into 1. |
---|
81 | |
---|
82 | //getFileAssociations(fileID) |
---|
83 | getFileAssociationsSampleEnv(fileID) |
---|
84 | |
---|
85 | //close xml file without save |
---|
86 | XMLclosefile(fileID,0) |
---|
87 | |
---|
88 | //Read data from datafile into globals |
---|
89 | GetTransHeaderInfoToWave() |
---|
90 | |
---|
91 | //Sort entries based on date |
---|
92 | // SortGlobals(0) |
---|
93 | |
---|
94 | //position the windows nicely |
---|
95 | // AutoPositionWindow/M=1/R=ScatterFileTable |
---|
96 | // DoWindow/F Trans_Panel //nha Trans_Panel not required? |
---|
97 | |
---|
98 | End |
---|
99 | |
---|
100 | Function getReport() |
---|
101 | // Open the experiment report file(s) in this path |
---|
102 | variable refnum |
---|
103 | Open/D/R /M="Open experiment report file" /T=".xml" refnum |
---|
104 | if(cmpstr(S_filename,"")==0) |
---|
105 | Abort "No experimental report file selected" |
---|
106 | Endif |
---|
107 | variable fileID = XMLopenFile(S_filename) |
---|
108 | |
---|
109 | return fileID |
---|
110 | |
---|
111 | End |
---|
112 | |
---|
113 | Function getFileAssociations(fileID) |
---|
114 | |
---|
115 | // nha 22/1/2010 - new xml report structure, from December 2009 |
---|
116 | // incompatible with previous report structure |
---|
117 | // assumes the ANSTO filename convention QKKnnnnnnn.nx.hdf |
---|
118 | |
---|
119 | variable fileID |
---|
120 | variable ii,jj |
---|
121 | |
---|
122 | Wave/T S_Filenames = $"root:myGlobals:TransHeaderInfo:S_Filenames" |
---|
123 | Wave/T T_Filenames = $"root:myGlobals:TransHeaderInfo:T_Filenames" |
---|
124 | Wave/T EMP_Filenames = $"root:myGlobals:TransHeaderInfo:EMP_Filenames" |
---|
125 | Wave/T xmlContent = $"root:M_xmlcontent" |
---|
126 | Wave/T xmlContentNodes = $"root:W_xmlcontentnodes" |
---|
127 | |
---|
128 | |
---|
129 | string prefix = "QKK" |
---|
130 | string suffix = ".nx.hdf" |
---|
131 | string full_fname, xpath, xpath_config, xpath_type, xpath_fname, xmlString, list, fname |
---|
132 | variable nConfig, tSamples, sSamples |
---|
133 | wave w_fname |
---|
134 | |
---|
135 | //determine no. of samples |
---|
136 | xpath = "/report//config" //root node of report |
---|
137 | XMLWaveFmXpath(fileID,xpath,"","") |
---|
138 | nConfig = DimSize(xmlContentNodes,0) |
---|
139 | |
---|
140 | ii=1 |
---|
141 | do |
---|
142 | xpath_config = "/report/config[" + num2str(ii) + "]" //there may be multiple config per report |
---|
143 | |
---|
144 | xpath_fname = xpath_config + "/transmission//sample[@type = 'sample']/@runId" //select all sample nodes of type sample and return runId attribute |
---|
145 | XMLwaveFmXpath(fileID,xpath_fname,"","") |
---|
146 | tSamples = DimSize(xmlContentNodes,0) |
---|
147 | |
---|
148 | if(tSamples>=1) //sample exist under the transmission node - probably a more elegant way of get these values into T_Filenames |
---|
149 | jj=0 |
---|
150 | do |
---|
151 | full_fname = prefix + xmlcontent[0][jj] + suffix |
---|
152 | InsertPoints jj,1,T_Filenames |
---|
153 | if(strlen(xmlcontent[0][jj])<7) // assumes the ANSTO filename convention QKKnnnnnnn.nx.hdf |
---|
154 | T_Filenames[jj] = "" |
---|
155 | else |
---|
156 | T_Filenames[jj] = full_fname |
---|
157 | endif |
---|
158 | jj+=1 |
---|
159 | while (jj<tSamples) |
---|
160 | endif |
---|
161 | |
---|
162 | xpath_fname = xpath_config + "/scattering//sample[@type = 'sample']/@runId" //select all sample nodes of type sample and return runId attribute |
---|
163 | XMLwaveFmXpath(fileID,xpath_fname,"","") |
---|
164 | sSamples = DimSize(xmlContentNodes,0) |
---|
165 | |
---|
166 | if(sSamples>=1) //sample exist under the scattering node |
---|
167 | jj=0 |
---|
168 | do |
---|
169 | full_fname = prefix + xmlcontent[0][jj] + suffix |
---|
170 | InsertPoints jj,1,S_Filenames |
---|
171 | if(strlen(xmlcontent[0][jj])<7) // assumes the ANSTO filename convention QKKnnnnnnn.nx.hdf |
---|
172 | S_Filenames[jj] = "" |
---|
173 | else |
---|
174 | S_Filenames[jj] = full_fname |
---|
175 | endif |
---|
176 | jj+=1 |
---|
177 | while (jj<sSamples) |
---|
178 | endif |
---|
179 | |
---|
180 | if(sSamples!=tSamples) |
---|
181 | // the experiment model from Dec 2009 should have equal numbers of scattering and trans |
---|
182 | // sample, according to Tony Lam, although the string may be "" |
---|
183 | //abort "The number transmissions samples in the report file does not equal the number of scattering files" |
---|
184 | endif |
---|
185 | |
---|
186 | // use empty beam for transmission, not empty cell |
---|
187 | //empty beam transmission |
---|
188 | xpath_fname = xpath_config + "/emptyBeamTransmissionRunId" //select all sample nodes of type sample and return runId attribute |
---|
189 | XMLwaveFmXpath(fileID,xpath_fname,"","") |
---|
190 | if(sSamples>=1) //sample exist under the scattering node |
---|
191 | jj=0 |
---|
192 | do |
---|
193 | full_fname = prefix + xmlcontent[0][0] + suffix |
---|
194 | InsertPoints jj,1,EMP_Filenames |
---|
195 | if(strlen(xmlcontent[0][0])<7) // assumes the ANSTO filename convention QKKnnnnnnn.nx.hdf |
---|
196 | EMP_Filenames[jj] = "" |
---|
197 | else |
---|
198 | EMP_Filenames[jj] = full_fname |
---|
199 | endif |
---|
200 | jj+=1 |
---|
201 | while (jj<sSamples) |
---|
202 | endif |
---|
203 | ii+=1 |
---|
204 | while(ii<nConfig+1) //ii is using one-based counting because xml is one-based |
---|
205 | |
---|
206 | //delete rows with blanks |
---|
207 | ii=0 |
---|
208 | do |
---|
209 | if(cmpstr(T_Filenames[ii],"")==0 || cmpstr(S_Filenames[ii],"")==0 || cmpstr(EMP_Filenames[ii],"")==0) |
---|
210 | print "Row is incomplete and therefore being deleted " + T_Filenames[ii] + " " + S_Filenames[ii] + " " + EMP_Filenames[ii] |
---|
211 | DeletePoints ii,1,T_Filenames,S_Filenames,EMP_Filenames |
---|
212 | ii-=1 |
---|
213 | endif |
---|
214 | ii+=1 |
---|
215 | while (ii<DimSize(S_Filenames,0)) |
---|
216 | |
---|
217 | |
---|
218 | //Check if the files in the report file are available in the path. |
---|
219 | // |
---|
220 | |
---|
221 | //Put up a dialog of the number of missing files and their filenames. ABORT or CONTINUE |
---|
222 | // |
---|
223 | |
---|
224 | End |
---|
225 | |
---|
226 | Function/S pickFileInCatPath(fileFilterStr, messageStr) |
---|
227 | |
---|
228 | string fileFilterStr |
---|
229 | string messageStr |
---|
230 | |
---|
231 | variable refNum |
---|
232 | Open/D/R /F=fileFilterStr /M=messageStr refNum |
---|
233 | |
---|
234 | variable len = strlen(S_fileName) |
---|
235 | variable lastSepIndex = strsearch(S_fileName, ":", inf, 1) |
---|
236 | if (lastSepIndex == -1) |
---|
237 | return S_fileName |
---|
238 | else |
---|
239 | svar defaultPath = root:myGlobals:gCatPathStr |
---|
240 | string selectedPath |
---|
241 | variable q = 0 |
---|
242 | |
---|
243 | for (selectedPath = ""; q <= lastSepIndex; q += 1) |
---|
244 | selectedPath += S_fileName[q] |
---|
245 | endfor |
---|
246 | |
---|
247 | if (cmpstr(defaultPath, selectedPath) == 0) // path does match |
---|
248 | |
---|
249 | string result |
---|
250 | for (result = ""; q < len; q += 1) |
---|
251 | result += S_fileName[q] |
---|
252 | endfor |
---|
253 | return result |
---|
254 | |
---|
255 | else // path doesn't match |
---|
256 | DoAlert 1, "You need to pick a file in the same location as the report file. Would you like to pick another file?" |
---|
257 | |
---|
258 | if (V_flag == 1) // answer was yes |
---|
259 | return pickFileInCatPath(fileFilterStr, messageStr) |
---|
260 | else |
---|
261 | return "" |
---|
262 | endif |
---|
263 | endif |
---|
264 | endif |
---|
265 | |
---|
266 | End |
---|
267 | |
---|
268 | Function getFileAssociationsSampleEnv(fileID) |
---|
269 | |
---|
270 | // nha 22/1/2010 - new xml report structure, from December 2009 |
---|
271 | // incompatible with previous report structure |
---|
272 | // assumes the ANSTO filename convention QKKnnnnnnn.nx.hdf |
---|
273 | |
---|
274 | variable fileID |
---|
275 | variable ii, jj |
---|
276 | variable kkS, kkSmax, kkT, kkTmax, kkE |
---|
277 | variable kkToffset |
---|
278 | |
---|
279 | variable s_pos, t_pos |
---|
280 | |
---|
281 | Wave/T S_Filenames = $"root:myGlobals:TransHeaderInfo:S_Filenames" |
---|
282 | Wave/T T_Filenames = $"root:myGlobals:TransHeaderInfo:T_Filenames" |
---|
283 | Wave/T EMP_Filenames = $"root:myGlobals:TransHeaderInfo:EMP_Filenames" |
---|
284 | |
---|
285 | // Wave/T xmlContent = $"root:Packages:NIST:M_xmlcontent" |
---|
286 | // Wave/T xmlContentNodes = $"root:Packages:NIST:W_xmlcontentnodes" // this location doesn't work. Don't know why. nha ??? |
---|
287 | |
---|
288 | // "root:M_xmlcontent" and "root:W_xmlcontentnodes" is not available until XMLWaveFmXpath has been called the first time! [davidm] |
---|
289 | //Wave/T xmlContent = $"root:M_xmlcontent" // this has been move to the lines after: XMLWaveFmXpath |
---|
290 | //Wave/T xmlContentNodes = $"root:W_xmlcontentnodes" |
---|
291 | |
---|
292 | // "root:M_listXPath" is not available until xmlListXPath(fileID,xpath,"") has been called the first time! [davidm] |
---|
293 | // Wave/T listXPath = $"root:M_listXPath" // this has been move to the line after: err = xmlListXPath(fileID,xpath,"") |
---|
294 | |
---|
295 | string prefix = "QKK" |
---|
296 | string suffix = ".nx.hdf" |
---|
297 | string full_fname, xpath, xpath_SampleEnv, xpath_config, xpath_type, xpath_fname, xmlString, list, fname |
---|
298 | variable nSampleEnv, nConfig, tSamples, sSamples |
---|
299 | variable tSampleNum, sSampleNum, eSampleNum // used to accumulate the number of samples across multiple configs |
---|
300 | variable noRunIds |
---|
301 | |
---|
302 | variable hasSampleEnv |
---|
303 | variable err |
---|
304 | |
---|
305 | // to disable asking dialogs |
---|
306 | variable specifyTFile_Enabled = 1 // 0: Disabled; 1: Enabled; 2: Always specify if missing |
---|
307 | variable specifySFile_Enabled = 1 |
---|
308 | variable specifyEMPFile_Enabled = 1 |
---|
309 | |
---|
310 | //in a report there are 0..n /sampleEnvironment |
---|
311 | //these have 1..n or 1..2 /config |
---|
312 | //these have a /transmission /scattering |
---|
313 | //these have 1..n sample which may or maynot have a runId |
---|
314 | //config also has 0..1 /emptyCellTransmissionRunId 0..1 /emptyCellScatteringRunId 0..1 /emptyBeamTransmissionRunId |
---|
315 | |
---|
316 | //determine no. of sampleEnvironment tags |
---|
317 | hasSampleEnv = 0 |
---|
318 | xpath = "/report//sampleEnvironment" //root node of report - what happens if this xpath doesn't exist ???TEST |
---|
319 | // xpath = "/report//config" // for test ??? nha |
---|
320 | |
---|
321 | //check if the file contains the required nodes |
---|
322 | //xmlelementlist(fileID) |
---|
323 | err = xmlListXPath(fileID,xpath,"") // this creates a three column text wave, M_listXPath |
---|
324 | |
---|
325 | Wave/T listXPath = $"root:M_listXPath" |
---|
326 | |
---|
327 | if (err != 0) |
---|
328 | abort "Can't read xml file" |
---|
329 | endif |
---|
330 | |
---|
331 | if (DimSize(listXPath,0) > 0) |
---|
332 | hasSampleEnv = 1 |
---|
333 | else |
---|
334 | xpath = "/report//config" |
---|
335 | endif |
---|
336 | |
---|
337 | nSampleEnv = 0 |
---|
338 | if (hasSampleEnv) |
---|
339 | XMLWaveFmXpath(fileID,xpath,"","") |
---|
340 | |
---|
341 | Wave/T xmlContentNodes = $"root:W_xmlcontentnodes" // [davidm] |
---|
342 | |
---|
343 | nSampleEnv = DimSize(xmlContentNodes,0) |
---|
344 | endif |
---|
345 | ii=1 //sample environment iterator |
---|
346 | |
---|
347 | tSampleNum = 0 |
---|
348 | sSampleNum = 0 |
---|
349 | eSampleNum = 0 |
---|
350 | |
---|
351 | do |
---|
352 | if (hasSampleEnv) |
---|
353 | xpath_SampleEnv = "/report/sampleEnvironment[" + num2str(ii) + "]" //there may be multiple sampleEnvironment per report |
---|
354 | else |
---|
355 | xpath_SampleEnv = "/report" |
---|
356 | endif |
---|
357 | |
---|
358 | //determine no. of config tags |
---|
359 | xpath = xpath_SampleEnv + "//config" |
---|
360 | XMLWaveFmXpath(fileID,xpath,"","") |
---|
361 | |
---|
362 | Wave/T xmlContent = $"root:M_xmlcontent" // [davidm] |
---|
363 | Wave/T xmlContentNodes = $"root:W_xmlcontentnodes" |
---|
364 | |
---|
365 | nConfig = DimSize(xmlContentNodes,0) |
---|
366 | jj=1 // config iterator |
---|
367 | |
---|
368 | do |
---|
369 | // Execute "ProgressWindow spin" |
---|
370 | xpath_config = xpath_SampleEnv + "/config[" + num2str(jj) + "]" //there may be multiple config per report |
---|
371 | |
---|
372 | // get the positions of the s-samples (used to check if report file does not contain all samples) |
---|
373 | xpath_fname = xpath_config + "/scattering//sample[@type = 'sample']/@position" //select all sample nodes of type sample and return position attribute |
---|
374 | XMLwaveFmXpath(fileID,xpath_fname,"","") |
---|
375 | Duplicate /FREE/T xmlcontent, S_Positions |
---|
376 | |
---|
377 | // get the runIds of the s-sampels |
---|
378 | xpath_fname = xpath_config + "/scattering//sample[@type = 'sample']/@runId" //select all sample nodes of type sample and return runId attribute |
---|
379 | XMLwaveFmXpath(fileID,xpath_fname,"","") |
---|
380 | sSamples = DimSize(xmlContentNodes,0) |
---|
381 | kkSmax = sSamples - 1 |
---|
382 | |
---|
383 | // if no runIds are specified then xmlcontent is empty |
---|
384 | noRunIds = DimSize(xmlcontent,0) == 0 |
---|
385 | |
---|
386 | // s-sample exist under the scattering node |
---|
387 | if (sSamples > 0) |
---|
388 | for (kkS = 0; kkS <= kkSmax; kkS += 1) // scattering sample iterator |
---|
389 | |
---|
390 | InsertPoints sSampleNum + kkS, 1, S_Filenames |
---|
391 | |
---|
392 | if (noRunIds) |
---|
393 | S_Filenames[sSampleNum + kkS] = "" |
---|
394 | else |
---|
395 | full_fname = prefix + xmlcontent[0][kkS] + suffix |
---|
396 | if (strlen(xmlcontent[0][kkS]) < 7) // assumes the ANSTO filename convention QKKnnnnnnn.nx.hdf |
---|
397 | S_Filenames[sSampleNum + kkS] = "" |
---|
398 | else |
---|
399 | S_Filenames[sSampleNum + kkS] = full_fname |
---|
400 | endif |
---|
401 | endif |
---|
402 | |
---|
403 | endfor |
---|
404 | endif |
---|
405 | |
---|
406 | // get the positions of the t-samples (used to check if report file does not contain samples) |
---|
407 | xpath_fname = xpath_config + "/transmission//sample[@type = 'sample']/@position" //select all sample nodes of type sample and return position attribute |
---|
408 | XMLwaveFmXpath(fileID,xpath_fname,"","") |
---|
409 | Duplicate /FREE/T xmlcontent, T_Positions |
---|
410 | |
---|
411 | // get the runIds of the t-sampels |
---|
412 | xpath_fname = xpath_config + "/transmission//sample[@type = 'sample']/@runId" //select all sample nodes of type sample and return runId attribute |
---|
413 | XMLwaveFmXpath(fileID,xpath_fname,"","") |
---|
414 | tSamples = DimSize(xmlContentNodes,0) |
---|
415 | kkTmax = tSamples - 1 |
---|
416 | |
---|
417 | // if no runIds are specified then xmlcontent is empty |
---|
418 | noRunIds = DimSize(xmlcontent,0) == 0 |
---|
419 | |
---|
420 | // we need to know how many t-samples are added (if report file does not contain all t-sampels) |
---|
421 | kkToffset = 0 |
---|
422 | |
---|
423 | // t-sample exist under the transmission node |
---|
424 | if (tSamples > 0) |
---|
425 | for (kkS = 0, kkT = 0; kkT <= kkTmax;) // transmission sample iterator |
---|
426 | |
---|
427 | // we need to compare the position of the current s- and t-sample |
---|
428 | if (kkS <= kkSmax) |
---|
429 | s_pos = str2num(S_Positions[0][kkS]) |
---|
430 | else |
---|
431 | s_pos = Inf // this means that at least one s-sample is missing |
---|
432 | endif |
---|
433 | t_pos = str2num(T_Positions[0][kkT]) |
---|
434 | |
---|
435 | if (s_pos < t_pos) // t-sample is missing |
---|
436 | |
---|
437 | if (specifyTFile_Enabled) |
---|
438 | DoAlert 1, "For the S-File \"" + S_Filenames[tSampleNum+kkS] + "\" (position " + S_Positions[0][kkS] + ") no T-File was specified. Would you like to select one now?" |
---|
439 | else |
---|
440 | V_flag = 0 // if disabled then answer is always no |
---|
441 | endif |
---|
442 | |
---|
443 | // insert new t-sample |
---|
444 | InsertPoints tSampleNum + kkT + kkToffset, 1, T_Filenames |
---|
445 | if (V_flag != 1) // answer was no |
---|
446 | T_Filenames[tSampleNum + kkT + kkToffset] = "" |
---|
447 | |
---|
448 | if (specifyTFile_Enabled == 1) |
---|
449 | DoAlert 1, "Would you like to specify any missing T-Files?" |
---|
450 | if (V_flag != 1) // answer was no |
---|
451 | specifyTFile_Enabled = 0 |
---|
452 | else |
---|
453 | specifyTFile_Enabled = 2 |
---|
454 | endif |
---|
455 | endif |
---|
456 | |
---|
457 | else |
---|
458 | T_Filenames[tSampleNum + kkT + kkToffset] = pickFileInCatPath("Hierarchical Data Format (*.nx.hdf):.nx.hdf;All Files:.*;", "Select the corresponding T-File") |
---|
459 | endif |
---|
460 | |
---|
461 | kkToffset += 1 |
---|
462 | kkS += 1 |
---|
463 | tSamples += 1 |
---|
464 | |
---|
465 | else // insert t-sample from report file |
---|
466 | |
---|
467 | InsertPoints tSampleNum + kkT + kkToffset, 1, T_Filenames |
---|
468 | |
---|
469 | if (noRunIds) |
---|
470 | T_Filenames[tSampleNum + kkT + kkToffset] = "" |
---|
471 | else |
---|
472 | full_fname = prefix + xmlcontent[0][kkT] + suffix |
---|
473 | if(strlen(xmlcontent[0][kkT]) < 7) // assumes the ANSTO filename convention QKKnnnnnnn.nx.hdf |
---|
474 | T_Filenames[tSampleNum + kkT + kkToffset] = "" |
---|
475 | else |
---|
476 | T_Filenames[tSampleNum + kkT + kkToffset] = full_fname |
---|
477 | endif |
---|
478 | endif |
---|
479 | |
---|
480 | kkT += 1 |
---|
481 | |
---|
482 | if (s_pos == t_pos) |
---|
483 | kkS += 1 |
---|
484 | else // s-sample is missing |
---|
485 | |
---|
486 | if (specifySFile_Enabled) |
---|
487 | DoAlert 1, "For the T-File \"" + T_Filenames[tSampleNum+kkT] + "\" (position " + T_Positions[0][kkT] + ") no S-File was specified. Would you like to select one now?" |
---|
488 | else |
---|
489 | V_flag = 0 // if disabled then answer is always no |
---|
490 | endif |
---|
491 | |
---|
492 | // insert new s-sample |
---|
493 | InsertPoints tSampleNum + kkT + kkToffset, 1, S_Filenames |
---|
494 | if (V_flag != 1) // answer was no |
---|
495 | S_Filenames[tSampleNum + kkT + kkToffset] = "" |
---|
496 | |
---|
497 | if (specifySFile_Enabled == 1) |
---|
498 | DoAlert 1, "Would you like to specify any missing S-Files?" |
---|
499 | if (V_flag != 1) // answer was no |
---|
500 | specifySFile_Enabled = 0 |
---|
501 | else |
---|
502 | specifySFile_Enabled = 2 |
---|
503 | endif |
---|
504 | endif |
---|
505 | |
---|
506 | else |
---|
507 | S_Filenames[tSampleNum + kkT + kkToffset] = pickFileInCatPath("Hierarchical Data Format (*.nx.hdf):.nx.hdf;All Files:.*;", "Select the corresponding S-File") |
---|
508 | endif |
---|
509 | |
---|
510 | sSamples += 1 |
---|
511 | endif |
---|
512 | endif |
---|
513 | endfor |
---|
514 | endif |
---|
515 | |
---|
516 | if (sSamples > tSamples) // checks if t-samples are still missing |
---|
517 | do |
---|
518 | if (specifyTFile_Enabled) |
---|
519 | DoAlert 1, "For the S-File \"" + S_Filenames[tSampleNum+kkS] + "\" (position " + S_Positions[0][kkS] + ") no T-File was specified. Would you like to select one now?" |
---|
520 | else |
---|
521 | V_flag = 0 // if disabled then answer is always no |
---|
522 | endif |
---|
523 | |
---|
524 | // insert new t-sample |
---|
525 | InsertPoints tSampleNum + kkT + kkToffset, 1, T_Filenames |
---|
526 | if (V_flag != 1) // answer was no |
---|
527 | |
---|
528 | T_Filenames[tSampleNum + kkT + kkToffset] = "" |
---|
529 | |
---|
530 | if (specifyTFile_Enabled == 1) |
---|
531 | DoAlert 1, "Would you like to specify any missing T-Files?" |
---|
532 | if (V_flag != 1) // answer was no |
---|
533 | specifyTFile_Enabled = 0 |
---|
534 | else |
---|
535 | specifyTFile_Enabled = 2 |
---|
536 | endif |
---|
537 | endif |
---|
538 | |
---|
539 | else |
---|
540 | T_Filenames[tSampleNum + kkT + kkToffset] = pickFileInCatPath("Hierarchical Data Format (*.nx.hdf):.nx.hdf;All Files:.*;", "Select the corresponding T-File") |
---|
541 | endif |
---|
542 | |
---|
543 | kkToffset += 1 |
---|
544 | kkS += 1 |
---|
545 | tSamples += 1 |
---|
546 | |
---|
547 | while (sSamples > tSamples) |
---|
548 | endif |
---|
549 | |
---|
550 | tSampleNum += tSamples |
---|
551 | sSampleNum += sSamples |
---|
552 | |
---|
553 | // empty beam transmission |
---|
554 | xpath_fname = xpath_config + "/emptyBeamTransmissionRunId" |
---|
555 | XMLwaveFmXpath(fileID,xpath_fname,"","") |
---|
556 | |
---|
557 | if (sSamples>=1) //sample exist under the scattering node |
---|
558 | |
---|
559 | if (WaveDims(xmlcontent) && (strlen(xmlcontent[0][0]) == 7)) // assumes the ANSTO filename convention QKKnnnnnnn.nx.hdf |
---|
560 | full_fname = prefix + xmlcontent[0][0] + suffix |
---|
561 | else |
---|
562 | kkS = sSampleNum-sSamples |
---|
563 | string sFilenames = S_Filenames[kkS] |
---|
564 | |
---|
565 | for (kkS += 1; kkS < sSampleNum; kkS += 1) |
---|
566 | if (strlen(S_Filenames[kkS]) > 0) |
---|
567 | sFilenames = sFilenames + ", " + S_Filenames[kkS] |
---|
568 | endif |
---|
569 | endfor |
---|
570 | |
---|
571 | // only ask if sFilenames is not empty |
---|
572 | full_fname = "" |
---|
573 | if (strlen(sFilenames) > 0) |
---|
574 | |
---|
575 | if (specifyEMPFile_Enabled) |
---|
576 | DoAlert 1, "For the listed S-File(s), no appropriate EMP-File was specified. Would you like to select one now?\n" + sFilenames |
---|
577 | else |
---|
578 | V_flag = 0 // if disabled then answer is always no |
---|
579 | endif |
---|
580 | |
---|
581 | if (V_flag == 1) // answer was yes |
---|
582 | full_fname = pickFileInCatPath("Hierarchical Data Format (*.nx.hdf):.nx.hdf;All Files:.*;", "Select an EMP-File") |
---|
583 | elseif (specifyEMPFile_Enabled == 1) |
---|
584 | DoAlert 1, "Would you like to specify any missing EMP-Files?" |
---|
585 | if (V_flag != 1) // answer was no |
---|
586 | specifyEMPFile_Enabled = 0 |
---|
587 | else |
---|
588 | specifyEMPFile_Enabled = 2 |
---|
589 | endif |
---|
590 | endif |
---|
591 | endif |
---|
592 | endif |
---|
593 | |
---|
594 | kkE = 0 |
---|
595 | do |
---|
596 | InsertPoints eSampleNum + kkE,1,EMP_Filenames |
---|
597 | EMP_Filenames[eSampleNum + kkE] = full_fname |
---|
598 | kkE += 1 |
---|
599 | while (kkE < sSamples) |
---|
600 | |
---|
601 | eSampleNum += sSamples |
---|
602 | endif |
---|
603 | |
---|
604 | jj += 1 |
---|
605 | while(jj<nConfig+1) |
---|
606 | ii+=1 |
---|
607 | while(ii<nsampleEnv+1) //ii is using one-based counting because xml is one-based |
---|
608 | |
---|
609 | //delete rows with blanks |
---|
610 | // ??? testing without removal of blanks. nha. |
---|
611 | // ii=0 |
---|
612 | // do |
---|
613 | // if(cmpstr(T_Filenames[ii],"")==0 || cmpstr(S_Filenames[ii],"")==0 || cmpstr(EMP_Filenames[ii],"")==0) |
---|
614 | // print "Row is incomplete and therefore being deleted " + T_Filenames + " " + S_Filenames + " " + EMP_Filenames |
---|
615 | // DeletePoints ii,1,T_Filenames,S_Filenames,EMP_Filenames |
---|
616 | // ii-=1 |
---|
617 | // endif |
---|
618 | // ii+=1 |
---|
619 | // while (ii<DimSize(S_Filenames,0)) |
---|
620 | |
---|
621 | |
---|
622 | //Check if the files in the report file are available in the path. |
---|
623 | // |
---|
624 | |
---|
625 | //Put up a dialog of the number of missing files and their filenames. ABORT or CONTINUE |
---|
626 | // |
---|
627 | |
---|
628 | End |
---|
629 | |
---|
630 | //actually creates the table of scattering files |
---|
631 | // - the waves must exist |
---|
632 | // |
---|
633 | Function BuildScatTableWindow() |
---|
634 | Wave/T S_Filenames = $"root:myGlobals:TransHeaderInfo:S_Filenames" |
---|
635 | Wave/T T_Filenames = $"root:myGlobals:TransHeaderInfo:T_Filenames" |
---|
636 | Wave/T EMP_Filenames = $"root:myGlobals:TransHeaderInfo:EMP_Filenames" |
---|
637 | Wave/T S_Labels = $"root:myGlobals:TransHeaderInfo:S_Labels" |
---|
638 | Wave/T T_Labels = $"root:myGlobals:TransHeaderInfo:T_Labels" |
---|
639 | Wave S_SDD = $"root:myGlobals:TransHeaderInfo:S_SDD" |
---|
640 | Wave S_Lambda = $"root:myGlobals:TransHeaderInfo:S_Lambda" |
---|
641 | Wave S_Transmission = $"root:myGlobals:TransHeaderInfo:S_Transmission" |
---|
642 | Wave S_Whole= $"root:myGlobals:TransHeaderInfo:S_Whole" |
---|
643 | Wave T_SDD = $"root:myGlobals:TransHeaderInfo:T_SDD" |
---|
644 | Wave T_Lambda = $"root:myGlobals:TransHeaderInfo:T_Lambda" |
---|
645 | // Wave T_Transmission = $"root:myGlobals:TransHeaderInfo:T_Transmission" |
---|
646 | // Wave T_Whole= $"root:myGlobals:TransHeaderInfo:T_Whole" |
---|
647 | Wave EMP_x1= $"root:myGlobals:TransHeaderInfo:EMP_x1" |
---|
648 | Wave EMP_x2= $"root:myGlobals:TransHeaderInfo:EMP_x2" |
---|
649 | Wave EMP_y1= $"root:myGlobals:TransHeaderInfo:EMP_y1" |
---|
650 | Wave EMP_y2= $"root:myGlobals:TransHeaderInfo:EMP_y2" |
---|
651 | |
---|
652 | Edit/K=1/W=(20,20,520,470) 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" |
---|
653 | |
---|
654 | String name="ScatterFileTable" |
---|
655 | DoWindow/C $name |
---|
656 | |
---|
657 | End |
---|
658 | |
---|
659 | |
---|
660 | //sorts each of the tables by date - does this by using the suffix "Annn" |
---|
661 | // which is automatically supplied by the VAX (and can't be changed) |
---|
662 | // - only problem may be "Z999" -> "A001" rollover |
---|
663 | // |
---|
664 | // sorts files alphabetically byt the sample label |
---|
665 | // - consistent and descriptive sample labels really pay off here |
---|
666 | // |
---|
667 | Function SortGlobals(sortFlag) |
---|
668 | Variable sortFlag |
---|
669 | |
---|
670 | Wave/T EMP_Filenames = $"root:myGlobals:TransHeaderInfo:EMP_Filenames" |
---|
671 | Wave/T T_Filenames = $"root:myGlobals:TransHeaderInfo:T_Filenames" |
---|
672 | Wave/T T_Labels = $"root:myGlobals:TransHeaderInfo:T_Labels" |
---|
673 | Wave T_SDD = $"root:myGlobals:TransHeaderInfo:T_SDD" |
---|
674 | Wave T_Lambda = $"root:myGlobals:TransHeaderInfo:T_Lambda" |
---|
675 | // Wave T_Transmission = $"root:myGlobals:TransHeaderInfo:T_Transmission" |
---|
676 | // Wave T_Whole= $"root:myGlobals:TransHeaderInfo:T_Whole" |
---|
677 | |
---|
678 | Wave/T S_Filenames = $"root:myGlobals:TransHeaderInfo:S_Filenames" |
---|
679 | Wave/T S_Labels = $"root:myGlobals:TransHeaderInfo:S_Labels" |
---|
680 | Wave S_SDD = $"root:myGlobals:TransHeaderInfo:S_SDD" |
---|
681 | Wave S_Lambda = $"root:myGlobals:TransHeaderInfo:S_Lambda" |
---|
682 | Wave S_Transmission = $"root:myGlobals:TransHeaderInfo:S_Transmission" |
---|
683 | Wave S_Whole= $"root:myGlobals:TransHeaderInfo:S_Whole" |
---|
684 | |
---|
685 | Wave EMP_x1= $"root:myGlobals:TransHeaderInfo:EMP_x1" |
---|
686 | Wave EMP_x2= $"root:myGlobals:TransHeaderInfo:EMP_x2" |
---|
687 | Wave EMP_y1= $"root:myGlobals:TransHeaderInfo:EMP_y1" |
---|
688 | Wave EMP_y2= $"root:myGlobals:TransHeaderInfo:EMP_y2" |
---|
689 | |
---|
690 | if(sortFlag == 0) // by date |
---|
691 | 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 |
---|
692 | else //by label |
---|
693 | 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 |
---|
694 | endif |
---|
695 | End |
---|
696 | |
---|
697 | //reads the file and assigns header information to globals, which are read by the ScatteringTable. |
---|
698 | //assumes that associations have been found in experiment report |
---|
699 | // |
---|
700 | //scat_fname - is the full path:name of the datafile (used by Open) |
---|
701 | // |
---|
702 | // takes care of all necessary open/close of file |
---|
703 | // |
---|
704 | Function GetTransHeaderInfoToWave() |
---|
705 | |
---|
706 | String s_fname,t_fname,emp_fname |
---|
707 | |
---|
708 | Variable lastPoint, ii |
---|
709 | |
---|
710 | Wave/T S_Filenames = $"root:myGlobals:TransHeaderInfo:S_Filenames" |
---|
711 | Wave/T T_Filenames = $"root:myGlobals:TransHeaderInfo:T_Filenames" |
---|
712 | Wave/T EMP_Filenames = $"root:myGlobals:TransHeaderInfo:EMP_Filenames" |
---|
713 | Wave/T S_Labels = $"root:myGlobals:TransHeaderInfo:S_Labels" |
---|
714 | Wave/T T_Labels = $"root:myGlobals:TransHeaderInfo:T_Labels" |
---|
715 | Wave S_SDD = $"root:myGlobals:TransHeaderInfo:S_SDD" |
---|
716 | Wave S_Lambda = $"root:myGlobals:TransHeaderInfo:S_Lambda" |
---|
717 | Wave S_Transmission = $"root:myGlobals:TransHeaderInfo:S_Transmission" |
---|
718 | Wave S_Whole= $"root:myGlobals:TransHeaderInfo:S_Whole" |
---|
719 | Wave T_SDD = $"root:myGlobals:TransHeaderInfo:T_SDD" |
---|
720 | Wave T_Lambda = $"root:myGlobals:TransHeaderInfo:T_Lambda" |
---|
721 | // Wave T_Transmission = $"root:myGlobals:TransHeaderInfo:T_Transmission" |
---|
722 | // Wave T_Whole= $"root:myGlobals:TransHeaderInfo:T_Whole" |
---|
723 | |
---|
724 | Wave EMP_x1= $"root:myGlobals:TransHeaderInfo:EMP_x1" |
---|
725 | Wave EMP_x2= $"root:myGlobals:TransHeaderInfo:EMP_x2" |
---|
726 | Wave EMP_y1= $"root:myGlobals:TransHeaderInfo:EMP_y1" |
---|
727 | Wave EMP_y2= $"root:myGlobals:TransHeaderInfo:EMP_y2" |
---|
728 | |
---|
729 | lastPoint = numpnts(S_Filenames) |
---|
730 | PathInfo catPathName |
---|
731 | variable x1, x2, y1, y2 |
---|
732 | |
---|
733 | variable FilesAreMissing = 0 |
---|
734 | |
---|
735 | // Execute "ProgressWindow open, text=\"Loading Table...\"" |
---|
736 | |
---|
737 | ii = 0 |
---|
738 | do |
---|
739 | s_fname = S_path + S_Filenames[ii] |
---|
740 | t_fname = S_path + T_Filenames[ii] |
---|
741 | emp_fname = S_path + EMP_Filenames[ii] |
---|
742 | |
---|
743 | // Execute "ProgressWindow text=\"Loading Table...\n" + S_Filenames[ii] + "\"" |
---|
744 | |
---|
745 | InsertPoints ii,1,S_Labels |
---|
746 | InsertPoints ii,1,S_Transmission |
---|
747 | InsertPoints ii,1,S_Whole |
---|
748 | InsertPoints ii,1,S_SDD |
---|
749 | InsertPoints ii,1,S_Lambda |
---|
750 | InsertPoints ii,1,T_Labels |
---|
751 | // InsertPoints ii,1,T_Transmission |
---|
752 | // InsertPoints ii,1,T_Whole |
---|
753 | InsertPoints ii,1,T_SDD |
---|
754 | InsertPoints ii,1,T_Lambda |
---|
755 | InsertPoints ii,1,EMP_x1 |
---|
756 | InsertPoints ii,1,EMP_x2 |
---|
757 | InsertPoints ii,1,EMP_y1 |
---|
758 | InsertPoints ii,1,EMP_y2 |
---|
759 | |
---|
760 | if (CheckIfFileExists(s_fname)) |
---|
761 | if (CheckIfRawData(s_fname)) |
---|
762 | // read the sample.label text field - OK |
---|
763 | S_Labels[ii]=getSampleLabel(s_fname) |
---|
764 | |
---|
765 | //Transmission - OK as long as it has been patched in ??? |
---|
766 | S_Transmission[ii]=getSampleTrans(s_fname) |
---|
767 | |
---|
768 | //Whole detector Transmission - Don't know where this will be in the file. Need help from epg ??? |
---|
769 | S_Whole[ii]=getSampleTransWholeDetector(s_fname) |
---|
770 | |
---|
771 | //SDD - OK |
---|
772 | S_SDD[ii]=getSDD(s_fname) |
---|
773 | |
---|
774 | //wavelength - OK |
---|
775 | S_Lambda[ii]=getWavelength(s_fname) |
---|
776 | endif |
---|
777 | else |
---|
778 | S_Filenames[ii] = "? " + S_Filenames[ii] |
---|
779 | FilesAreMissing = 1 |
---|
780 | endif |
---|
781 | |
---|
782 | if (CheckIfFileExists(t_fname)) |
---|
783 | if (CheckIfRawData(t_fname)) |
---|
784 | // read the sample.label text field - OK |
---|
785 | T_Labels[ii]=getSampleLabel(t_fname) |
---|
786 | |
---|
787 | //Transmission - OK as long as it has been patched in ??? |
---|
788 | //T_Transmission[ii]=getSampleTrans(t_fname) |
---|
789 | |
---|
790 | //Whole detector Transmission - Don't know where this will be in the file. Need help from epg ??? |
---|
791 | //T_Whole[ii]=getSampleTransWholeDetector(t_fname) |
---|
792 | |
---|
793 | //SDD - OK |
---|
794 | T_SDD[ii]=getSDD(t_fname) |
---|
795 | |
---|
796 | //wavelength - OK |
---|
797 | T_Lambda[ii]=getWavelength(t_fname) |
---|
798 | endif |
---|
799 | else |
---|
800 | T_Filenames[ii] = "? " + T_Filenames[ii] |
---|
801 | FilesAreMissing = 1 |
---|
802 | endif |
---|
803 | |
---|
804 | if (CheckIfFileExists(emp_fname)) |
---|
805 | if (CheckIfRawData(emp_fname)) |
---|
806 | getXYBoxFromFile(emp_fname,x1,x2,y1,y2) |
---|
807 | EMP_x1[ii] = x1 |
---|
808 | EMP_x2[ii] = x2 |
---|
809 | EMP_y1[ii] = y1 |
---|
810 | EMP_y2[ii] = y2 |
---|
811 | endif |
---|
812 | else |
---|
813 | EMP_Filenames[ii] = "? " + EMP_Filenames[ii] |
---|
814 | FilesAreMissing = 1 |
---|
815 | endif |
---|
816 | |
---|
817 | ii+=1 |
---|
818 | // Execute "ProgressWindow percent=" + Num2Str(100*ii/lastPoint) |
---|
819 | |
---|
820 | while(ii<lastPoint) |
---|
821 | |
---|
822 | // Execute "ProgressWindow close" |
---|
823 | |
---|
824 | if (FilesAreMissing) |
---|
825 | DoAlert /T="Warning" 0, "The files marked with \"?\" in the table could not be found.\r\n\r\nSome files listed in the XML-Catalog may be missing." |
---|
826 | endif |
---|
827 | |
---|
828 | return(0) |
---|
829 | End |
---|
830 | |
---|
831 | //initialize data folder and globals for the Trans panel as needed |
---|
832 | //since this operation is somewhat tangled with the Patch Panel, keep all of the |
---|
833 | //globals in the Patch subfolder (make sure both panels are simultaneously initialized) |
---|
834 | //do not create a separate Trans folder |
---|
835 | // |
---|
836 | Proc InitializeTransPanel() |
---|
837 | //create the global variables needed to run the Trans Panel |
---|
838 | //all are kept in root:myGlobals:TransHeaderInfo |
---|
839 | If( ! (DataFolderExists("root:myGlobals:TransHeaderInfo")) ) |
---|
840 | //create the data folder and the clobals for BOTH the Patch and Trans Panels |
---|
841 | NewDataFolder/O root:myGlobals:TransHeaderInfo |
---|
842 | CreateTransGlobals() |
---|
843 | Endif |
---|
844 | End |
---|
845 | |
---|
846 | |
---|
847 | // |
---|
848 | Proc CreateTransGlobals() |
---|
849 | |
---|
850 | PathInfo catPathName |
---|
851 | If(V_flag==1) |
---|
852 | String dum = S_path |
---|
853 | String/G root:myGlobals:TransHeaderInfo:gCatPathStr = dum |
---|
854 | else |
---|
855 | String/G root:myGlobals:TransHeaderInfo:gCatPathStr = "no path selected" |
---|
856 | endif |
---|
857 | |
---|
858 | String/G root:myGlobals:TransHeaderInfo:gEMP = "no file selected" |
---|
859 | String/G root:myGlobals:TransHeaderInfo:gBox = "" |
---|
860 | Make/O/T/N=0 $"root:myGlobals:TransHeaderInfo:EMP_Filenames" |
---|
861 | Make/O/T/N=0 $"root:myGlobals:TransHeaderInfo:T_Filenames" |
---|
862 | Make/O/T/N=0 $"root:myGlobals:TransHeaderInfo:T_Labels" |
---|
863 | Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:T_SDD" |
---|
864 | Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:T_Lambda" |
---|
865 | // Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:T_Transmission" |
---|
866 | // Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:T_Whole" |
---|
867 | |
---|
868 | Make/O/T/N=0 $"root:myGlobals:TransHeaderInfo:S_Filenames" |
---|
869 | Make/O/T/N=0 $"root:myGlobals:TransHeaderInfo:S_Labels" |
---|
870 | Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:S_SDD" |
---|
871 | Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:S_Lambda" |
---|
872 | Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:S_Transmission" |
---|
873 | Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:S_Whole" |
---|
874 | |
---|
875 | Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:EMP_x1" |
---|
876 | Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:EMP_x2" |
---|
877 | Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:EMP_y1" |
---|
878 | Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:EMP_y2" |
---|
879 | End |
---|
880 | |
---|
881 | //given a selection of scattering files, calculates the transmission |
---|
882 | //and writes the new transmission to the file header |
---|
883 | // |
---|
884 | //given the full path;name;vers (= filenmame), of a raw binary SANS file, |
---|
885 | //the transmission of the sample is calculated (if possible) from information |
---|
886 | //in the file header. empty beam and sample transmision run numbers are extracted |
---|
887 | //and the files are located from the run number (if possible) |
---|
888 | //from the header of the empty beam file, the XY box coordinates and "empty" |
---|
889 | //counts are determined |
---|
890 | //once all information is located, the transmission is calculated and the |
---|
891 | //transmission field of the sample file is automatically "Patched" |
---|
892 | // - updates the global variable that is displayed in the panel |
---|
893 | //can be run in batch mode, sequentially passing each item from a list of filenames |
---|
894 | //this is the single step of the batch mode |
---|
895 | // |
---|
896 | //in batch mode: execution will proceed through all of the files, reporting |
---|
897 | //results to the history window. If no trans could be successfully calculated |
---|
898 | //(for a blocked beam, for example), then that is displayed as well, and the |
---|
899 | //raw data is not modified |
---|
900 | // |
---|
901 | // now takes the attenuation of the sample trans and empty beam trans into account, (normally this == 1) |
---|
902 | // and rescales the transmission as appropriate |
---|
903 | // 3/31/04 SRK |
---|
904 | // |
---|
905 | Function CalcSelTransFromHeader(startRow,endRow) |
---|
906 | Variable startRow,endRow |
---|
907 | // GetSelection table,ScatterFileTable,1 |
---|
908 | |
---|
909 | String S_Filename, T_Filename, EMP_Filename |
---|
910 | |
---|
911 | Wave/T EMP_Filenames = $"root:myGlobals:TransHeaderInfo:EMP_Filenames" |
---|
912 | Wave/T T_Filenames = $"root:myGlobals:TransHeaderInfo:T_Filenames" |
---|
913 | Wave/T S_Filenames = $"root:myGlobals:TransHeaderInfo:S_Filenames" |
---|
914 | |
---|
915 | Wave S_Transmission = $"root:myGlobals:TransHeaderInfo:S_Transmission" |
---|
916 | |
---|
917 | Variable/G $"root:Packages:quokka:IgnoreTrans" |
---|
918 | NVAR IgnoreTrans = $"root:Packages:quokka:IgnoreTrans" |
---|
919 | |
---|
920 | Variable num_s_files, num_t_files, ii, jj |
---|
921 | Variable refnum, transCts, emptyCts,attenRatio,lambda,trans |
---|
922 | Variable x1,x2,y1,y2,err,attenEmp,attenSam |
---|
923 | String suffix = "",pathName,textStr,abortStr,samFileStr |
---|
924 | String GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=2/W=1/Q" |
---|
925 | |
---|
926 | num_t_files = numpnts(T_Filenames) |
---|
927 | |
---|
928 | PathInfo catPathName |
---|
929 | pathname = S_path |
---|
930 | |
---|
931 | // [davidm] restructured the following code |
---|
932 | for (ii = startRow; ii<=endRow; ii += 1) |
---|
933 | |
---|
934 | S_Filename = pathname + S_Filenames[ii] |
---|
935 | T_Filename = pathname + T_Filenames[ii] |
---|
936 | EMP_Filename = pathname + EMP_Filenames[ii] |
---|
937 | |
---|
938 | // check S-file |
---|
939 | if ((cmpstr(S_Filenames[ii],"") == 0) || !CheckIfFileExists(S_Filename)) |
---|
940 | Print "Scattering beam file not assigned properly in line", ii+1 |
---|
941 | |
---|
942 | // check T-file |
---|
943 | elseif ((cmpstr(T_Filenames[ii],"") == 0) || !CheckIfFileExists(T_Filename)) |
---|
944 | Print "Transmission beam file not assigned properly for", S_Filenames[ii] |
---|
945 | |
---|
946 | // check EMP-file |
---|
947 | elseif ((cmpstr(EMP_Filenames[ii],"") == 0) || !CheckIfFileExists(EMP_Filename)) |
---|
948 | Print "Empty beam file not assigned properly for", S_Filenames[ii] |
---|
949 | |
---|
950 | // proceed |
---|
951 | else |
---|
952 | // check the empty beam file for previously selected coordinates |
---|
953 | //if they exist, set the xy string , save the normalized counts somewhere |
---|
954 | GetXYBoxFromFile(EMP_Filename,x1,x2,y1,y2) |
---|
955 | |
---|
956 | //read the real count value |
---|
957 | //emptyCts = getBoxCounts(emptyFile) |
---|
958 | //if(emptyCts < 1) //box counts hasn't been patched to file |
---|
959 | ReadHeaderAndData(EMP_Filename) |
---|
960 | IgnoreTrans = 1 // to prevent the warning message: ***transmission is ZERO*** |
---|
961 | err = Raw_to_work("SAM") |
---|
962 | IgnoreTrans = 0 |
---|
963 | emptyCts = SumCountsInBox(x1,x2,y1,y2,"SAM") |
---|
964 | //nha debug |
---|
965 | //textStr = "Box counts for " + emptyFile + " " + num2str(emptyCts) |
---|
966 | //print textStr |
---|
967 | //endif |
---|
968 | |
---|
969 | // read the attenuator number of the empty beam file |
---|
970 | attenEmp = getAttenNumber(EMP_Filename) |
---|
971 | // |
---|
972 | if( ((x1-x2)==0) || ((y1-y2)==0) ) //zero width marquee in either direction |
---|
973 | //no region selected -- prompt user to select box w/marquee |
---|
974 | DoWindow/F ScatterFileTable |
---|
975 | Abort "Use \"Set EMP File\", then \"SetXYBox\" to select XY range in empty beam file "+EMP_Filenames[ii] |
---|
976 | //from here the Marquee menu selection must handle the task of setting the box and updating the information in the file header |
---|
977 | Endif |
---|
978 | |
---|
979 | //read in trans file |
---|
980 | ReadHeaderAndData(T_Filename) |
---|
981 | //adds to SAM |
---|
982 | IgnoreTrans = 1 // to prevent the warning message: ***transmission is ZERO*** |
---|
983 | err = Raw_to_work("SAM") |
---|
984 | IgnoreTrans = 0 |
---|
985 | //sum region in SAM |
---|
986 | transCts = SumCountsInBox(x1,x2,y1,y2,"SAM") |
---|
987 | // get the attenuator, lambda, and sample string (to get the instrument) |
---|
988 | // WAVE/T samText = $"root:Packages:NIST:SAM:textRead" |
---|
989 | WAVE samReals = $"root:Packages:NIST:SAM:realsRead" |
---|
990 | // samfileStr = samText[3] |
---|
991 | lambda = samReals[26] |
---|
992 | attenSam = samReals[3] |
---|
993 | //nha debug |
---|
994 | //variable attenSamFromFile |
---|
995 | //attenSamFromFile = getAttenNumber(transFile) |
---|
996 | //textStr = num2str(attenSam) + " "+ num2str(attenSamFromFile) |
---|
997 | //print textStr |
---|
998 | //calculate the ratio of attenuation factors - assumes that same instrument used for each, AND same lambda |
---|
999 | AttenRatio = AttenuationFactor("",lambda,attenEmp)/AttenuationFactor("",lambda,attenSam) |
---|
1000 | //calculate trans based on empty beam value and rescale by attenuation ratio |
---|
1001 | trans= transCts/emptyCts * AttenRatio |
---|
1002 | |
---|
1003 | //write out counts and transmission to history window, showing the attenuator ratio, if it is not unity |
---|
1004 | If(attenRatio==1) |
---|
1005 | Printf "%s\t\tTrans Counts = %g\tTrans = %g\r",S_Filenames[ii], transCts,trans |
---|
1006 | else |
---|
1007 | Printf "%s\t\tTrans Counts = %g\tTrans = %g\tAttenuatorRatio = %g\r",S_Filenames[ii], transCts,trans,attenRatio |
---|
1008 | endif |
---|
1009 | //write the trans to the file header of the raw data (open/close done in function) |
---|
1010 | WriteTransmissionToHeader(S_Filename,trans) |
---|
1011 | |
---|
1012 | // after patching, the file needs to be removed from the DataFolder |
---|
1013 | // so that it will be reloaded if it is needed again [davidm] |
---|
1014 | string partialName = S_Filenames[ii] |
---|
1015 | variable index = strsearch(partialName, ".", 0) |
---|
1016 | if (index != -1) |
---|
1017 | partialName = partialName[0,index-1] |
---|
1018 | endif |
---|
1019 | KillDataFolder/Z $"root:Packages:quokka:"+partialName |
---|
1020 | |
---|
1021 | //then update the global that is displayed |
---|
1022 | S_Transmission[ii] = trans |
---|
1023 | endif |
---|
1024 | endfor |
---|
1025 | |
---|
1026 | print "done" |
---|
1027 | return 0 |
---|
1028 | End |
---|
1029 | |
---|
1030 | // |
---|
1031 | // For the calculation of the Transmission using only the Trans Files screen |
---|
1032 | // Uses only the information on the transmissionFiles screen to calculate |
---|
1033 | // a "box" Transmission for comparison with the Whole Transmission |
---|
1034 | // updated 5/11/2006 by Bryan Greenwald |
---|
1035 | Function CalcTotalTrans(startRow,endRow) |
---|
1036 | Variable startRow,endRow |
---|
1037 | // GetSelection table,ScatterFileTable,1 |
---|
1038 | |
---|
1039 | String filename |
---|
1040 | Wave/T EMP_Filenames = $"root:myGlobals:TransHeaderInfo:EMP_Filenames" |
---|
1041 | Wave/T T_Filenames = $"root:myGlobals:TransHeaderInfo:T_Filenames" |
---|
1042 | // Wave T_GTransmission = $"root:myGlobals:TransHeaderInfo:T_Transmission" |
---|
1043 | |
---|
1044 | Wave/T S_Filenames = $"root:myGlobals:TransHeaderInfo:S_Filenames" |
---|
1045 | // Wave/T S_GFilenames = $"root:myGlobals:TransHeaderInfo:S_Filenames" |
---|
1046 | // Wave S_GTransmission = $"root:myGlobals:TransHeaderInfo:S_Transmission" |
---|
1047 | // Wave GWhole= $"root:myGlobals:TransHeaderInfo:T_Whole" |
---|
1048 | |
---|
1049 | Variable num_t_files, ii, jj |
---|
1050 | Variable refnum, transCts, emptyCts,attenRatio,lambda,trans |
---|
1051 | Variable x1,x2,y1,y2,err,attenEmp,attenSam |
---|
1052 | String suffix = "",pathName,textStr,abortStr,emptyFile,transFile,samFileStr |
---|
1053 | String GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=2/W=1/Q" |
---|
1054 | String strToExecute |
---|
1055 | |
---|
1056 | // num_t_files = numpnts(T_Filenames) |
---|
1057 | |
---|
1058 | PathInfo catPathName |
---|
1059 | pathname = S_path |
---|
1060 | |
---|
1061 | ii= startRow |
---|
1062 | do |
---|
1063 | if (cmpstr(T_Filenames[ii],"")!=0) //if there is a sample trans file assigned |
---|
1064 | if (cmpstr(EMP_Filenames[ii],"")!=0) //if empty beam file assigned, proceed with the calculation |
---|
1065 | |
---|
1066 | //full path+name to access all 3 files |
---|
1067 | filename=pathname+S_Filenames[ii] |
---|
1068 | emptyFile = pathname+ EMP_Filenames[ii] |
---|
1069 | transFile = pathname+T_Filenames[ii] |
---|
1070 | ////////// |
---|
1071 | // check the empty beam file for previously selected coordinates |
---|
1072 | //if they exist, set the xy string , save the normalized counts somewhere |
---|
1073 | //the value was written to an unused r*4 header analysis.factor (@b494) |
---|
1074 | getXYBoxFromFile(emptyFile,x1,x2,y1,y2) |
---|
1075 | |
---|
1076 | //read the real count value |
---|
1077 | emptyCts = getBoxCounts(emptyFile) |
---|
1078 | // read the attenuator number of the empty beam file |
---|
1079 | attenEmp = getAttenNumber(emptyFile) |
---|
1080 | // |
---|
1081 | if( ((x1-x2)==0) || ((y1-y2)==0) ) //zero width marquee in either direction |
---|
1082 | //no region selected -- prompt user to select box w/marquee |
---|
1083 | DoWindow/F TransFileTable |
---|
1084 | Abort "Use \"Set EMP File\", then \"SetXYBox\" to select XY range in empty beam file "+EMP_Filenames[ii] |
---|
1085 | //from here the Marquee menu selection must handle the task of setting the box and updating the information in the file header |
---|
1086 | Endif |
---|
1087 | |
---|
1088 | //read in trans file then add to SAM |
---|
1089 | ReadHeaderAndData(transFile) |
---|
1090 | //adds to SAM |
---|
1091 | err = Raw_to_work("SAM") |
---|
1092 | //sum region in SAM |
---|
1093 | transCts = SumCountsInBox(x1,x2,y1,y2,"SAM") |
---|
1094 | // get the attenuator, lambda, and sample string (to get the instrument) |
---|
1095 | WAVE/T samText = $"root:Packages:NIST:SAM:textRead" |
---|
1096 | WAVE samReals = $"root:Packages:NIST:SAM:realsRead" |
---|
1097 | samfileStr = samText[3] |
---|
1098 | lambda = samReals[26] |
---|
1099 | attenSam = samReals[3] |
---|
1100 | //calculate the ratio of attenuation factors - assumes that same instrument used for each, AND same lambda |
---|
1101 | AttenRatio = AttenuationFactor("",lambda,attenEmp)/AttenuationFactor("",lambda,attenSam) |
---|
1102 | //calculate trans based on empty beam value and rescale by attenuation ratio |
---|
1103 | trans= transCts/emptyCts * AttenRatio |
---|
1104 | |
---|
1105 | //write out counts and transmission to history window, showing the attenuator ratio, if it is not unity |
---|
1106 | If(attenRatio==1) |
---|
1107 | //Printf "%s\t\tTrans Counts = %g\t Actual Trans = %g\r",T_GFilenames[ii], transCts,trans |
---|
1108 | Printf "%s\t\tBox Counts = %g\t Trans = %g\r",T_Filenames[ii], transCts,trans |
---|
1109 | else |
---|
1110 | //Printf "%s\t\tTrans Counts = %g\t Trans = %g\tAttenuatorRatio = %g\r",T_GFilenames[ii], transCts,trans,attenRatio |
---|
1111 | Printf "%s\t\tBox Counts = %g\t Trans = %g\t AttenuatorRatio = %g\r",T_Filenames[ii], transCts,trans,attenRatio |
---|
1112 | endif |
---|
1113 | //write the trans to the file header of the raw data (open/close done in function) |
---|
1114 | WriteTransmissionToHeader(filename,trans) //transmission start byte is 158 |
---|
1115 | |
---|
1116 | // after patching, the file needs to be removed from the DataFolder |
---|
1117 | // so that it will be reloaded if it is needed again [davidm] |
---|
1118 | string partialName = S_Filenames[ii] |
---|
1119 | variable index = strsearch(partialName, ".", 0) |
---|
1120 | if (index != -1) |
---|
1121 | partialName = partialName[0,index-1] |
---|
1122 | endif |
---|
1123 | KillDataFolder/Z $"root:Packages:quokka:"+partialName |
---|
1124 | |
---|
1125 | //then update the global that is displayed |
---|
1126 | // T_GTransmission[ii] = trans |
---|
1127 | |
---|
1128 | else // There is no empty assigned |
---|
1129 | abortStr = "Empty beam file not assigned properly for " + S_Filenames[jj] |
---|
1130 | Print abortStr |
---|
1131 | //Abort abortStr |
---|
1132 | return(1) |
---|
1133 | endif |
---|
1134 | else //no transmission file |
---|
1135 | abortStr = "Transmission beam file not assigned properly for " + S_Filenames[ii] |
---|
1136 | Print abortStr |
---|
1137 | endif |
---|
1138 | ii+=1 |
---|
1139 | while(ii<=endRow) |
---|
1140 | //print "done" |
---|
1141 | return(0) |
---|
1142 | End |
---|
1143 | |
---|
1144 | // |
---|
1145 | // For the calculation of the Transmission using only the whole detector |
---|
1146 | // Used to compute the transmission for the TransmissionFiles table using |
---|
1147 | // the entire detector. For comparison with the "box" trans |
---|
1148 | // updated: 5/11/2006 by Bryan Greenwald |
---|
1149 | Function CalcWholeTrans(startRow,endRow) |
---|
1150 | Variable startRow,endRow |
---|
1151 | // GetSelection table,ScatterFileTable,1 |
---|
1152 | |
---|
1153 | NVAR pixelsX = root:myGlobals:gNPixelsX |
---|
1154 | NVAR pixelsY = root:myGlobals:gNPixelsY |
---|
1155 | |
---|
1156 | String filename |
---|
1157 | Wave/T EMP_Filenames = $"root:myGlobals:TransHeaderInfo:EMP_Filenames" |
---|
1158 | |
---|
1159 | Wave/T T_Filenames = $"root:myGlobals:TransHeaderInfo:T_Filenames" |
---|
1160 | // Wave T_GTransmission = $"root:myGlobals:TransHeaderInfo:T_Transmission" |
---|
1161 | |
---|
1162 | Wave/T S_Filenames = $"root:myGlobals:TransHeaderInfo:S_Filenames" |
---|
1163 | // Wave/T S_GFilenames = $"root:myGlobals:TransHeaderInfo:S_Filenames" |
---|
1164 | Wave S_Transmission = $"root:myGlobals:TransHeaderInfo:S_Transmission" |
---|
1165 | Wave S_Whole= $"root:myGlobals:TransHeaderInfo:S_Whole" |
---|
1166 | |
---|
1167 | Variable num_t_files, ii, jj |
---|
1168 | Variable refnum, transCts, emptyCts,attenRatio,lambda,trans |
---|
1169 | Variable x1,x2,y1,y2,err,attenEmp,attenSam |
---|
1170 | String suffix = "",pathName,textStr,abortStr,emptyFile,transFile,samFileStr |
---|
1171 | String GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=2/W=1/Q" |
---|
1172 | String strToExecute |
---|
1173 | |
---|
1174 | // num_t_files = numpnts(T_GFilenames) |
---|
1175 | |
---|
1176 | PathInfo catPathName |
---|
1177 | pathname = S_path |
---|
1178 | |
---|
1179 | ii= startRow |
---|
1180 | do |
---|
1181 | if (cmpstr(T_Filenames[ii],"")!=0) //if there is a sample trans file assigned |
---|
1182 | if (cmpstr(EMP_Filenames[ii],"")!=0) //if empty beam file assigned, proceed with the calculation |
---|
1183 | //full path+name to access all 3 files |
---|
1184 | filename=pathname+ S_Filenames[ii] |
---|
1185 | emptyFile = pathname+EMP_Filenames[ii] |
---|
1186 | transFile = pathname+T_Filenames[ii] |
---|
1187 | ////////// |
---|
1188 | // check the empty beam file for previously selected coordinates |
---|
1189 | //if they exist, set the xy string , save the normalized counts somewhere |
---|
1190 | //the value was written to an unused r*4 header analysis.factor (@b494) |
---|
1191 | |
---|
1192 | getXYBoxFromFile(emptyFile,x1,x2,y1,y2) |
---|
1193 | //read the real count value |
---|
1194 | emptyCts = getBoxCounts(emptyFile) |
---|
1195 | // read the attenuator number of the empty beam file |
---|
1196 | attenEmp = getAttenNumber(emptyFile) |
---|
1197 | // |
---|
1198 | if( ((x1-x2)==0) || ((y1-y2)==0) ) //zero width marquee in either direction |
---|
1199 | //no region selected -- prompt user to select box w/marquee |
---|
1200 | DoWindow/F TransFileTable |
---|
1201 | Abort "Use \"Set EMP File\", then \"SetXYBox\" to select XY range in empty beam file "+EMP_Filenames[ii] |
---|
1202 | //from here the Marquee menu selection must handle the task of setting the box and updating the information in the file header |
---|
1203 | Endif |
---|
1204 | |
---|
1205 | //read in trans file then add to SAM |
---|
1206 | ReadHeaderAndData(transFile) |
---|
1207 | //adds to SAM |
---|
1208 | err = Raw_to_work("SAM") |
---|
1209 | //sum region in SAM |
---|
1210 | transCts = SumCountsInBox(0,pixelsX-1,0,pixelsY-1,"SAM") |
---|
1211 | // get the attenuator, lambda, and sample string (to get the instrument) |
---|
1212 | WAVE/T samText = $"root:Packages:NIST:SAM:textRead" |
---|
1213 | WAVE samReals = $"root:Packages:NIST:SAM:realsRead" |
---|
1214 | samfileStr = samText[3] |
---|
1215 | lambda = samReals[26] |
---|
1216 | attenSam = samReals[3] |
---|
1217 | //calculate the ratio of attenuation factors - assumes that same instrument used for each, AND same lambda |
---|
1218 | AttenRatio = AttenuationFactor("",lambda,attenEmp)/AttenuationFactor("",lambda,attenSam) |
---|
1219 | //calculate trans based on empty beam value and rescale by attenuation ratio |
---|
1220 | trans= transCts/emptyCts * AttenRatio |
---|
1221 | |
---|
1222 | //write out counts and transmission to history window, showing the attenuator ratio, if it is not unity |
---|
1223 | If(attenRatio==1) |
---|
1224 | //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 |
---|
1225 | Printf "%s\t\tTotal Counts = %g\t Trans using whole detector = %g\t",T_Filenames[ii], transCts,trans |
---|
1226 | else |
---|
1227 | //Printf "%s\t\tTrans Counts = %g\tTrans = %g\tAttenuatorRatio = %g, Tbox/Twhole = %g\r",T_GFilenames[ii], transCts,trans,attenRatio, T_GTransmission[ii]/trans |
---|
1228 | Printf "%s\t\tTotal Counts = %g\t Trans using whole detector = %g\t AttenuatorRatio = %g",T_Filenames[ii], transCts,trans,attenRatio |
---|
1229 | endif |
---|
1230 | If(S_Transmission[ii]/trans > 0.97) |
---|
1231 | printf " Tbox/Twhole = %g\r",S_Transmission[ii]/trans |
---|
1232 | else |
---|
1233 | printf " !!! Tbox/Twhole is low !!! = %g\r",S_Transmission[ii]/trans |
---|
1234 | endif |
---|
1235 | //write the trans to the file header of the raw data (open/close done in function) |
---|
1236 | WriteWholeTransToHeader(filename,trans) |
---|
1237 | |
---|
1238 | //then update the global that is displayed |
---|
1239 | S_Whole[ii] = trans |
---|
1240 | |
---|
1241 | else // There is no empty assigned |
---|
1242 | abortStr = "Empty beam file not assigned properly for " + S_Filenames[ii] |
---|
1243 | Print abortStr |
---|
1244 | //Abort abortStr |
---|
1245 | return(1) |
---|
1246 | endif |
---|
1247 | |
---|
1248 | else //no transmission file |
---|
1249 | abortStr = "Transmission beam file not assigned properly for " + S_Filenames[ii] |
---|
1250 | Print abortStr |
---|
1251 | endif |
---|
1252 | ii+=1 |
---|
1253 | while(ii<=endRow) |
---|
1254 | print "done" |
---|
1255 | return(0) |
---|
1256 | End |
---|
1257 | |
---|
1258 | Function PickEMPTransButton(ctrlName) : ButtonControl |
---|
1259 | String ctrlName |
---|
1260 | |
---|
1261 | Variable ScatFileTableExists |
---|
1262 | ScatFileTableExists = WinType("ScatterFileTable") |
---|
1263 | //??BUG?? V_flag returns 1 even if no selection? |
---|
1264 | //check manually for null selection |
---|
1265 | //Print "local v_flag = ",num2str(V_flag) |
---|
1266 | Wave/T LocFilenames = $"root:myGlobals:TransHeaderInfo:EMP_Filenames" |
---|
1267 | if (ScatFileTableExists != 0) |
---|
1268 | String/G root:myGlobals:TransHeaderInfo:gEMP = "" |
---|
1269 | GetSelection table,ScatterFileTable,7 |
---|
1270 | //Print S_Selection |
---|
1271 | if(strsearch(S_selection,"EMP_Filenames",0) == 0) |
---|
1272 | //selection OK, add to list |
---|
1273 | Duplicate/O/R=[V_startRow,V_endRow] LocFilenames, filenames |
---|
1274 | Wave/T selectedFiles = $"filenames" |
---|
1275 | |
---|
1276 | SVAR temp = root:myGlobals:TransHeaderInfo:gEMP |
---|
1277 | // |
---|
1278 | temp = temp+selectedFiles[0] //take just the first file |
---|
1279 | UpdateBoxCoordinates() |
---|
1280 | Else |
---|
1281 | DoWindow/F ScatterFileTable |
---|
1282 | DoAlert 0,"Invalid selection from the Scattering file table. You must select a file from the EMP_Filenames column" |
---|
1283 | Endif |
---|
1284 | else |
---|
1285 | //no selection |
---|
1286 | DoAlert 0,"No file selected from Scattering file table or no Scattering file table available" |
---|
1287 | Endif |
---|
1288 | End |
---|
1289 | |
---|
1290 | |
---|
1291 | //window recreation macro for the Trans Panel |
---|
1292 | // |
---|
1293 | Proc Trans_Panel() |
---|
1294 | PauseUpdate; Silent 1 // building window... |
---|
1295 | NewPanel /W=(173,197,540,424)/K=1 as "Calculate Transmissions" |
---|
1296 | DoWindow/C Trans_Panel |
---|
1297 | ModifyPanel cbRGB=(49807,47186,38011) |
---|
1298 | ModifyPanel fixedSize=1 |
---|
1299 | SetDrawLayer UserBack |
---|
1300 | DrawLine 0,56,368,56 |
---|
1301 | DrawLine 0,125,368,125 |
---|
1302 | Button pick_emp,pos={4,65},size={105,20},proc=PickEMPTransButton,title="set EMP file" |
---|
1303 | Button pick_emp,help={"This button will set the file selected in the Transmission file table to be the empty beam file."} |
---|
1304 | SetVariable empStr,pos={114,67},size={250,17},title="file:" |
---|
1305 | SetVariable empStr,help={"Filename of the empty beam file(s) to be used in the transmission calculation"} |
---|
1306 | SetVariable empStr,fSize=10 |
---|
1307 | SetVariable empStr,limits={-Inf,Inf,0},value= root:myGlobals:TransHeaderInfo:gEMP |
---|
1308 | Button Trn_button_1,pos={5,101},size={90,20},proc=Trn_SetXYBoxButton,title="Set XY Box" |
---|
1309 | Button Trn_button_1,help={"Sets the XY box to sum over"} |
---|
1310 | Button Trn_button_2,pos={174,139},size={110,20},proc=Trn_SortFilesByDate,title="Sort by Date" |
---|
1311 | Button Trn_button_2,help={"Sort the scattering and transmission files by creation date."} |
---|
1312 | Button Trn_button_3,pos={174,169},size={110,20},proc=Trn_SortFilesByLabel,title="Sort by Label" |
---|
1313 | Button Trn_button_3,help={"Sort the scattering and transmission files by label."} |
---|
1314 | Button Trn_button_4,pos={295,139},size={67,20},proc=Trn_ShowHelpProc,title="Help" |
---|
1315 | Button Trn_button_4,help={"Show a help notebook for calculating transmissions."} |
---|
1316 | SetVariable Trn_setvar_1,pos={135,100},size={227,17},title="Box is " |
---|
1317 | SetVariable Trn_setvar_1,help={"Box coordinates to sum over"},fSize=10 |
---|
1318 | SetVariable Trn_setvar_1,limits={-Inf,Inf,0},value= root:myGlobals:TransHeaderInfo:gBox |
---|
1319 | Button Trn_button_0,pos={1,1},size={70,20},proc=Trn_PickPathButton,title="Pick Path" |
---|
1320 | Button Trn_button_0,help={"Select the folder containing the SANS data files"} |
---|
1321 | Button Trn_button_9,pos={335,1},size={25,20},proc=ShowTransHelp,title="?" |
---|
1322 | Button Trn_button_9,help={"Show the help file for calculating sample transmissions"} |
---|
1323 | SetVariable Trn_setvar_0,pos={80,4},size={250,17},title="Path" |
---|
1324 | SetVariable Trn_setvar_0,help={"Currently selected data path"},fSize=10 |
---|
1325 | SetVariable Trn_setvar_0,limits={-Inf,Inf,0},value= root:myGlobals:TransHeaderInfo:gCatPathStr |
---|
1326 | Button Trn_button_5,pos={5,169},size={161,20},proc=Trn_CalcAllFilesButton,title="Calculate All Files" |
---|
1327 | Button Trn_button_5,help={"Calculate transmission and patch headers of ALL files in the Scattering File Table."} |
---|
1328 | Button Trn_button_6,pos={295,198},size={67,20},proc=Trn_PanelDoneButtonProc,title="Done" |
---|
1329 | Button Trn_button_6,help={"Close the panel when done calculating transmissions"} |
---|
1330 | |
---|
1331 | Button Trn_button_7,pos={67,32},size={114,20},proc=Trn_RefreshProc,title="List Files" |
---|
1332 | Button Trn_button_7,help={"Generate or refresh the tables of files."} |
---|
1333 | |
---|
1334 | Button Trn_button_7b, pos={67+114+5,32},size={114,20},proc=Trn_AutoCompleteProc,title="Auto Complete" |
---|
1335 | Button Trn_button_7b, help={"???"} |
---|
1336 | |
---|
1337 | Button Trn_button_8,pos={5,139},size={161,20},proc=Trn_CalcSelectedFilesButton,title="Calculate Selected Files" |
---|
1338 | Button Trn_button_8,help={"Calculate transmission and patch headers of selected files in the Scattering File Table."} |
---|
1339 | Button Trn_button_10,pos={5,198}, size={161,20},proc=TotalTransButtonProc |
---|
1340 | Button Trn_button_10 title="Calculate Total Trans" |
---|
1341 | Button Trn_button_10 help={"Calculate transmission over the whole detector and patch headers of ALL files in the data folder."} |
---|
1342 | EndMacro |
---|
1343 | |
---|
1344 | |
---|
1345 | Function TotalTransButtonProc(ctrlName) : ButtonControl |
---|
1346 | String ctrlName |
---|
1347 | TotalTrans(ctrlName) |
---|
1348 | End |
---|
1349 | |
---|
1350 | |
---|
1351 | Proc ShowTransHelp(ctrlName) : ButtonControl |
---|
1352 | String ctrlName |
---|
1353 | DisplayHelpTopic/K=1 "SANS Data Reduction Tutorial[Calculate Transmissions]" |
---|
1354 | if(V_flag !=0) |
---|
1355 | DoAlert 0,"The SANS Data Reduction Tutorial Help file could not be found" |
---|
1356 | endif |
---|
1357 | End |
---|
1358 | |
---|
1359 | |
---|
1360 | //generates the file tables of scattering files and transmission files |
---|
1361 | // |
---|
1362 | // if the tables already exist, they will be updated |
---|
1363 | // |
---|
1364 | Proc Trn_RefreshProc(ctrlName) : ButtonControl |
---|
1365 | String ctrlName |
---|
1366 | BuildFileTables() |
---|
1367 | End |
---|
1368 | |
---|
1369 | Function Example2() |
---|
1370 | String browserCmd,cmd1,cmd2,promptStr |
---|
1371 | |
---|
1372 | cmd1="Display %s" |
---|
1373 | cmd2="AppendToGraph %s" |
---|
1374 | promptStr="Select Waves for Graph" |
---|
1375 | sprintf browserCmd, "CreateBrowser prompt=\"%s\", executeMode=2, command1=\"%s\", command2=\"%s\"",promptStr,cmd1,cmd2 |
---|
1376 | Execute browserCmd |
---|
1377 | End |
---|
1378 | |
---|
1379 | //improves the file tables of scattering files and transmission files |
---|
1380 | Function Trn_AutoCompleteProc(ctrlName) : ButtonControl |
---|
1381 | String ctrlName |
---|
1382 | |
---|
1383 | Variable i, in |
---|
1384 | Variable j, jn |
---|
1385 | Variable row |
---|
1386 | |
---|
1387 | Wave/T S_Filenames = $"root:myGlobals:TransHeaderInfo:S_Filenames" |
---|
1388 | Wave/T T_Filenames = $"root:myGlobals:TransHeaderInfo:T_Filenames" |
---|
1389 | Wave/T EMP_Filenames = $"root:myGlobals:TransHeaderInfo:EMP_Filenames" |
---|
1390 | Wave/T S_Labels = $"root:myGlobals:TransHeaderInfo:S_Labels" |
---|
1391 | |
---|
1392 | String Pathname, S_Filename, T_Filename, EMP_Filename, S_Label |
---|
1393 | String safeLabel |
---|
1394 | |
---|
1395 | String dicValidRows = "" // [safeLabel] -> [[row1],[row2],...] |
---|
1396 | String dicCandidates = "" // [safeLabel] -> [[row1],[row2],...] // candidates to be auto completed |
---|
1397 | |
---|
1398 | String validRows // [[row1],[row2],...] |
---|
1399 | String candidateRows // [[row1],[row2],...] |
---|
1400 | |
---|
1401 | String title, message, selection |
---|
1402 | |
---|
1403 | // String selection |
---|
1404 | // Prompt selection, "titleStr", popup, "hallo\tTest;nein\tJa;danke" |
---|
1405 | // DoPrompt "hello", selection |
---|
1406 | |
---|
1407 | PathInfo catPathName |
---|
1408 | Pathname = S_path |
---|
1409 | |
---|
1410 | // check if ScatterFileTable exists |
---|
1411 | if (WinType("ScatterFileTable") == 2) |
---|
1412 | |
---|
1413 | // |
---|
1414 | // first step: find valid rows and find rows which potentially could be auto fixed |
---|
1415 | // |
---|
1416 | |
---|
1417 | in = DimSize(S_Filenames, 0) |
---|
1418 | for (i = 0; i < in; i += 1) |
---|
1419 | S_Filename = Pathname + S_Filenames[i] |
---|
1420 | T_Filename = Pathname + T_Filenames[i] |
---|
1421 | EMP_Filename = Pathname + EMP_Filenames[i] |
---|
1422 | S_Label = S_Labels[i] |
---|
1423 | |
---|
1424 | // check S-file |
---|
1425 | if ((strlen(S_Filenames[i]) != 0) && CheckIfFileExists(S_Filename) && (strlen(S_Label) != 0)) |
---|
1426 | |
---|
1427 | // make sure that label doesn't interfere with list and dictionary symbols |
---|
1428 | safeLabel = S_Label |
---|
1429 | safeLabel = ReplaceString("\\", safeLabel, "\\1") // ReplaceString("\", safeLabel, "\1") |
---|
1430 | safeLabel = ReplaceString(":", safeLabel, "\\2") |
---|
1431 | safeLabel = ReplaceString(";", safeLabel, "\\3") |
---|
1432 | |
---|
1433 | // check T-file and EMP-file |
---|
1434 | if ((strlen(T_Filenames[i]) != 0) && CheckIfFileExists(T_Filename) && (strlen(EMP_Filenames[i]) != 0) && CheckIfFileExists(EMP_Filename)) |
---|
1435 | // check if sample is already marked as valid row |
---|
1436 | if (-1 != strsearch(dicValidRows, safeLabel, 0)) |
---|
1437 | // add row-index |
---|
1438 | validRows = StringByKey(safeLabel, dicValidRows) |
---|
1439 | sprintf validRows, "%s, %g", validRows, i |
---|
1440 | else |
---|
1441 | // set first row-index |
---|
1442 | sprintf validRows, "%g", i |
---|
1443 | endif |
---|
1444 | dicValidRows = ReplaceStringByKey(safeLabel, dicValidRows, validRows) |
---|
1445 | |
---|
1446 | // S-file seemed fine but problems occurred with T- and EMP-file |
---|
1447 | else |
---|
1448 | // check if sample is already marked as possible candidate |
---|
1449 | if (-1 != strsearch(dicCandidates, safeLabel, 0)) |
---|
1450 | // add row-index |
---|
1451 | candidateRows = StringByKey(safeLabel, dicCandidates) |
---|
1452 | sprintf candidateRows, "%s, %g", candidateRows, i |
---|
1453 | else |
---|
1454 | // set first row-index |
---|
1455 | sprintf candidateRows, "%g", i |
---|
1456 | endif |
---|
1457 | dicCandidates = ReplaceStringByKey(safeLabel, dicCandidates, candidateRows) |
---|
1458 | endif |
---|
1459 | endif |
---|
1460 | endfor |
---|
1461 | |
---|
1462 | // |
---|
1463 | // second step: fix invalid rows |
---|
1464 | // |
---|
1465 | |
---|
1466 | jn = ItemsInList(dicCandidates) |
---|
1467 | for (j = 0; j < jn; j += 1) |
---|
1468 | safeLabel = StringFromList(0, StringFromList(j, dicCandidates), ":") |
---|
1469 | |
---|
1470 | // check if invalid rows of current sample can be fixed |
---|
1471 | if (-1 != strsearch(dicValidRows, safeLabel, 0)) |
---|
1472 | validRows = StringByKey(safeLabel, dicValidRows) |
---|
1473 | candidateRows = StringByKey(safeLabel, dicCandidates) |
---|
1474 | |
---|
1475 | // check if more than one row can be used to fix current candidates |
---|
1476 | if (-1 != strsearch(validRows, ",", 0)) |
---|
1477 | |
---|
1478 | sprintf message, "Select row you want to use to update all incomplete rows with that sample." |
---|
1479 | |
---|
1480 | // check if more than one row is afftected |
---|
1481 | if (-1 != strsearch(candidateRows, ",", 0)) |
---|
1482 | sprintf title, "\"%s\" (Affected rows: %s)", S_Labels[str2num(StringFromList(0, validRows, ","))], candidateRows |
---|
1483 | else |
---|
1484 | sprintf title, " \"%s\" (Affected row: %s)", S_Labels[str2num(StringFromList(0, validRows, ","))], candidateRows |
---|
1485 | endif |
---|
1486 | |
---|
1487 | selection = StringFromList(0, validRows, ",") |
---|
1488 | Prompt selection, message, popup, ReplaceString(", ", validRows, ";") |
---|
1489 | DoPrompt /HELP="" title, selection |
---|
1490 | |
---|
1491 | // evaluate result |
---|
1492 | switch (V_flag) |
---|
1493 | case 0: // yes |
---|
1494 | row = str2num(selection) // use selected row value |
---|
1495 | break |
---|
1496 | |
---|
1497 | case 1: // cancel |
---|
1498 | row = -1 // skip |
---|
1499 | break |
---|
1500 | |
---|
1501 | default: |
---|
1502 | return 0 |
---|
1503 | endswitch |
---|
1504 | else |
---|
1505 | // only one row can be used to fix current candidates |
---|
1506 | row = str2num(validRows) |
---|
1507 | |
---|
1508 | // check if more than one row is afftected |
---|
1509 | if (-1 != strsearch(candidateRows, ",", 0)) |
---|
1510 | sprintf message, "The transmission value of \"%s\" can be determined with the information provided in row %g.\rWould you like to apply the information to all rows with that sample? (Affected rows: %s)", S_Labels[row], row, candidateRows |
---|
1511 | else |
---|
1512 | sprintf message, "The transmission value of \"%s\" can be determined with the information provided in row %g.\rWould you like to apply the information to all rows with that sample? (Affected row: %s)", S_Labels[row], row, candidateRows |
---|
1513 | endif |
---|
1514 | DoAlert 2, message |
---|
1515 | |
---|
1516 | // evaluate result |
---|
1517 | switch (V_flag) |
---|
1518 | case 1: // yes |
---|
1519 | break // use selected row value |
---|
1520 | |
---|
1521 | case 2: // no |
---|
1522 | row = -1 // skip |
---|
1523 | break |
---|
1524 | |
---|
1525 | default: // cancel |
---|
1526 | return 0 |
---|
1527 | endswitch |
---|
1528 | endif |
---|
1529 | |
---|
1530 | // fix current candidates if source row is specified |
---|
1531 | if (row != -1) |
---|
1532 | // these are the values to be used to fix current candidates |
---|
1533 | T_Filename = T_Filenames[row] |
---|
1534 | EMP_Filename = EMP_Filenames[row] |
---|
1535 | |
---|
1536 | // fix all invalid rows of current sample |
---|
1537 | in = ItemsInList(candidateRows, ",") |
---|
1538 | for (i = 0; i < in; i += 1) |
---|
1539 | row = str2num(StringFromList(i, candidateRows, ",")) |
---|
1540 | T_Filenames[row] = T_Filename |
---|
1541 | EMP_Filenames[row] = EMP_Filename |
---|
1542 | endfor |
---|
1543 | endif |
---|
1544 | endif |
---|
1545 | |
---|
1546 | |
---|
1547 | |
---|
1548 | // // if dicValidRows contains row number for current sample, then transmission can be determined |
---|
1549 | // row = NumberByKey(safeLabel, dicValidRows) // if item is not in dicValidRows then row is set to NaN |
---|
1550 | // if (numtype(row) == 0) // check for normal number |
---|
1551 | // S_Label = S_Labels[row] |
---|
1552 | // if (-1 != strsearch(rowSelection, ",", 0)) // check if more than one row is afftected |
---|
1553 | // sprintf message, "The transmission value of \"%s\" can be determined with the information provided in row %g.\rWould you like to apply the information to all rows with that sample? (Affected rows: %s)", S_Label, row, rowSelection |
---|
1554 | // else |
---|
1555 | // sprintf message, "The transmission value of \"%s\" can be determined with the information provided in row %g.\rWould you like to apply the information to all rows with that sample? (Affected row: %s)", S_Label, row, rowSelection |
---|
1556 | // endif |
---|
1557 | // DoAlert 2, message |
---|
1558 | // |
---|
1559 | // switch (V_flag) |
---|
1560 | // case 1: // yes |
---|
1561 | // T_Filename = T_Filenames[row] |
---|
1562 | // EMP_Filename = EMP_Filenames[row] |
---|
1563 | // // find sample and replace T- and EMP-Filename |
---|
1564 | // for (i = 0; i < in; i += 1) |
---|
1565 | // // check S-file |
---|
1566 | // if ((strlen(S_Filenames[i]) != 0) && CheckIfFileExists(Pathname + S_Filenames[i]) && (cmpstr(S_Label, S_Labels[i]) == 0)) |
---|
1567 | // T_Filenames[i] = T_Filename |
---|
1568 | // EMP_Filenames[i] = EMP_Filename |
---|
1569 | // endif |
---|
1570 | // endfor |
---|
1571 | // break |
---|
1572 | // |
---|
1573 | // case 3: // cancel |
---|
1574 | // return 0 |
---|
1575 | // endswitch |
---|
1576 | // |
---|
1577 | // // check if transmission of current sample could be determined |
---|
1578 | // elseif (-1 != strsearch(listUnclearSamples, safeLabel, 0)) |
---|
1579 | // S_Label = safeLabel |
---|
1580 | // S_Label = ReplaceString("\\3", S_Label, ";") |
---|
1581 | // S_Label = ReplaceString("\\2", S_Label, ":") |
---|
1582 | // S_Label = ReplaceString("\\1", S_Label, "\\") |
---|
1583 | // if (-1 != strsearch(rowSelection, ",", 0)) // check if more than one row is afftected |
---|
1584 | // sprintf message, "The transmission value of \"%s\" can be determined with the information provided by multiple rows.\rPlease complete the report file manually for that sample. (Affected rows: %s)", S_Label, rowSelection |
---|
1585 | // else |
---|
1586 | // sprintf message, "The transmission value of \"%s\" can be determined with the information provided by multiple rows.\rPlease complete the report file manually for that sample. (Affected row: %s)", S_Label, rowSelection |
---|
1587 | // endif |
---|
1588 | // DoAlert 0, message |
---|
1589 | // |
---|
1590 | // |
---|
1591 | // Example2() |
---|
1592 | // endif |
---|
1593 | endfor |
---|
1594 | else |
---|
1595 | DoAlert 0,"No file selected from Scattering Files table or no Scattering Files table available" |
---|
1596 | endif |
---|
1597 | End |
---|
1598 | |
---|
1599 | //shows a noteboox of help text describing how to calculate transmissions |
---|
1600 | // - better that the user read the igor or pdf file, but it's a victory to get |
---|
1601 | //users to read anything at all |
---|
1602 | // |
---|
1603 | Proc Trn_ShowHelpProc(ctrlName) : ButtonControl |
---|
1604 | String ctrlName |
---|
1605 | DisplayTransHelp() |
---|
1606 | End |
---|
1607 | |
---|
1608 | //sorts the tables by date |
---|
1609 | // |
---|
1610 | Proc Trn_SortFilesByDate(ctrlName) : ButtonControl |
---|
1611 | String ctrlName |
---|
1612 | SortGlobals(0) |
---|
1613 | End |
---|
1614 | |
---|
1615 | //sorts the tables alphabetically by the sample label field |
---|
1616 | // |
---|
1617 | Proc Trn_SortFilesByLabel(ctrlName) : ButtonControl |
---|
1618 | String ctrlName |
---|
1619 | SortGlobals(1) |
---|
1620 | End |
---|
1621 | |
---|
1622 | //button action procedure to select the local path to the |
---|
1623 | //folder containing the RAW SANS data files |
---|
1624 | // - once the data folder is selected, all of the popup file menus are |
---|
1625 | //forced to update with fresh file lists |
---|
1626 | // |
---|
1627 | Function Trn_PickPathButton(PathButton) : ButtonControl |
---|
1628 | String PathButton |
---|
1629 | |
---|
1630 | //set the global string to the selected pathname |
---|
1631 | Variable err |
---|
1632 | err = PickPath() |
---|
1633 | if(err) |
---|
1634 | return(1) //some problem with path or user cancelled, get out |
---|
1635 | endif |
---|
1636 | |
---|
1637 | PathInfo/S catPathName |
---|
1638 | String path = S_path |
---|
1639 | if (V_flag == 0) |
---|
1640 | //path does not exist - no folder selected |
---|
1641 | String/G root:myGlobals:TransHeaderInfo:gCatPathStr = "no folder selected" |
---|
1642 | else |
---|
1643 | String/G root:myGlobals:TransHeaderInfo:gCatPathStr = path |
---|
1644 | endif |
---|
1645 | |
---|
1646 | //Update the pathStr variable box |
---|
1647 | ControlUpdate/W=Trans_Panel $"Trn_setvar_0" |
---|
1648 | //Generate tables |
---|
1649 | Execute "BuildFileTables()" |
---|
1650 | |
---|
1651 | End |
---|
1652 | |
---|
1653 | //button action function that asks the user to set the XY box to sum over |
---|
1654 | //for all transmission calculations |
---|
1655 | // |
---|
1656 | // requires the user to set the box coordinates with the marquee popup |
---|
1657 | //that wil properly set the keyword string, and write the values to the empty beam header |
---|
1658 | // |
---|
1659 | Function Trn_SetXYBoxButton(ctrlName) : ButtonControl |
---|
1660 | String ctrlName |
---|
1661 | |
---|
1662 | String msgStr = "Select the Empty Beam File" |
---|
1663 | String filename="" |
---|
1664 | |
---|
1665 | //get the filename from the popup menu |
---|
1666 | //and construct a full path to it |
---|
1667 | SVAR partialName = root:myGlobals:TransHeaderInfo:gEMP |
---|
1668 | print partialName |
---|
1669 | //get a valid file based on this partialName and catPathName |
---|
1670 | String tempName = FindValidFilename(partialName) |
---|
1671 | if(cmpstr(tempName,"")==0) |
---|
1672 | //file not found, get out |
---|
1673 | Abort "Empty beam file not found Trn_SetXYBoxButton(ctrlName)" |
---|
1674 | Endif |
---|
1675 | //name is ok, prepend path to tempName for read routine |
---|
1676 | PathInfo catPathName |
---|
1677 | filename = S_path + tempName |
---|
1678 | |
---|
1679 | //read the file in - check for previous coordinates |
---|
1680 | ReadHeaderAndData(filename) |
---|
1681 | |
---|
1682 | Wave realw=$"root:Packages:NIST:RAW:RealsRead" |
---|
1683 | if (realw[26] == 0) |
---|
1684 | DoAlert /T="Warning" 0, "Lambda for this file is zero! You might need to patch this file again before you continue to work with it." |
---|
1685 | endif |
---|
1686 | |
---|
1687 | //data is displayed here (go through the normal display steps, so all is created properly |
---|
1688 | String/G root:myGlobals:gDataDisplayType="RAW" |
---|
1689 | fRawWindowHook() |
---|
1690 | |
---|
1691 | // check the empty beam file for previously selected coordinates |
---|
1692 | //if they exist, set the xy string , save the normalized counts somewhere |
---|
1693 | //the value was written to an unused r*4 header analysis.factor (@b494) |
---|
1694 | Variable refnum,x1,x2,y1,y2,err |
---|
1695 | getXYBoxFromFile(filename,x1,x2,y1,y2) |
---|
1696 | |
---|
1697 | //read the real count value, assign to a global |
---|
1698 | Variable/G root:myGlobals:gTransCts = getBoxCounts(filename) //***NOTE this is NOT in the Trans sub-folder |
---|
1699 | // |
---|
1700 | if( ((x1-x2)==0) || ((y1-y2)==0) ) //zero width marquee in either direction |
---|
1701 | //no region selected |
---|
1702 | |
---|
1703 | //add the empty beam file to work.SAM |
---|
1704 | err = Raw_to_work("SAM") |
---|
1705 | |
---|
1706 | //the calling macro must change the display type |
---|
1707 | String/G root:myGlobals:gDataDisplayType="SAM" //displayed data type is sam |
---|
1708 | |
---|
1709 | //data is displayed here |
---|
1710 | fRawWindowHook() |
---|
1711 | |
---|
1712 | //prompt user to select box w/marquee |
---|
1713 | DoAlert 0,"(1) Select the region to sum with the Marquee.\n(2) Right click into the selected region.\n(3) Click on SetXYBoxCoords" |
---|
1714 | // DoAlert 0,"Select the region to sum with the Marquee" |
---|
1715 | |
---|
1716 | //from here the Marquee menu selection must handle the task of setting the box |
---|
1717 | //and updating the information in the file header |
---|
1718 | else |
---|
1719 | // region already selected, just put up the values from the file header |
---|
1720 | //allow user the option of overriding the current box region |
---|
1721 | msgStr = "X1="+num2str(x1)+";" |
---|
1722 | msgStr += "X2="+num2str(x2)+";" |
---|
1723 | msgStr += "Y1="+num2str(y1)+";" |
---|
1724 | msgStr += "Y2="+num2str(y2)+";" |
---|
1725 | String textStr |
---|
1726 | textStr = "Override current box "+msgStr+" ?" |
---|
1727 | DoAlert 1,textStr |
---|
1728 | If((V_flag)==1) |
---|
1729 | //get new box coordinates, same procedure as above |
---|
1730 | //add the empty beam file to work.SAM |
---|
1731 | err = Raw_to_work("SAM") |
---|
1732 | |
---|
1733 | //the calling macro must change the display type |
---|
1734 | String/G root:myGlobals:gDataDisplayType="SAM" //displayed data type is sam |
---|
1735 | |
---|
1736 | //data is displayed here |
---|
1737 | fRawWindowHook() |
---|
1738 | |
---|
1739 | //prompt user to select box w/marquee |
---|
1740 | DoAlert 0,"(1) Select the region to sum with the Marquee.\n(2) Right click into the selected region.\n(3) Click on SetXYBoxCoords" |
---|
1741 | // DoAlert 0,"Select the region to sum with the Marquee" |
---|
1742 | |
---|
1743 | //from here the Marquee menu selection must handle the task of setting the box |
---|
1744 | //and updating the information in the file header |
---|
1745 | else |
---|
1746 | String/G root:myGlobals:TransHeaderInfo:gBox = msgStr |
---|
1747 | Endif |
---|
1748 | Endif |
---|
1749 | |
---|
1750 | UpdateBoxCoordinates() |
---|
1751 | Return (0) |
---|
1752 | End |
---|
1753 | |
---|
1754 | |
---|
1755 | //button action function that assigns the selected empty beam file (run number only) |
---|
1756 | //and the sample trnansmissionfile (run number only) to the popup list of sample scattering |
---|
1757 | //files (ALL of the list items). Assignment is done by writing the integer run numbers of |
---|
1758 | //trans files to the header of each of the scattering files, in a batchwise processing |
---|
1759 | //of the popup list |
---|
1760 | // |
---|
1761 | //transmission are not calculated here - only the file numbers are set |
---|
1762 | // |
---|
1763 | //*********unused*********** |
---|
1764 | //Function Trn_AssignAllFilesButton(ctrlName) : ButtonControl |
---|
1765 | // String ctrlName |
---|
1766 | // |
---|
1767 | // AssignTransFilesToData() |
---|
1768 | // |
---|
1769 | //End |
---|
1770 | |
---|
1771 | //button action procedure to calculate the transmission of all of the sample files in the |
---|
1772 | //sample popup list, based on the information in EACH sample header and in the empty beam file |
---|
1773 | //the box must be set properly in the empty beam file, AND the empty and trans |
---|
1774 | //run number must also be set properly in EACH scattering file, |
---|
1775 | //If run numbers are not properly assigned, no trans is calculated and the |
---|
1776 | //header is not modified |
---|
1777 | // |
---|
1778 | //The RAW data header of EACH sample file IS modified, with the newly calculated transmission |
---|
1779 | // |
---|
1780 | //not very friendly, but forces users to assign the files before continuing |
---|
1781 | // |
---|
1782 | Function Trn_CalcAllFilesButton(ctrlName) : ButtonControl |
---|
1783 | String ctrlName |
---|
1784 | |
---|
1785 | //calculate the transmission and Patch the header (if possible) |
---|
1786 | Wave/T S_Filenames = $"root:myGlobals:TransHeaderInfo:S_Filenames" |
---|
1787 | Variable num_s_files = numpnts(S_Filenames) |
---|
1788 | CalcSelTransFromHeader(0,num_s_files-1) |
---|
1789 | |
---|
1790 | End |
---|
1791 | |
---|
1792 | //for selected scattering files in the scattering table, |
---|
1793 | // the "Annn" association of trans file is written to the data file, |
---|
1794 | // the the transmission is actually calculated |
---|
1795 | // |
---|
1796 | Function Trn_CalcSelectedFilesButton(ctrlName) : ButtonControl |
---|
1797 | String ctrlName |
---|
1798 | |
---|
1799 | Variable scatterTableExists |
---|
1800 | scatterTableExists = WinType("ScatterFileTable") |
---|
1801 | if (scatterTableExists != 0) |
---|
1802 | GetSelection table,ScatterFileTable,1 |
---|
1803 | if(V_Flag != 0) |
---|
1804 | //AssignSelTransFilesToData(V_StartRow,V_EndRow) |
---|
1805 | //calculate the transmission and Patch the header (if possible) |
---|
1806 | CalcSelTransFromHeader(V_StartRow,V_EndRow) |
---|
1807 | Else |
---|
1808 | DoAlert 0,"No selection from Scattering Files table" |
---|
1809 | Endif |
---|
1810 | Else |
---|
1811 | DoAlert 0,"No file selected from Scattering Files table or no Scattering Files table available" |
---|
1812 | Endif |
---|
1813 | End |
---|
1814 | |
---|
1815 | // |
---|
1816 | // I am not sure what the difference is inthe function of CalcTotalTrans and CalcWholeTrans ? |
---|
1817 | // do they really do anything different? |
---|
1818 | // is it a useful calculation at all? |
---|
1819 | // |
---|
1820 | Function TotalTrans(ctrlName) : ButtonControl |
---|
1821 | String ctrlName |
---|
1822 | |
---|
1823 | Variable scatTableExists |
---|
1824 | scatTableExists = WinType("ScatterFileTable") |
---|
1825 | if (scatTableExists != 0) |
---|
1826 | GetSelection table,ScatterFileTable,1 |
---|
1827 | if(V_Flag != 0) |
---|
1828 | //AssignTotalTransFilesToData(V_StartRow,V_EndRow) |
---|
1829 | //calculate the transmission and Patch the header (if possible) |
---|
1830 | CalcTotalTrans(V_StartRow,V_EndRow) |
---|
1831 | CalcWholeTrans(V_StartRow,V_EndRow) |
---|
1832 | Else |
---|
1833 | DoAlert 0,"No selection from Trans Files table" |
---|
1834 | Endif |
---|
1835 | Else |
---|
1836 | DoAlert 0,"No file selected from Trans Files table or no Trans Files table available" |
---|
1837 | Endif |
---|
1838 | End |
---|
1839 | |
---|
1840 | |
---|
1841 | //simple button procedure to close the trans panel |
---|
1842 | // - automatically kills the two tables as well |
---|
1843 | // |
---|
1844 | Function Trn_PanelDoneButtonProc(ctrlName) : ButtonControl |
---|
1845 | String ctrlName |
---|
1846 | |
---|
1847 | // this button will make sure all files are closed |
---|
1848 | //and close the panel |
---|
1849 | |
---|
1850 | Close/A |
---|
1851 | DoWindow/K Trans_Panel |
---|
1852 | DoWindow/K ScatterFileTable |
---|
1853 | DoWindow/K TransFileTable |
---|
1854 | End |
---|
1855 | |
---|
1856 | |
---|
1857 | //function to update the box coordinates of the file selected as the |
---|
1858 | //empty beam file - takes the file that is currently popped from the list |
---|
1859 | //reads the 4 "analysis" integers that hold the box coordinates |
---|
1860 | //resets the globals string that is displayed with the new values |
---|
1861 | //should be called whenever the "empty" popup is popped, to ensure |
---|
1862 | //that current header information is displayed |
---|
1863 | // |
---|
1864 | Function UpdateBoxCoordinates() |
---|
1865 | |
---|
1866 | //construct a full name, and read in the label from the file |
---|
1867 | //and set the global |
---|
1868 | String textstr="" |
---|
1869 | ControlInfo empStr |
---|
1870 | SVAR item = root:myGlobals:TransHeaderInfo:gEMP |
---|
1871 | String tempName = FindValidFilename(item) |
---|
1872 | if(cmpstr(tempName,"")==0) |
---|
1873 | //file not found, get out |
---|
1874 | Abort "Empty beam file not found UpdateBoxCoordinates(ctrlName)" |
---|
1875 | Endif |
---|
1876 | //name is ok, prepend path to tempName for read routine |
---|
1877 | PathInfo catPathName |
---|
1878 | String filename = S_path + tempName |
---|
1879 | |
---|
1880 | Variable refnum,x1,x2,y1,y2,err |
---|
1881 | GetXYBoxFromFile(filename,x1,x2,y1,y2) |
---|
1882 | |
---|
1883 | //and update the global string |
---|
1884 | String msgStr="" |
---|
1885 | msgStr = "X1="+num2str(x1)+";" |
---|
1886 | msgStr += "X2="+num2str(x2)+";" |
---|
1887 | msgStr += "Y1="+num2str(y1)+";" |
---|
1888 | msgStr += "Y2="+num2str(y2)+";" |
---|
1889 | |
---|
1890 | String/G root:myGlobals:TransHeaderInfo:gBox = msgStr |
---|
1891 | |
---|
1892 | ControlUpdate/W=Trans_panel Trn_setvar_1 |
---|
1893 | End |
---|
1894 | |
---|
1895 | //crude procedure to display a notebook of help information for users |
---|
1896 | // |
---|
1897 | Proc DisplayTransHelp() |
---|
1898 | String nb = "Notebook0" |
---|
1899 | NewNotebook/N=$nb/F=1/V=1/W=(342,302,868,674) as "Notebook0:Transmission Help" |
---|
1900 | Notebook $nb defaultTab=36, statusWidth=238, pageMargins={36,72,36,72} |
---|
1901 | Notebook $nb showRuler=1, rulerUnits=1, updating={1, 3600} |
---|
1902 | Notebook $nb newRuler=Normal, justification=0, margins={0,0,468}, spacing={0,0,0}, tabs={}, rulerDefaults={"Geneva",10,0,(0,0,0)} |
---|
1903 | Notebook $nb ruler=Normal; Notebook $nb justification=1, fSize=14, fStyle=1, text="Transmission Help\r" |
---|
1904 | Notebook $nb ruler=Normal, fSize=-1, fStyle=-1, text="\r" |
---|
1905 | Notebook $nb text="This panel allows quick and easy calculation of sample transmission. The neutron transmission of a sampl" |
---|
1906 | Notebook $nb text="e must be calculated and entered into the header of each sample scattering file before proper background" |
---|
1907 | Notebook $nb text=" corrections or absolute scaling can be done.\r" |
---|
1908 | Notebook $nb text="\r" |
---|
1909 | Notebook $nb text="During data collection, you measured an empty beam - that is a measurement with heavy attenuation of th" |
---|
1910 | Notebook $nb text="e neutron beam and the beamstop mover out of line with the direct beam. Then without changing the attenu" |
---|
1911 | Notebook $nb text="ation or replacing the beamstop, you put a sample in the beam, and repeated the measurement (a sample tr" |
---|
1912 | Notebook $nb text="ansmission measurement). The neutron transmission of the sample is simply the ratio of the number of neu" |
---|
1913 | Notebook $nb text="tron counts from the sample transmission measurement normalized by the number of neutron counts from the" |
---|
1914 | Notebook $nb text=" empty beam measurement. In this way, each sample transmission file is \"linked\" to the same empty beam t" |
---|
1915 | Notebook $nb text="ransmission file.\r" |
---|
1916 | Notebook $nb text="\r" |
---|
1917 | Notebook $nb text="This calculated transmission value must be entered into the header of the sample scattering measurement " |
---|
1918 | Notebook $nb text="- that is the measurement of the sample with the beamstop covering the primary (transmitted) beam, and n" |
---|
1919 | Notebook $nb text="o (or few) attenuators in place. In this way, the sample transmission file is \"linked\" to its correspond" |
---|
1920 | Notebook $nb text="ing sample scattering file. This panel allows you to set up the links and calculate the transmission.Tra" |
---|
1921 | Notebook $nb text="nsmisison values are automatically patched to the scattering file headers as they are calculated.\r" |
---|
1922 | Notebook $nb text="\r" |
---|
1923 | Notebook $nb text="To Calculate Transmissions:\r" |
---|
1924 | Notebook $nb text="\r" |
---|
1925 | Notebook $nb text="1) Click \"List Files\" to get two lists (tables) - one of all the sample scattering files in the folder, " |
---|
1926 | Notebook $nb text="and one of the transmission files.\r" |
---|
1927 | Notebook $nb text="\r" |
---|
1928 | Notebook $nb text="2) Select the region of the detector to sum over from the empty beam transmission file. Do theis by clic" |
---|
1929 | Notebook $nb text="king on the filename of the empty beam transmision file (from the TransmissionFiles window, in the blue " |
---|
1930 | Notebook $nb text="\"T_Filenames\" column). Return to the panel, and click the \"set EMP file\" button\", and the filename shoul" |
---|
1931 | 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" |
---|
1932 | Notebook $nb text="et XY Box\" button. The empty beam file will be displayed, and you will be instructed to select the regio" |
---|
1933 | Notebook $nb text="n to sum with the marquee. On the data, click and drag a rectangle that encompasses the primary beam. Mo" |
---|
1934 | Notebook $nb text="ve the cursor inside the selection, to get an \"upside-down hat\" cursor. Click to get a menu, and near th" |
---|
1935 | Notebook $nb text="e bottom, select \"Set XY Box Coords\". The pixel values should be updated to the Transmission panel, and " |
---|
1936 | Notebook $nb text="are written to the empty beam header for future calculations. Note that the marquee selection can also b" |
---|
1937 | Notebook $nb text="e used to measure the beam center, or centroid of any selected region.\r" |
---|
1938 | Notebook $nb text="\r" |
---|
1939 | Notebook $nb text="3) Now you need to \"link\" the ", fStyle=2, text="sample", fStyle=-1, text=" transmission files to the " |
---|
1940 | Notebook $nb fStyle=2, text="empty", fStyle=-1, text=" ", fStyle=2, text="beam", fStyle=-1 |
---|
1941 | Notebook $nb text=" transmission file. Do this in the TransmissionFiles window by selecting the filename (in the blue T_Fil" |
---|
1942 | Notebook $nb text="enames column) and pasing it to the corresponding row(s) in the T_EMP_Filenames column. This links the e" |
---|
1943 | Notebook $nb text="mpty beam transmission with the sample transmission file. Do this for every sample transmission file.\r" |
---|
1944 | Notebook $nb text="\r" |
---|
1945 | Notebook $nb text="4) Now you need to link the sample ", fStyle=2, text="transmission", fStyle=-1 |
---|
1946 | Notebook $nb text=" file to the sample ", fStyle=2, text="scattering", fStyle=-1 |
---|
1947 | Notebook $nb text=" file. Do this by selecting the name of the transmission file (from the blue T_Filenames column) and pas" |
---|
1948 | Notebook $nb text="ting it into the corresponding row of the S_TRANS_Filenames column of the ScatteringFiles window. This l" |
---|
1949 | Notebook $nb text="inks the scattering file to its corresponding sample transmission file. This for all of the sample scatt" |
---|
1950 | Notebook $nb text="ering files.\r" |
---|
1951 | Notebook $nb text="\r" |
---|
1952 | Notebook $nb text="5) Calculate the transmissions (and automatically write the transmission value to the satterng file head" |
---|
1953 | Notebook $nb text="er) by clicking \"Calculate All Files\" from the Transmission Panel. The results will be printed to the co" |
---|
1954 | Notebook $nb text="mmand window at the bottom of the screen. Any improperly assigned files will be listed. For example, blo" |
---|
1955 | Notebook $nb text="cked beam scattering files will return an error, since the transmssion known to be zero, and is not meas" |
---|
1956 | Notebook $nb text="ured (and no files are \"linked\"). Rather than calculating the transmission of all of the files, a range" |
---|
1957 | Notebook $nb text=" of S_Filenames can be selected, then calculated by clicking \"Calculate Selected Files\".\r" |
---|
1958 | Notebook $nb text="\r" |
---|
1959 | Notebook $nb text="By default the lists are sorted by run number (= chronological). In some cases it may be easier to sort " |
---|
1960 | Notebook $nb text="by the sample label to group several of the same sample scattering files collected at different sample-t" |
---|
1961 | Notebook $nb text="o-detector distances. Its utility depends, of course, on how consistent and unique your sample labels ar" |
---|
1962 | Notebook $nb text="e.\r" |
---|
1963 | Notebook $nb text="\r" |
---|
1964 | Notebook $nb text="The \"links\" are stored in the corresponding files, and wil be re-generated when the lists are re-generat" |
---|
1965 | Notebook $nb text="ed. Unassigned links will appear as blank elements in the T_EMP_Filenames or S_TRANS_Filenames columns.\r" |
---|
1966 | Notebook $nb text="\r" |
---|
1967 | Notebook $nb, selection={startOfFile,startOfFile} |
---|
1968 | Notebook $nb text="\r" |
---|
1969 | End |
---|
1970 | |
---|
1971 | |
---|
1972 | |
---|
1973 | //******************* |
---|
1974 | //************ |
---|
1975 | // A simple panel to allow users of the NG1 SANS instrument to make their |
---|
1976 | // transmission files "look" like a transmission measurement to the data reduction |
---|
1977 | // program. Transmission files are designated by an x-position of the beamstop of |
---|
1978 | // < -5 (cm). this simple procedure sets xpos=-10 for individual files. files |
---|
1979 | // con be "un-converted", which set the xpos=0. |
---|
1980 | // 1/30/01 SRK |
---|
1981 | //************ |
---|
1982 | |
---|
1983 | Proc TransformToTransFile() |
---|
1984 | Variable/G root:myGlobals:gConvTrans=1 |
---|
1985 | DoWindow/F Convert_to_Trans |
---|
1986 | if(V_flag==0) |
---|
1987 | Convert2Trans() |
---|
1988 | endif |
---|
1989 | End |
---|
1990 | |
---|
1991 | //fname must be the full path and name for the file |
---|
1992 | Function ChangeBSXPos(fname,xpos) |
---|
1993 | String fname |
---|
1994 | Variable xpos |
---|
1995 | |
---|
1996 | Variable start |
---|
1997 | //x-position starts after byte 368 in VAX files |
---|
1998 | WriteBSXPosToHeader(fname,xpos) |
---|
1999 | return(0) |
---|
2000 | End |
---|
2001 | |
---|
2002 | //sets the beamstop position to zero NOT the original position |
---|
2003 | Function UnConvertButtonProc(ctrlName) : ButtonControl |
---|
2004 | String ctrlName |
---|
2005 | |
---|
2006 | //Print "UnConvert" |
---|
2007 | String fullname="" |
---|
2008 | ControlInfo fileNum |
---|
2009 | Variable num = V_Value //run number to find |
---|
2010 | |
---|
2011 | fullname = FindFileFromRunNumber(num) |
---|
2012 | Print fullname |
---|
2013 | //report error or change the file |
---|
2014 | if(cmpstr(fullname,"")==0) |
---|
2015 | Print "Unconvert - file not found" |
---|
2016 | else |
---|
2017 | //Print "Unconvert",fullname |
---|
2018 | ChangeBSXPos(fullName,0) |
---|
2019 | Endif |
---|
2020 | return(0) |
---|
2021 | End |
---|
2022 | |
---|
2023 | //button procedure to do the conversion |
---|
2024 | // writes fake beamstop position to the data file |
---|
2025 | // |
---|
2026 | Function ConvertButtonProc(ctrlName) : ButtonControl |
---|
2027 | String ctrlName |
---|
2028 | |
---|
2029 | String fullname="" |
---|
2030 | ControlInfo fileNum |
---|
2031 | Variable num = V_Value //run number to find |
---|
2032 | |
---|
2033 | fullname = FindFileFromRunNumber(num) |
---|
2034 | print fullname |
---|
2035 | //report error or change the file |
---|
2036 | if(cmpstr(fullname,"")==0) |
---|
2037 | Print "Convert - file not found" |
---|
2038 | else |
---|
2039 | //Print "Convert",fullname |
---|
2040 | ChangeBSXPos(fullName,-10) |
---|
2041 | Endif |
---|
2042 | return(0) |
---|
2043 | End |
---|
2044 | |
---|
2045 | //simple panel recreation macro |
---|
2046 | // |
---|
2047 | Proc Convert2Trans() |
---|
2048 | PauseUpdate; Silent 1 // building window... |
---|
2049 | NewPanel /W=(434,74,671,216) /K=1 |
---|
2050 | DoWindow/C Convert_to_Trans |
---|
2051 | SetDrawLayer UserBack |
---|
2052 | DrawText 18,22,"Convert files to be recognized" |
---|
2053 | DrawText 43,39,"as transmission files" |
---|
2054 | SetVariable fileNum,pos={43,58},size={130,15},title="File Number" |
---|
2055 | SetVariable fileNum,limits={1,Inf,1},value=root:myGlobals:gConvTrans |
---|
2056 | SetVariable fileNum,help={"Sets the run number of the file that is to be converted"} |
---|
2057 | Button ConvButton,pos={73,79},size={80,20},proc=ConvertButtonProc,title="Convert" |
---|
2058 | Button ConvButton,help={"Converts the chosen file to appear as a transmission file"} |
---|
2059 | Button UndoButton,pos={68,105},size={90,20},proc=UnConvertButtonProc,title="Un-Convert" |
---|
2060 | Button UndoButton,help={"Converts the chosen file to appear as a scattering file"} |
---|
2061 | EndMacro |
---|
2062 | |
---|
2063 | |
---|
2064 | ///// |
---|
2065 | // A quick way to fill all the T_EMP_Filenames with the selected empty beam file |
---|
2066 | // Note that you must go back and clear or reassign any files that are special cases |
---|
2067 | // |
---|
2068 | // IMPORTANT - this will overwrite any other file assignments (typically not a problem |
---|
2069 | // if you are using only one wavelength) |
---|
2070 | // |
---|
2071 | ///// |
---|
2072 | Function FillEMPFilenameWSelection() |
---|
2073 | |
---|
2074 | GetSelection table,TransFileTable,3 |
---|
2075 | Variable row=V_startRow //ony need the selected row, we know the column names and location |
---|
2076 | Wave/T fw = root:myGlobals:TransHeaderInfo:T_FileNames //trans files |
---|
2077 | Wave/T ew = root:myGlobals:TransHeaderInfo:T_EMP_FileNames //empty beam reference files |
---|
2078 | |
---|
2079 | ew[] = fw[row] |
---|
2080 | |
---|
2081 | return(0) |
---|
2082 | End |
---|
2083 | |
---|
2084 | //given a selection of the SAMPLE files, try to find the corresponding transmission file |
---|
2085 | // |
---|
2086 | Function GuessTransFile(charsToUse,row) |
---|
2087 | Variable charsToUse,row //number of characers to use from the beginning of the label, and the row of the sample file |
---|
2088 | |
---|
2089 | // GetSelection table,ScatterFileTable,3 |
---|
2090 | // Variable row=V_startRow //ony need the selected row, we know the column names and location |
---|
2091 | Wave/T sw = root:myGlobals:TransHeaderInfo:S_Labels //Sample file labels |
---|
2092 | Wave/T tw = root:myGlobals:TransHeaderInfo:T_Labels //trans file labels |
---|
2093 | Wave/T tnam = root:myGlobals:TransHeaderInfo:T_FileNames //trans file names |
---|
2094 | Wave/T snam = root:myGlobals:TransHeaderInfo:S_TRANS_FileNames //Scattering - trans correspondence |
---|
2095 | |
---|
2096 | Variable num,ii,found |
---|
2097 | String samStr = "",testStr="" |
---|
2098 | |
---|
2099 | samStr = (sw[row])[0,charsToUse-1] //string to try and match |
---|
2100 | samStr += "*" |
---|
2101 | // Print samStr |
---|
2102 | num=numpnts(tw) |
---|
2103 | ii=0 |
---|
2104 | do |
---|
2105 | testStr=tw[ii] |
---|
2106 | found = stringmatch(testStr, samStr ) |
---|
2107 | if(found == 1) |
---|
2108 | Print "Match Found at: ",samStr,tnam[ii],tw[ii] |
---|
2109 | snam[row] = tnam[ii] //write the file name into the table |
---|
2110 | return(0) |
---|
2111 | endif |
---|
2112 | ii+=1 |
---|
2113 | while(ii<num) |
---|
2114 | |
---|
2115 | //method 2 |
---|
2116 | // samStr = (sw[row])[0,charsToUse-1] //string to try and match |
---|
2117 | //// Print samStr |
---|
2118 | // num=numpnts(tw) |
---|
2119 | // ii=0 |
---|
2120 | // do |
---|
2121 | // testStr=tw[ii] |
---|
2122 | // found = strsearch(testStr,samStr,0) //start from zero, Need Igor 5 to allow 4th parameter to ignore case |
---|
2123 | // if(found != -1) |
---|
2124 | // Print "Match Found at: ",samStr,tnam[ii],tw[ii] |
---|
2125 | // snam[row] = tnam[ii] //write the file name into the table |
---|
2126 | // return(0) |
---|
2127 | // endif |
---|
2128 | // ii+=1 |
---|
2129 | // while(ii<num) |
---|
2130 | |
---|
2131 | Print "No Match found" |
---|
2132 | return(0) |
---|
2133 | End |
---|
2134 | |
---|
2135 | //given a single transmission file, try to find the corresponding scattering file(s) |
---|
2136 | // |
---|
2137 | // apply TWO criteria |
---|
2138 | // (1) the label must match "well enough" |
---|
2139 | // (2) the wavelength must be the same |
---|
2140 | // |
---|
2141 | // passes the matching rows in the sample table back |
---|
2142 | // |
---|
2143 | Function GuessTransToScattFiles(charsToUse,row,matchRows) |
---|
2144 | Variable charsToUse,row //number of characers to use from the beginning of the label, and the row of the transmission file |
---|
2145 | Wave matchRows //rows where (potential) matches found. initially zero points |
---|
2146 | |
---|
2147 | Wave/T sw = root:myGlobals:TransHeaderInfo:S_Labels //Sample file labels |
---|
2148 | Wave/T tw = root:myGlobals:TransHeaderInfo:T_Labels //trans file labels |
---|
2149 | Wave/T tnam = root:myGlobals:TransHeaderInfo:T_FileNames //trans file names |
---|
2150 | Wave/T snam = root:myGlobals:TransHeaderInfo:S_TRANS_FileNames //Scattering - trans correspondence |
---|
2151 | Wave sLam = root:myGlobals:TransHeaderInfo:S_Lambda //Scattering file wavelength |
---|
2152 | Wave tLam = root:myGlobals:TransHeaderInfo:T_Lambda //Transmission file wavelength |
---|
2153 | |
---|
2154 | Variable num,ii,found |
---|
2155 | String transStr = "",testStr="" |
---|
2156 | |
---|
2157 | transStr = (tw[row])[0,charsToUse-1] //string to try and match |
---|
2158 | transStr += "*" |
---|
2159 | |
---|
2160 | //loop over ALL sample files |
---|
2161 | num=numpnts(sw) |
---|
2162 | ii=0 |
---|
2163 | do |
---|
2164 | testStr=sw[ii] |
---|
2165 | found = stringmatch(testStr, transStr ) |
---|
2166 | if( (found == 1) && (sLam[ii] == tLam[row]) ) // both must match |
---|
2167 | Print "Match Found at: ",transStr,snam[ii],sw[ii] |
---|
2168 | InsertPoints numpnts(matchRows), 1, matchRows |
---|
2169 | matchRows[numpnts(matchRows)-1] = ii |
---|
2170 | endif |
---|
2171 | ii+=1 |
---|
2172 | while(ii<num) |
---|
2173 | |
---|
2174 | //method 2 *UNTESTED* |
---|
2175 | // transStr = (tw[row])[0,charsToUse-1] //string to try and match |
---|
2176 | // num=numpnts(sw) |
---|
2177 | // ii=0 |
---|
2178 | // do |
---|
2179 | // testStr=sw[ii] |
---|
2180 | // found = strsearch(testStr,transStr,0,2) //start from zero, ignore case |
---|
2181 | // if(found != -1) |
---|
2182 | // Print "Match Found at: ",transStr,snam[ii],sw[ii] |
---|
2183 | // InsertPoints numpnts(matchRows), 1, matchRows |
---|
2184 | // matchRows[numpnts(matchRows)-1] = ii |
---|
2185 | //// snam[ii] = tnam[row] //write the file name into the table |
---|
2186 | // endif |
---|
2187 | // ii+=1 |
---|
2188 | // while(ii<num) |
---|
2189 | |
---|
2190 | // Print "No Match found" |
---|
2191 | return(0) |
---|
2192 | End |
---|
2193 | |
---|
2194 | //get a single selection from the Trans table |
---|
2195 | // find all of the matching scattering files (rows) |
---|
2196 | // ask the user if the selections are OK |
---|
2197 | // if NOT OK, do nothing |
---|
2198 | // if OK: make the assignments, and immediately calculate the transmission |
---|
2199 | // |
---|
2200 | Function fGuessTransToScattFiles(numChars) |
---|
2201 | Variable numChars |
---|
2202 | |
---|
2203 | Variable ii,row |
---|
2204 | Variable transTableExists |
---|
2205 | Make/O/D/N=0 root:myGlobals:TransHeaderInfo:matchRows |
---|
2206 | Wave matchRows=root:myGlobals:TransHeaderInfo:matchRows |
---|
2207 | |
---|
2208 | transTableExists = WinType("TransFileTable") |
---|
2209 | if (transTableExists != 0) |
---|
2210 | GetSelection table,transFileTable,1 |
---|
2211 | row = V_startRow |
---|
2212 | GuessTransToScattFiles(numChars,row,matchRows) |
---|
2213 | else |
---|
2214 | Print "Transmission->Scattering File table is not open" |
---|
2215 | return (1) |
---|
2216 | endif |
---|
2217 | |
---|
2218 | Wave/T sw = root:myGlobals:TransHeaderInfo:S_Labels //Sample file labels |
---|
2219 | Wave/T tw = root:myGlobals:TransHeaderInfo:T_Labels //trans file labels |
---|
2220 | Wave/T tnam = root:myGlobals:TransHeaderInfo:T_FileNames //trans file names |
---|
2221 | Wave/T snam = root:myGlobals:TransHeaderInfo:S_TRANS_FileNames //Scattering - trans correspondence |
---|
2222 | Wave/T samfile = root:myGlobals:TransHeaderInfo:S_FileNames //Scattering file name |
---|
2223 | |
---|
2224 | // can do fancy formatted string with ... |
---|
2225 | //"asdf* matches file: \\f01filen\\f00 \\K(52428,1,1)\\f01afdsfdd\\f00\\K(0,0,0)asdfasdfs" |
---|
2226 | Variable num=numpnts(matchRows) |
---|
2227 | String result="",tmpStr |
---|
2228 | for(ii=0;ii<num;ii+=1) |
---|
2229 | 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] |
---|
2230 | result += tmpStr |
---|
2231 | endfor |
---|
2232 | |
---|
2233 | if(cmpstr(result,"")==0) |
---|
2234 | result = "No match found for "+ (tw[row])[0,numChars-1] |
---|
2235 | endif |
---|
2236 | |
---|
2237 | // Print result |
---|
2238 | Print "*******" |
---|
2239 | |
---|
2240 | String/G root:myGlobals:TransHeaderInfo:gResultStr = result |
---|
2241 | |
---|
2242 | DoWindow/F ConfirmGuess //it really shouldn't exist... |
---|
2243 | if(V_flag==1) |
---|
2244 | TitleBox title0,pos={9,5},variable=root:myGlobals:TransHeaderInfo:gResultStr |
---|
2245 | else |
---|
2246 | NewPanel /W=(578,44,1263,214) as "Confirm Guess" |
---|
2247 | DoWindow/C ConfirmGuess |
---|
2248 | TitleBox title0,pos={9,5},size={501,32} |
---|
2249 | TitleBox title0,variable= root:myGlobals:TransHeaderInfo:gResultStr |
---|
2250 | Button button0,pos={9,107},size={190,20},proc=DoAssignTransButtonProc,title="Assign Transmission Files" |
---|
2251 | Button button2,pos={341,108},size={90,20},proc=DoTryAgainButtonProc,title="Try Again" |
---|
2252 | ToolsGrid snap=1,visible=1 |
---|
2253 | endif |
---|
2254 | |
---|
2255 | PauseForUser ConfirmGuess |
---|
2256 | |
---|
2257 | // figure out from the return code what the user did... |
---|
2258 | // 1 = OK, accept guess (assign, and calculate immediately) |
---|
2259 | // 2 = try again |
---|
2260 | // 0 = cancel, don't do anything (not used, simply try again) |
---|
2261 | NVAR guessOK = root:myGlobals:TransHeaderInfo:GuessOK |
---|
2262 | |
---|
2263 | // switch here... |
---|
2264 | switch(guessOK) // numeric switch |
---|
2265 | case 1: |
---|
2266 | // accept guess (assign, and calculate immediately) |
---|
2267 | for(ii=0;ii<num;ii+=1) |
---|
2268 | snam[matchRows[ii]] = tnam[row] |
---|
2269 | //AssignSelTransFilesToData(matchRows[ii],matchRows[ii]) |
---|
2270 | CalcSelTransFromHeader(matchRows[ii],matchRows[ii]) //does only that sample file |
---|
2271 | endfor |
---|
2272 | break |
---|
2273 | case 2: //try again (with more / fewer characters?) |
---|
2274 | // does nothing right now |
---|
2275 | break |
---|
2276 | case 0: |
---|
2277 | // do nothing |
---|
2278 | break |
---|
2279 | default: |
---|
2280 | // do nothing |
---|
2281 | endswitch |
---|
2282 | |
---|
2283 | return(0) |
---|
2284 | End |
---|
2285 | |
---|
2286 | // a hook attached to the Transmission Files Table |
---|
2287 | // given a single selected Trans File, popup gives choices |
---|
2288 | // to guess using "n" characters, then dispatch accordingly |
---|
2289 | Function GuessFromTableHook(infoStr) |
---|
2290 | String infoStr |
---|
2291 | String event= StringByKey("EVENT",infoStr) |
---|
2292 | // Print "EVENT= ",event |
---|
2293 | |
---|
2294 | String menuStr="" |
---|
2295 | menuStr += "Guess using 3 characters;" |
---|
2296 | menuStr += "Guess using 6 characters;" |
---|
2297 | menuStr += "Guess using 9 characters;" |
---|
2298 | menuStr += "Guess using 12 characters;" |
---|
2299 | menuStr += "Guess using 15 characters;" |
---|
2300 | menuStr += "Guess using 18 characters;" |
---|
2301 | menuStr += "Guess using 21 characters;" |
---|
2302 | menuStr += "Guess using 24 characters;" |
---|
2303 | |
---|
2304 | strswitch(event) |
---|
2305 | case "mousedown": |
---|
2306 | Variable xpix= NumberByKey("MOUSEX",infoStr) |
---|
2307 | Variable ypix= NumberByKey("MOUSEY",infoStr) |
---|
2308 | Variable modif= NumberByKey("MODIFIERS",infoStr) |
---|
2309 | //print modif |
---|
2310 | if(modif & 2^1) //bit 1 set, shift key is down |
---|
2311 | PopupContextualMenu/C=(xpix, ypix) menuStr |
---|
2312 | strswitch(S_selection) |
---|
2313 | case "Guess using 3 characters": |
---|
2314 | fGuessTransToScattFiles(3) |
---|
2315 | break |
---|
2316 | case "Guess using 6 characters": |
---|
2317 | fGuessTransToScattFiles(6) |
---|
2318 | break |
---|
2319 | case "Guess using 9 characters": |
---|
2320 | fGuessTransToScattFiles(9) |
---|
2321 | break |
---|
2322 | case "Guess using 12 characters": |
---|
2323 | fGuessTransToScattFiles(12) |
---|
2324 | break |
---|
2325 | case "Guess using 15 characters": |
---|
2326 | fGuessTransToScattFiles(15) |
---|
2327 | break |
---|
2328 | case "Guess using 18 characters": |
---|
2329 | fGuessTransToScattFiles(18) |
---|
2330 | break |
---|
2331 | case "Guess using 21 characters": |
---|
2332 | fGuessTransToScattFiles(21) |
---|
2333 | break |
---|
2334 | case "Guess using 24 characters": |
---|
2335 | fGuessTransToScattFiles(24) |
---|
2336 | break |
---|
2337 | endswitch //on selection |
---|
2338 | endif |
---|
2339 | endswitch // on event |
---|
2340 | |
---|
2341 | return 0 |
---|
2342 | End |
---|
2343 | |
---|
2344 | // sets a flag if the user thinks that the guess was correct, and wants to use the |
---|
2345 | // identified files for the transmission |
---|
2346 | Function DoAssignTransButtonProc(ba) : ButtonControl |
---|
2347 | STRUCT WMButtonAction &ba |
---|
2348 | |
---|
2349 | switch( ba.eventCode ) |
---|
2350 | case 2: // mouse up |
---|
2351 | // click code here |
---|
2352 | //Print "Assigned stuff, and left." |
---|
2353 | Variable/G root:myGlobals:TransHeaderInfo:GuessOK= 1 |
---|
2354 | DoWindow/K ConfirmGuess |
---|
2355 | break |
---|
2356 | endswitch |
---|
2357 | |
---|
2358 | |
---|
2359 | return 0 |
---|
2360 | End |
---|
2361 | |
---|
2362 | // files are wrong, let the user try it again |
---|
2363 | // sets a flag, nothing else |
---|
2364 | Function DoTryAgainButtonProc(ba) : ButtonControl |
---|
2365 | STRUCT WMButtonAction &ba |
---|
2366 | |
---|
2367 | switch( ba.eventCode ) |
---|
2368 | case 2: // mouse up |
---|
2369 | // click code here |
---|
2370 | Variable/G root:myGlobals:TransHeaderInfo:GuessOK= 2 |
---|
2371 | DoWindow/K ConfirmGuess |
---|
2372 | //Print "Try Again" |
---|
2373 | break |
---|
2374 | endswitch |
---|
2375 | |
---|
2376 | return 0 |
---|
2377 | End |
---|
2378 | |
---|
2379 | // not used |
---|
2380 | Function DoCancelGuessButtonProc(ba) : ButtonControl |
---|
2381 | STRUCT WMButtonAction &ba |
---|
2382 | |
---|
2383 | switch( ba.eventCode ) |
---|
2384 | case 2: // mouse up |
---|
2385 | // click code here |
---|
2386 | //just kill the panel, don't do anything |
---|
2387 | Variable/G root:myGlobals:TransHeaderInfo:GuessOK= 0 |
---|
2388 | DoWindow/K ConfirmGuess |
---|
2389 | break |
---|
2390 | endswitch |
---|
2391 | |
---|
2392 | return 0 |
---|
2393 | End |
---|
2394 | |
---|
2395 | Function GuessAllTransFiles(numChars) |
---|
2396 | Variable numChars |
---|
2397 | |
---|
2398 | if(WinType("ScatterFileTable") ==0 ) |
---|
2399 | return(1) |
---|
2400 | endif |
---|
2401 | |
---|
2402 | Wave/T sw = root:myGlobals:TransHeaderInfo:S_Labels //Sample file labels |
---|
2403 | Variable ii,num=numpnts(sw) |
---|
2404 | |
---|
2405 | for(ii=0;ii<num;ii+=1) |
---|
2406 | GuessTransFile(numChars,ii) |
---|
2407 | endfor |
---|
2408 | |
---|
2409 | return(0) |
---|
2410 | End |
---|
2411 | |
---|
2412 | Function fGuessSelectedTransFiles(numChars) |
---|
2413 | Variable numChars |
---|
2414 | |
---|
2415 | Variable ii |
---|
2416 | Variable scatterTableExists |
---|
2417 | scatterTableExists = WinType("ScatterFileTable") |
---|
2418 | if (scatterTableExists != 0) |
---|
2419 | GetSelection table,ScatterFileTable,1 |
---|
2420 | for(ii=V_StartRow;ii<=V_EndRow;ii+=1) |
---|
2421 | GuessTransFile(numChars,ii) |
---|
2422 | endfor |
---|
2423 | else |
---|
2424 | Print "Transmission->Scattering File table is not open" |
---|
2425 | endif |
---|
2426 | return(0) |
---|
2427 | End |
---|
2428 | |
---|
2429 | Function ClearSelectedAssignments() |
---|
2430 | |
---|
2431 | // String winStr = WinList("*", ";", "WIN:" ) //returns the target window |
---|
2432 | // Variable scatterTableExists, transTableExists |
---|
2433 | // Print winStr |
---|
2434 | // scatterTableExists = cmpstr(winStr,"ScatterFileTable;") |
---|
2435 | // if (scatterTableExists == 0) |
---|
2436 | // GetSelection table,ScatterFileTable,1 |
---|
2437 | // fClearSelectedAssignments(V_startRow,V_endRow,1) |
---|
2438 | // endif |
---|
2439 | // |
---|
2440 | // transTableExists = cmpstr(winStr,"TransFileTable;") |
---|
2441 | // if (transTableExists == 0) |
---|
2442 | // GetSelection table,TransFileTable,1 |
---|
2443 | // fClearSelectedAssignments(V_startRow,V_endRow,2) |
---|
2444 | // endif |
---|
2445 | |
---|
2446 | // return(0) |
---|
2447 | End |
---|