1 | #pragma rtGlobals=1 // Use modern global access method. |
---|
2 | #pragma version=5.0 |
---|
3 | #pragma IgorVersion=6.0 |
---|
4 | |
---|
5 | // this file contains globals and functions that are specific to a |
---|
6 | // particular facility or data file format |
---|
7 | // branched out 29MAR07 - SRK |
---|
8 | // |
---|
9 | // functions are either labeled with the procedure file that calls them, |
---|
10 | // or noted that they are local to this file |
---|
11 | |
---|
12 | |
---|
13 | // initializes globals that are specific to a particular facility |
---|
14 | // - number of XY pixels |
---|
15 | // - pixexl resolution [cm] |
---|
16 | // - detector deadtime constant [s] |
---|
17 | // |
---|
18 | // called by Initialize.ipf |
---|
19 | // |
---|
20 | Function InitFacilityGlobals() |
---|
21 | |
---|
22 | //Detector -specific globals |
---|
23 | Variable/G root:myGlobals:gNPixelsX=128 |
---|
24 | Variable/G root:myGlobals:gNPixelsY=128 |
---|
25 | |
---|
26 | // as of Jan2008, detector pixel sizes are read directly from the file header, so they MUST |
---|
27 | // be set correctly in instr.cfg |
---|
28 | Variable/G root:myGlobals:PixelResNG3_ILL = 1.0 //pixel resolution in cm |
---|
29 | Variable/G root:myGlobals:PixelResNG5_ILL = 1.0 |
---|
30 | Variable/G root:myGlobals:PixelResNG7_ILL = 1.0 |
---|
31 | Variable/G root:myGlobals:PixelResNG3_ORNL = 0.5 |
---|
32 | Variable/G root:myGlobals:PixelResNG5_ORNL = 0.5 |
---|
33 | Variable/G root:myGlobals:PixelResNG7_ORNL = 0.5 |
---|
34 | Variable/G root:myGlobals:PixelResDefault = 0.5 |
---|
35 | |
---|
36 | Variable/G root:myGlobals:DeadtimeNG3_ILL = 3.0e-6 //deadtime in seconds |
---|
37 | Variable/G root:myGlobals:DeadtimeNG5_ILL = 3.0e-6 |
---|
38 | Variable/G root:myGlobals:DeadtimeNG7_ILL = 3.0e-6 |
---|
39 | Variable/G root:myGlobals:DeadtimeNG3_ORNL = 3.4e-6 |
---|
40 | Variable/G root:myGlobals:DeadtimeNG5_ORNL = 0.6e-6 //as of 9 MAY 2002 |
---|
41 | Variable/G root:myGlobals:DeadtimeNG7_ORNL = 3.4e-6 |
---|
42 | Variable/G root:myGlobals:DeadtimeDefault = 3.4e-6 |
---|
43 | |
---|
44 | //new 11APR07 |
---|
45 | Variable/G root:myGlobals:BeamstopXTol = -8 // (cm) is BS Xpos is -5 cm or less, it's a trans measurement |
---|
46 | // sample aperture offset is NOT stored in the VAX header, but it should be |
---|
47 | // - when it is, remove the global and write an accessor AND make a place for |
---|
48 | // it in the RealsRead |
---|
49 | Variable/G root:myGlobals:apOff = 5.0 // (cm) distance from sample aperture to sample position |
---|
50 | |
---|
51 | End |
---|
52 | |
---|
53 | |
---|
54 | //********************** |
---|
55 | // Resolution calculation - used by the averaging routines |
---|
56 | // to calculate the resolution function at each q-value |
---|
57 | // - the return value is not used |
---|
58 | // |
---|
59 | // equivalent to John's routine on the VAX Q_SIGMA_AVE.FOR |
---|
60 | // Incorporates eqn. 3-15 from J. Appl. Cryst. (1995) v. 28 p105-114 |
---|
61 | // |
---|
62 | // - 21 MAR 07 uses projected BS diameter on the detector |
---|
63 | // - APR 07 still need to add resolution with lenses. currently there is no flag in the |
---|
64 | // raw data header to indicate the presence of lenses. |
---|
65 | // |
---|
66 | // - Aug 07 - added input to switch calculation based on lenses (==1 if in) |
---|
67 | // |
---|
68 | // - called by CircSectAvg.ipf and RectAnnulAvg.ipf |
---|
69 | // |
---|
70 | // passed values are read from RealsRead |
---|
71 | // except DDet and apOff, which are set from globals before passing |
---|
72 | // |
---|
73 | // |
---|
74 | Function/S getResolution(inQ,lambda,lambdaWidth,DDet,apOff,S1,S2,L1,L2,BS,del_r,usingLenses,SigmaQ,QBar,fSubS) |
---|
75 | Variable inQ, lambda, lambdaWidth, DDet, apOff, S1, S2, L1, L2, BS, del_r,usingLenses |
---|
76 | Variable &fSubS, &QBar, &SigmaQ //these are the output quantities at the input Q value |
---|
77 | |
---|
78 | //lots of calculation variables |
---|
79 | Variable a2, q_small, lp, v_lambda, v_b, v_d, vz, yg, v_g |
---|
80 | Variable r0, delta, inc_gamma, fr, fv, rmd, v_r1, rm, v_r |
---|
81 | |
---|
82 | //Constants |
---|
83 | Variable vz_1 = 3.956e5 //velocity [cm/s] of 1 A neutron |
---|
84 | Variable g = 981.0 //gravity acceleration [cm/s^2] |
---|
85 | |
---|
86 | String results |
---|
87 | results ="Failure" |
---|
88 | |
---|
89 | S1 *= 0.5*0.1 //convert to radius and [cm] |
---|
90 | S2 *= 0.5*0.1 |
---|
91 | |
---|
92 | L1 *= 100.0 // [cm] |
---|
93 | L1 -= apOff //correct the distance |
---|
94 | |
---|
95 | L2 *= 100.0 |
---|
96 | L2 += apOff |
---|
97 | del_r *= 0.1 //width of annulus, convert mm to [cm] |
---|
98 | |
---|
99 | BS *= 0.5*0.1 //nominal BS diameter passed in, convert to radius and [cm] |
---|
100 | // 21 MAR 07 SRK - use the projected BS diameter, based on a point sample aperture |
---|
101 | Variable LB |
---|
102 | LB = 20.1 + 1.61*BS //distance in cm from beamstop to anode plane (empirical) |
---|
103 | BS = bs + bs*lb/(l2-lb) //adjusted diameter of shadow from parallax |
---|
104 | |
---|
105 | //Start resolution calculation |
---|
106 | a2 = S1*L2/L1 + S2*(L1+L2)/L1 |
---|
107 | q_small = 2.0*Pi*(BS-a2)*(1.0-lambdaWidth)/(lambda*L2) |
---|
108 | lp = 1.0/( 1.0/L1 + 1.0/L2) |
---|
109 | |
---|
110 | v_lambda = lambdaWidth^2/6.0 |
---|
111 | |
---|
112 | // if(usingLenses==1) //SRK 2007 |
---|
113 | if(usingLenses != 0) //SRK 2008 allows for the possibility of different numbers of lenses in header |
---|
114 | v_b = 0.25*(S1*L2/L1)^2 +0.25*(2/3)*(lambdaWidth/lambda)^2*(S2*L2/lp)^2 //correction to 2nd term |
---|
115 | else |
---|
116 | v_b = 0.25*(S1*L2/L1)^2 +0.25*(S2*L2/lp)^2 //original form |
---|
117 | endif |
---|
118 | |
---|
119 | v_d = (DDet/2.3548)^2 + del_r^2/12.0 |
---|
120 | vz = vz_1 / lambda |
---|
121 | yg = 0.5*g*L2*(L1+L2)/vz^2 |
---|
122 | v_g = 2.0*(2.0*yg^2*v_lambda) //factor of 2 correction, B. Hammouda, 2007 |
---|
123 | |
---|
124 | r0 = L2*tan(2.0*asin(lambda*inQ/(4.0*Pi) )) |
---|
125 | delta = 0.5*(BS - r0)^2/v_d |
---|
126 | |
---|
127 | if (r0 < BS) |
---|
128 | inc_gamma=exp(gammln(1.5))*(1-gammp(1.5,delta)) |
---|
129 | else |
---|
130 | inc_gamma=exp(gammln(1.5))*(1+gammp(1.5,delta)) |
---|
131 | endif |
---|
132 | |
---|
133 | fSubS = 0.5*(1.0+erf( (r0-BS)/sqrt(2.0*v_d) ) ) |
---|
134 | if (fSubS <= 0.0) |
---|
135 | fSubS = 1.e-10 |
---|
136 | endif |
---|
137 | fr = 1.0 + sqrt(v_d)*exp(-1.0*delta) /(r0*fSubS*sqrt(2.0*Pi)) |
---|
138 | fv = inc_gamma/(fSubS*sqrt(Pi)) - r0^2*(fr-1.0)^2/v_d |
---|
139 | |
---|
140 | rmd = fr*r0 |
---|
141 | v_r1 = v_b + fv*v_d +v_g |
---|
142 | |
---|
143 | rm = rmd + 0.5*v_r1/rmd |
---|
144 | v_r = v_r1 - 0.5*(v_r1/rmd)^2 |
---|
145 | if (v_r < 0.0) |
---|
146 | v_r = 0.0 |
---|
147 | endif |
---|
148 | QBar = (4.0*Pi/lambda)*sin(0.5*atan(rm/L2)) |
---|
149 | SigmaQ = QBar*sqrt(v_r/rmd^2 +v_lambda) |
---|
150 | |
---|
151 | results = "success" |
---|
152 | Return results |
---|
153 | End |
---|
154 | |
---|
155 | |
---|
156 | //Utility function that returns the detector resolution (in cm) |
---|
157 | //Global values are set in the Initialize procedure |
---|
158 | // |
---|
159 | // |
---|
160 | // - called by CircSectAvg.ipf, RectAnnulAvg.ipf, and ProtocolAsPanel.ipf |
---|
161 | // |
---|
162 | // fileStr is passed as TextRead[3] |
---|
163 | // detStr is passed as TextRead[9] |
---|
164 | // |
---|
165 | // *** as of Jan 2008, depricated. Now detector pixel sizes are read from the file header |
---|
166 | // rw[10] = x size (mm); rw[13] = y size (mm) |
---|
167 | // |
---|
168 | Function xDetectorPixelResolution(fileStr,detStr) |
---|
169 | String fileStr,detStr |
---|
170 | |
---|
171 | Variable DDet |
---|
172 | String instr=fileStr[1,3] //filestr is "[NGnSANSn] " or "[NGnSANSnn]" (11 characters total) |
---|
173 | |
---|
174 | NVAR PixelResNG3_ILL = root:myGlobals:PixelResNG3_ILL //pixel resolution in cm |
---|
175 | NVAR PixelResNG5_ILL = root:myGlobals:PixelResNG5_ILL |
---|
176 | NVAR PixelResNG7_ILL = root:myGlobals:PixelResNG7_ILL |
---|
177 | NVAR PixelResNG3_ORNL = root:myGlobals:PixelResNG3_ORNL |
---|
178 | NVAR PixelResNG5_ORNL = root:myGlobals:PixelResNG5_ORNL |
---|
179 | NVAR PixelResNG7_ORNL = root:myGlobals:PixelResNG7_ORNL |
---|
180 | NVAR PixelResDefault = root:myGlobals:PixelResDefault |
---|
181 | |
---|
182 | strswitch(instr) |
---|
183 | case "NG3": |
---|
184 | if(cmpstr(detStr, "ILL ") == 0 ) |
---|
185 | DDet= PixelResNG3_ILL |
---|
186 | else |
---|
187 | DDet = PixelResNG3_ORNL //detector is ordella-type |
---|
188 | endif |
---|
189 | break |
---|
190 | case "NG5": |
---|
191 | if(cmpstr(detStr, "ILL ") == 0 ) |
---|
192 | DDet= PixelResNG5_ILL |
---|
193 | else |
---|
194 | DDet = PixelResNG5_ORNL //detector is ordella-type |
---|
195 | endif |
---|
196 | break |
---|
197 | case "NG7": |
---|
198 | if(cmpstr(detStr, "ILL ") == 0 ) |
---|
199 | DDet= PixelResNG7_ILL |
---|
200 | else |
---|
201 | DDet = PixelResNG7_ORNL //detector is ordella-type |
---|
202 | endif |
---|
203 | break |
---|
204 | default: |
---|
205 | //return error? |
---|
206 | DDet = PixelResDefault //0.5 cm, typical for new ORNL detectors |
---|
207 | endswitch |
---|
208 | |
---|
209 | return(DDet) |
---|
210 | End |
---|
211 | |
---|
212 | //Utility function that returns the detector deadtime (in seconds) |
---|
213 | //Global values are set in the Initialize procedure |
---|
214 | // |
---|
215 | // - called by WorkFileUtils.ipf |
---|
216 | // |
---|
217 | // fileStr is passed as TextRead[3] |
---|
218 | // detStr is passed as TextRead[9] |
---|
219 | // |
---|
220 | Function DetectorDeadtime(fileStr,detStr) |
---|
221 | String fileStr,detStr |
---|
222 | |
---|
223 | Variable deadtime |
---|
224 | String instr=fileStr[1,3] //filestr is "[NGnSANSn] " or "[NGnSANSnn]" (11 characters total) |
---|
225 | |
---|
226 | NVAR DeadtimeNG3_ILL = root:myGlobals:DeadtimeNG3_ILL //pixel resolution in cm |
---|
227 | NVAR DeadtimeNG5_ILL = root:myGlobals:DeadtimeNG5_ILL |
---|
228 | NVAR DeadtimeNG7_ILL = root:myGlobals:DeadtimeNG7_ILL |
---|
229 | NVAR DeadtimeNG3_ORNL = root:myGlobals:DeadtimeNG3_ORNL |
---|
230 | NVAR DeadtimeNG5_ORNL = root:myGlobals:DeadtimeNG5_ORNL |
---|
231 | NVAR DeadtimeNG7_ORNL = root:myGlobals:DeadtimeNG7_ORNL |
---|
232 | NVAR DeadtimeDefault = root:myGlobals:DeadtimeDefault |
---|
233 | |
---|
234 | strswitch(instr) |
---|
235 | case "NG3": |
---|
236 | if(cmpstr(detStr, "ILL ") == 0 ) |
---|
237 | deadtime= DeadtimeNG3_ILL |
---|
238 | else |
---|
239 | deadtime = DeadtimeNG3_ORNL //detector is ordella-type |
---|
240 | endif |
---|
241 | break |
---|
242 | case "NG5": |
---|
243 | if(cmpstr(detStr, "ILL ") == 0 ) |
---|
244 | deadtime= DeadtimeNG5_ILL |
---|
245 | else |
---|
246 | deadtime = DeadtimeNG5_ORNL //detector is ordella-type |
---|
247 | endif |
---|
248 | break |
---|
249 | case "NG7": |
---|
250 | if(cmpstr(detStr, "ILL ") == 0 ) |
---|
251 | deadtime= DeadtimeNG7_ILL |
---|
252 | else |
---|
253 | deadtime = DeadtimeNG7_ORNL //detector is ordella-type |
---|
254 | endif |
---|
255 | break |
---|
256 | default: |
---|
257 | //return error? |
---|
258 | deadtime = DeadtimeDefault //1e-6 seconds, typical for new ORNL detectors |
---|
259 | endswitch |
---|
260 | |
---|
261 | return(deadtime) |
---|
262 | End |
---|
263 | |
---|
264 | |
---|
265 | /////VAX filename/Run number parsing utilities |
---|
266 | // |
---|
267 | // a collection of uilities for processing vax filenames |
---|
268 | //and processing lists (especially for display in popup menus) |
---|
269 | // |
---|
270 | //required to correctly account for VAX supplied version numbers, which |
---|
271 | //may or may not be removed by the ftp utility |
---|
272 | // |
---|
273 | // - parses lists of run numbers into real filenames |
---|
274 | // - selects proper detector constants |
---|
275 | // |
---|
276 | //************************** |
---|
277 | // |
---|
278 | //given a filename of a SANS data filename of the form |
---|
279 | //TTTTTnnn.SAn_TTT_Txxx |
---|
280 | //returns the run number "nnn" as a number |
---|
281 | //returns -1 as an invalid file number |
---|
282 | // |
---|
283 | // called by several ipfs |
---|
284 | // |
---|
285 | // |
---|
286 | Function GetRunNumFromFile(item) |
---|
287 | String item |
---|
288 | Variable invalid = -1 //negative numbers are invalid |
---|
289 | Variable num=-1 |
---|
290 | |
---|
291 | //find the "dot" |
---|
292 | String runStr="" |
---|
293 | Variable pos = strsearch(item,".",0) |
---|
294 | if(pos == -1) |
---|
295 | //"dot" not found |
---|
296 | return (invalid) |
---|
297 | else |
---|
298 | //found, get the three characters preceeding it |
---|
299 | if (pos <=2) |
---|
300 | //not enough characters |
---|
301 | return (invalid) |
---|
302 | else |
---|
303 | runStr = item[pos-3,pos-1] |
---|
304 | //convert to a number |
---|
305 | num = str2num(runStr) |
---|
306 | //if valid, return it |
---|
307 | if (num == NaN) |
---|
308 | //3 characters were not a number |
---|
309 | return (invalid) |
---|
310 | else |
---|
311 | //run was OK |
---|
312 | return (num) |
---|
313 | Endif |
---|
314 | Endif |
---|
315 | Endif |
---|
316 | End |
---|
317 | |
---|
318 | //given a filename of a SANS data filename of the form |
---|
319 | //TTTTTnnn.SAn_TTT_Txxx |
---|
320 | //returns the run number "nnn" as a STRING of THREE characters |
---|
321 | //returns "ABC" as an invalid file number |
---|
322 | // |
---|
323 | // local function to aid in locating files by run number |
---|
324 | // |
---|
325 | Function/S GetRunNumStrFromFile(item) |
---|
326 | String item |
---|
327 | String invalid = "ABC" //"ABC" is not a valid run number, since it's text |
---|
328 | Variable num=-1 |
---|
329 | |
---|
330 | //find the "dot" |
---|
331 | String runStr="" |
---|
332 | Variable pos = strsearch(item,".",0) |
---|
333 | if(pos == -1) |
---|
334 | //"dot" not found |
---|
335 | return (invalid) |
---|
336 | else |
---|
337 | //found, get the three characters preceeding it |
---|
338 | if (pos <=2) |
---|
339 | //not enough characters |
---|
340 | return (invalid) |
---|
341 | else |
---|
342 | runStr = item[pos-3,pos-1] |
---|
343 | return (runStr) |
---|
344 | Endif |
---|
345 | Endif |
---|
346 | End |
---|
347 | |
---|
348 | //returns a string containing the full path to the file containing the |
---|
349 | //run number "num". The null string is returned if no valid file can be found |
---|
350 | //the path "catPathName" used and is hard-wired, will abort if this path does not exist |
---|
351 | //the file returned will be a RAW SANS data file, other types of files are |
---|
352 | //filtered out. |
---|
353 | // |
---|
354 | // called by Buttons.ipf and Transmission.ipf, and locally by parsing routines |
---|
355 | // |
---|
356 | Function/S FindFileFromRunNumber(num) |
---|
357 | Variable num |
---|
358 | |
---|
359 | String fullName="",partialName="",item="" |
---|
360 | //get list of raw data files in folder that match "num" (add leading zeros) |
---|
361 | if( (num>999) || (num<=0) ) |
---|
362 | //Print "error in FindFileFromRunNumber(num), file number too large or too small" |
---|
363 | Return ("") |
---|
364 | Endif |
---|
365 | //make a three character string of the run number |
---|
366 | String numStr="" |
---|
367 | if(num<10) |
---|
368 | numStr = "00"+num2str(num) |
---|
369 | else |
---|
370 | if(num<100) |
---|
371 | numStr = "0"+num2str(num) |
---|
372 | else |
---|
373 | numStr = num2str(num) |
---|
374 | Endif |
---|
375 | Endif |
---|
376 | //Print "numstr = ",numstr |
---|
377 | |
---|
378 | //make sure that path exists |
---|
379 | PathInfo catPathName |
---|
380 | String path = S_path |
---|
381 | if (V_flag == 0) |
---|
382 | Abort "folder path does not exist - use Pick Path button" |
---|
383 | Endif |
---|
384 | String list="",newList="",testStr="" |
---|
385 | |
---|
386 | list = IndexedFile(catPathName,-1,"????") //get all files in folder |
---|
387 | //find (the) one with the number in the run # location in the name |
---|
388 | Variable numItems,ii,runFound,isRAW |
---|
389 | numItems = ItemsInList(list,";") //get the new number of items in the list |
---|
390 | ii=0 |
---|
391 | do |
---|
392 | //parse through the list in this order: |
---|
393 | // 1 - does item contain run number (as a string) "TTTTTnnn.SAn_XXX_Tyyy" |
---|
394 | // 2 - exclude by isRaw? (to minimize disk access) |
---|
395 | item = StringFromList(ii, list ,";" ) |
---|
396 | if(strlen(item) != 0) |
---|
397 | //find the run number, if it exists as a three character string |
---|
398 | testStr = GetRunNumStrFromFile(item) |
---|
399 | runFound= cmpstr(numStr,testStr) //compare the three character strings, 0 if equal |
---|
400 | if(runFound == 0) |
---|
401 | //the run Number was found |
---|
402 | //build valid filename |
---|
403 | partialName = FindValidFileName(item) |
---|
404 | if(strlen(partialName) != 0) //non-null return from FindValidFileName() |
---|
405 | fullName = path + partialName |
---|
406 | //check if RAW, if so,this must be the file! |
---|
407 | isRAW = CheckIfRawData(fullName) |
---|
408 | if(isRaw) |
---|
409 | //stop here |
---|
410 | return(fullname) |
---|
411 | Endif |
---|
412 | Endif |
---|
413 | Endif |
---|
414 | Endif |
---|
415 | ii+=1 |
---|
416 | while(ii<numItems) //process all items in list |
---|
417 | Return ("") //null return if file not found in list |
---|
418 | End |
---|
419 | |
---|
420 | //function to test a binary file to see if it is a RAW binary SANS file |
---|
421 | //first checks the total bytes in the file (which for raw data is 33316 bytes) |
---|
422 | //**note that the "DIV" file will also show up as a raw file by the run field |
---|
423 | //should be listed in CAT/SHORT and in patch windows |
---|
424 | // |
---|
425 | //Function then checks the file fname (full path:file) for "RAW" run.type field |
---|
426 | //if not found, the data is not raw data and zero is returned |
---|
427 | // |
---|
428 | // called by many procedures (both external and local) |
---|
429 | // |
---|
430 | Function CheckIfRawData(fname) |
---|
431 | String fname |
---|
432 | |
---|
433 | Variable refnum,totalBytes |
---|
434 | String testStr="" |
---|
435 | |
---|
436 | Open/R/T="????TEXT" refNum as fname |
---|
437 | //get the total number of bytes in the file |
---|
438 | FStatus refNum |
---|
439 | totalBytes = V_logEOF |
---|
440 | //Print totalBytes |
---|
441 | FSetPos refNum,75 |
---|
442 | FReadLine/N=3 refNum,testStr |
---|
443 | Close refNum |
---|
444 | |
---|
445 | if(totalBytes == 33316 && cmpstr(testStr,"RAW")==0) |
---|
446 | //true, is raw data file |
---|
447 | Return(1) |
---|
448 | else |
---|
449 | //some other file |
---|
450 | Return(0) |
---|
451 | Endif |
---|
452 | End |
---|
453 | |
---|
454 | //function to check the header of a raw data file (full path specified by fname) |
---|
455 | //checks the field of the x-position of the beamstop during data collection |
---|
456 | //if the x-position is more negative (farther to the left) than xTol(input) |
---|
457 | //the the beamstop is "out" and the file is a transmission run and not a scattering run |
---|
458 | //xtol typically set at -5 (cm) - trans runs have bs(x) at -10 to -15 cm |
---|
459 | // function returns 1 if beamstop is out, 0 if beamstop is in |
---|
460 | // |
---|
461 | // tolerance is set as a global value "root:myGlobals:BeamstopXTol" |
---|
462 | // |
---|
463 | // called by Transmission.ipf, CatVSTable.ipf, NSORT.ipf |
---|
464 | // |
---|
465 | Function isTransFile(fName) |
---|
466 | String fname |
---|
467 | |
---|
468 | Variable refnum,xpos |
---|
469 | NVAR xTol = root:myGlobals:BeamstopXTol |
---|
470 | |
---|
471 | //pos = 369, read one real value |
---|
472 | |
---|
473 | SetDataFolder root: |
---|
474 | String GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=2/W=1/Q" |
---|
475 | String strToExecute="" |
---|
476 | // 1 R*4 value |
---|
477 | strToExecute = GBLoadStr + "/S=368/U=1" + "\"" + fname + "\"" |
---|
478 | Execute strToExecute |
---|
479 | Wave w=$"root:tempGBWave0" |
---|
480 | xPos = w[0] |
---|
481 | KillWaves/Z w |
---|
482 | //Print "xPos = ",xpos |
---|
483 | |
---|
484 | if(xpos<=xTol) |
---|
485 | //xpos is farther left (more negative) than xtol (currently -5 cm) |
---|
486 | Return(1) |
---|
487 | else |
---|
488 | //some other file |
---|
489 | Return(0) |
---|
490 | Endif |
---|
491 | End |
---|
492 | |
---|
493 | |
---|
494 | //function to remove all spaces from names when searching for filenames |
---|
495 | //the filename (as saved) will never have interior spaces (TTTTTnnn_AB _Bnnn) |
---|
496 | //but the text field in the header WILL, if less than 3 characters were used for the |
---|
497 | //user's initials, and can have leading spaces if prefix was less than 5 characters |
---|
498 | // |
---|
499 | //returns a string identical to the original string, except with the interior spaces removed |
---|
500 | // |
---|
501 | // local function for file name manipulation |
---|
502 | // |
---|
503 | Function/S RemoveAllSpaces(str) |
---|
504 | String str |
---|
505 | |
---|
506 | String tempstr = str |
---|
507 | Variable ii,spc,len //should never be more than 2 or 3 trailing spaces in a filename |
---|
508 | ii=0 |
---|
509 | do |
---|
510 | len = strlen(tempStr) |
---|
511 | spc = strsearch(tempStr," ",0) //is the last character a space? |
---|
512 | if (spc == -1) |
---|
513 | break //no more spaces found, get out |
---|
514 | endif |
---|
515 | str = tempstr |
---|
516 | tempStr = str[0,(spc-1)] + str[(spc+1),(len-1)] //remove the space from the string |
---|
517 | While(1) //should never be more than 2 or 3 |
---|
518 | |
---|
519 | If(strlen(tempStr) < 1) |
---|
520 | tempStr = "" //be sure to return a null string if problem found |
---|
521 | Endif |
---|
522 | |
---|
523 | //Print strlen(tempstr) |
---|
524 | |
---|
525 | Return(tempStr) |
---|
526 | |
---|
527 | End |
---|
528 | |
---|
529 | |
---|
530 | //Function attempts to find valid filename from partial name by checking for |
---|
531 | // the existence of the file on disk. |
---|
532 | // - checks as is |
---|
533 | // - adds ";vers" for possible VAX files |
---|
534 | // - strips spaces |
---|
535 | // - permutations of upper/lowercase |
---|
536 | // |
---|
537 | // added 11/99 - uppercase and lowercase versions of the file are tried, if necessary |
---|
538 | // since from marquee, the filename field (textread[0]) must be used, and can be a mix of |
---|
539 | // upper/lowercase letters, while the filename on the server (should) be all caps |
---|
540 | // now makes repeated calls to ValidFileString() |
---|
541 | // |
---|
542 | // returns a valid filename (No path prepended) or a null string |
---|
543 | // |
---|
544 | // called by any functions, both external and local |
---|
545 | // |
---|
546 | Function/S FindValidFilename(partialName) |
---|
547 | String PartialName |
---|
548 | |
---|
549 | String retStr="" |
---|
550 | |
---|
551 | //try name with no changes - to allow for ABS files that have spaces in the names 12APR04 |
---|
552 | retStr = ValidFileString(partialName) |
---|
553 | if(cmpstr(retStr,"") !=0) |
---|
554 | //non-null return |
---|
555 | return(retStr) |
---|
556 | Endif |
---|
557 | |
---|
558 | //if the partial name is derived from the file header, there can be spaces at the beginning |
---|
559 | //or in the middle of the filename - depending on the prefix and initials used |
---|
560 | // |
---|
561 | //remove any leading spaces from the name before starting |
---|
562 | partialName = RemoveAllSpaces(partialName) |
---|
563 | |
---|
564 | //try name with no spaces |
---|
565 | retStr = ValidFileString(partialName) |
---|
566 | if(cmpstr(retStr,"") !=0) |
---|
567 | //non-null return |
---|
568 | return(retStr) |
---|
569 | Endif |
---|
570 | |
---|
571 | //try all UPPERCASE |
---|
572 | partialName = UpperStr(partialName) |
---|
573 | retStr = ValidFileString(partialName) |
---|
574 | if(cmpstr(retStr,"") !=0) |
---|
575 | //non-null return |
---|
576 | return(retStr) |
---|
577 | Endif |
---|
578 | |
---|
579 | //try all lowercase (ret null if failure) |
---|
580 | partialName = LowerStr(partialName) |
---|
581 | retStr = ValidFileString(partialName) |
---|
582 | if(cmpstr(retStr,"") !=0) |
---|
583 | //non-null return |
---|
584 | return(retStr) |
---|
585 | else |
---|
586 | return(retStr) |
---|
587 | Endif |
---|
588 | End |
---|
589 | |
---|
590 | // Function checks for the existence of a file |
---|
591 | // partialName;vers (to account for VAX filenaming conventions) |
---|
592 | // The partial name is tried first with no version number |
---|
593 | // |
---|
594 | // *** the PATH is hard-wired to catPathName (which is assumed to exist) |
---|
595 | // version numers up to ;10 are tried |
---|
596 | // only the "name;vers" is returned if successful. The path is not prepended |
---|
597 | // |
---|
598 | // local function |
---|
599 | // |
---|
600 | Function/S ValidFileString(partialName) |
---|
601 | String partialName |
---|
602 | |
---|
603 | String tempName = "",msg="" |
---|
604 | Variable ii,refnum |
---|
605 | |
---|
606 | ii=0 |
---|
607 | do |
---|
608 | if(ii==0) |
---|
609 | //first pass, try the partialName |
---|
610 | tempName = partialName |
---|
611 | Open/Z/R/T="????TEXT"/P=catPathName refnum tempName //Does open file (/Z flag) |
---|
612 | if(V_flag == 0) |
---|
613 | //file exists |
---|
614 | Close refnum //YES needed, |
---|
615 | break |
---|
616 | endif |
---|
617 | else |
---|
618 | tempName = partialName + ";" + num2str(ii) |
---|
619 | Open/Z/R/T="????TEXT"/P=catPathName refnum tempName |
---|
620 | if(V_flag == 0) |
---|
621 | //file exists |
---|
622 | Close refnum |
---|
623 | break |
---|
624 | endif |
---|
625 | Endif |
---|
626 | ii+=1 |
---|
627 | //print "ii=",ii |
---|
628 | while(ii<11) |
---|
629 | //go get the selected bits of information, using tempName, which exists |
---|
630 | if(ii>=11) |
---|
631 | //msg = partialName + " not found. is version number > 11?" |
---|
632 | //DoAlert 0, msg |
---|
633 | //PathInfo catPathName |
---|
634 | //Print S_Path |
---|
635 | Return ("") //use null string as error condition |
---|
636 | Endif |
---|
637 | |
---|
638 | Return (tempName) |
---|
639 | End |
---|
640 | |
---|
641 | //returns a string containing filename (WITHOUT the ;vers) |
---|
642 | //the input string is a full path to the file (Mac-style, still works on Win in IGOR) |
---|
643 | //with the folders separated by colons |
---|
644 | // |
---|
645 | // called by MaskUtils.ipf, ProtocolAsPanel.ipf, WriteQIS.ipf |
---|
646 | // |
---|
647 | Function/S GetFileNameFromPathNoSemi(fullPath) |
---|
648 | String fullPath |
---|
649 | |
---|
650 | Variable offset1,offset2 |
---|
651 | String filename="" |
---|
652 | //String PartialPath |
---|
653 | offset1 = 0 |
---|
654 | do |
---|
655 | offset2 = StrSearch(fullPath, ":", offset1) |
---|
656 | if (offset2 == -1) // no more colons ? |
---|
657 | fileName = FullPath[offset1,strlen(FullPath) ] |
---|
658 | //PartialPath = FullPath[0, offset1-1] |
---|
659 | break |
---|
660 | endif |
---|
661 | offset1 = offset2+1 |
---|
662 | while (1) |
---|
663 | |
---|
664 | //remove version number from name, if it's there - format should be: filename;N |
---|
665 | filename = StringFromList(0,filename,";") //returns null if error |
---|
666 | |
---|
667 | Return filename |
---|
668 | End |
---|
669 | |
---|
670 | //returns a string containing filename (INCLUDING the ;vers) |
---|
671 | //the input string is a full path to the file (Mac-style, still works on Win in IGOR) |
---|
672 | //with the folders separated by colons |
---|
673 | // |
---|
674 | // local, currently unused |
---|
675 | // |
---|
676 | Function/S GetFileNameFromPathKeepSemi(fullPath) |
---|
677 | String fullPath |
---|
678 | |
---|
679 | Variable offset1,offset2 |
---|
680 | String filename |
---|
681 | //String PartialPath |
---|
682 | offset1 = 0 |
---|
683 | do |
---|
684 | offset2 = StrSearch(fullPath, ":", offset1) |
---|
685 | if (offset2 == -1) // no more colons ? |
---|
686 | fileName = FullPath[offset1,strlen(FullPath) ] |
---|
687 | //PartialPath = FullPath[0, offset1-1] |
---|
688 | break |
---|
689 | endif |
---|
690 | offset1 = offset2+1 |
---|
691 | while (1) |
---|
692 | |
---|
693 | //keep version number from name, if it's there - format should be: filename;N |
---|
694 | |
---|
695 | Return filename |
---|
696 | End |
---|
697 | |
---|
698 | //given the full path and filename (fullPath), strips the data path |
---|
699 | //(Mac-style, separated by colons) and returns this path |
---|
700 | //this partial path is the same string that would be returned from PathInfo, for example |
---|
701 | // |
---|
702 | // - allows the user to save to a different path than catPathName |
---|
703 | // |
---|
704 | // called by WriteQIS.ipf |
---|
705 | // |
---|
706 | Function/S GetPathStrFromfullName(fullPath) |
---|
707 | String fullPath |
---|
708 | |
---|
709 | Variable offset1,offset2 |
---|
710 | //String filename |
---|
711 | String PartialPath |
---|
712 | offset1 = 0 |
---|
713 | do |
---|
714 | offset2 = StrSearch(fullPath, ":", offset1) |
---|
715 | if (offset2 == -1) // no more colons ? |
---|
716 | //fileName = FullPath[offset1,strlen(FullPath) ] |
---|
717 | PartialPath = FullPath[0, offset1-1] |
---|
718 | break |
---|
719 | endif |
---|
720 | offset1 = offset2+1 |
---|
721 | while (1) |
---|
722 | |
---|
723 | Return PartialPath |
---|
724 | End |
---|
725 | |
---|
726 | //given the VAX filename, pull off the first 8 characters to make a valid |
---|
727 | //file string that can be used for naming averaged 1-d files |
---|
728 | // |
---|
729 | // called by ProtocolAsPanel.ipf and Tile_2D.ipf |
---|
730 | // |
---|
731 | Function/S GetNameFromHeader(fullName) |
---|
732 | String fullName |
---|
733 | String temp, newName = "" |
---|
734 | Variable spc,ii=0 |
---|
735 | |
---|
736 | //filename is 20 characters NNNNNxxx.SAn_NNN_NNN |
---|
737 | //want the first 8 characters, NNNNNxxx, then strip off any spaces at the beginning |
---|
738 | //NNNNN was entered as less than 5 characters |
---|
739 | //returns a null string if no name can be found |
---|
740 | do |
---|
741 | temp = fullname[ii,7] //characters ii,7 of the name |
---|
742 | spc = strsearch(temp," ",0) |
---|
743 | if (spc == -1) |
---|
744 | break //no more spaces found |
---|
745 | endif |
---|
746 | ii+=1 |
---|
747 | While(ii<8) |
---|
748 | |
---|
749 | If(strlen(temp) < 1) |
---|
750 | newName = "" //be sure to return a null string if problem found |
---|
751 | else |
---|
752 | newName = temp |
---|
753 | Endif |
---|
754 | |
---|
755 | Return(newName) |
---|
756 | End |
---|
757 | |
---|
758 | //list (input) is a list, typically returned from IndexedFile() |
---|
759 | //which is semicolon-delimited, and may contain filenames from the VAX |
---|
760 | //that contain version numbers, where the version number appears as a separate list item |
---|
761 | //(and also as a non-existent file) |
---|
762 | //these numbers must be purged from the list, especially for display in a popup |
---|
763 | //or list processing of filenames |
---|
764 | //the function returns the list, cleaned of version numbers (up to 11) |
---|
765 | //raw data files will typically never have a version number other than 1. |
---|
766 | // |
---|
767 | // if there are no version numbers in the list, the input list is returned |
---|
768 | // |
---|
769 | // called by CatVSTable.ipf, NSORT.ipf, Transmission.ipf, WorkFileUtils.ipf |
---|
770 | // |
---|
771 | Function/S RemoveVersNumsFromList(list) |
---|
772 | String list |
---|
773 | |
---|
774 | //get rid of version numbers first (up to 11) |
---|
775 | Variable ii,num |
---|
776 | String item |
---|
777 | num = ItemsInList(list,";") |
---|
778 | ii=1 |
---|
779 | do |
---|
780 | item = num2str(ii) |
---|
781 | list = RemoveFromList(item, list ,";" ) |
---|
782 | ii+=1 |
---|
783 | while(ii<12) |
---|
784 | |
---|
785 | return (list) |
---|
786 | End |
---|
787 | |
---|
788 | //input is a list of run numbers, and output is a list of filenames (not the full path) |
---|
789 | //*** input list must be COMMA delimited*** |
---|
790 | //output is equivalent to selecting from the CAT table |
---|
791 | //if some or all of the list items are valid filenames, keep them... |
---|
792 | //if an error is encountered, notify of the offending element and return a null list |
---|
793 | // |
---|
794 | //output is COMMA delimited |
---|
795 | // |
---|
796 | // this routine is expecting that the "ask", "none" special cases are handled elsewhere |
---|
797 | //and not passed here |
---|
798 | // |
---|
799 | // called by Marquee.ipf, MultipleReduce.ipf, ProtocolAsPanel.ipf |
---|
800 | // |
---|
801 | Function/S ParseRunNumberList(list) |
---|
802 | String list |
---|
803 | |
---|
804 | String newList="",item="",tempStr="" |
---|
805 | Variable num,ii,runNum |
---|
806 | |
---|
807 | //expand number ranges, if any |
---|
808 | list = ExpandNumRanges(list) |
---|
809 | |
---|
810 | num=itemsinlist(list,",") |
---|
811 | |
---|
812 | for(ii=0;ii<num;ii+=1) |
---|
813 | //get the item |
---|
814 | item = StringFromList(ii,list,",") |
---|
815 | //is it already a valid filename? |
---|
816 | tempStr=FindValidFilename(item) //returns filename if good, null if error |
---|
817 | if(strlen(tempstr)!=0) |
---|
818 | //valid name, add to list |
---|
819 | //Print "it's a file" |
---|
820 | newList += tempStr + "," |
---|
821 | else |
---|
822 | //not a valid name |
---|
823 | //is it a number? |
---|
824 | runNum=str2num(item) |
---|
825 | //print runnum |
---|
826 | if(numtype(runNum) != 0) |
---|
827 | //not a number - maybe an error |
---|
828 | DoAlert 0,"List item "+item+" is not a valid run number or filename. Please enter a valid number or filename." |
---|
829 | return("") |
---|
830 | else |
---|
831 | //a run number or an error |
---|
832 | tempStr = GetFileNameFromPathNoSemi( FindFileFromRunNumber(runNum) ) |
---|
833 | if(strlen(tempstr)==0) |
---|
834 | //file not found, error |
---|
835 | DoAlert 0,"List item "+item+" is not a valid run number. Please enter a valid number." |
---|
836 | return("") |
---|
837 | else |
---|
838 | newList += tempStr + "," |
---|
839 | endif |
---|
840 | endif |
---|
841 | endif |
---|
842 | endfor //loop over all items in list |
---|
843 | |
---|
844 | return(newList) |
---|
845 | End |
---|
846 | |
---|
847 | //takes a comma delimited list that MAY contain number range, and |
---|
848 | //expands any range of run numbers into a comma-delimited list... |
---|
849 | //and returns the new list - if not a range, return unchanged |
---|
850 | // |
---|
851 | // local function |
---|
852 | // |
---|
853 | Function/S ExpandNumRanges(list) |
---|
854 | String list |
---|
855 | |
---|
856 | String newList="",dash="-",item,str |
---|
857 | Variable num,ii,hasDash |
---|
858 | |
---|
859 | num=itemsinlist(list,",") |
---|
860 | // print num |
---|
861 | for(ii=0;ii<num;ii+=1) |
---|
862 | //get the item |
---|
863 | item = StringFromList(ii,list,",") |
---|
864 | //does it contain a dash? |
---|
865 | hasDash = strsearch(item,dash,0) //-1 if no dash found |
---|
866 | if(hasDash == -1) |
---|
867 | //not a range, keep it in the list |
---|
868 | newList += item + "," |
---|
869 | else |
---|
870 | //has a dash (so it's a range), expand (or add null) |
---|
871 | newList += ListFromDash(item) |
---|
872 | endif |
---|
873 | endfor |
---|
874 | |
---|
875 | return newList |
---|
876 | End |
---|
877 | |
---|
878 | //be sure to add a trailing comma to the return string... |
---|
879 | // |
---|
880 | // local function |
---|
881 | // |
---|
882 | Function/S ListFromDash(item) |
---|
883 | String item |
---|
884 | |
---|
885 | String numList="",loStr="",hiStr="" |
---|
886 | Variable lo,hi,ii |
---|
887 | |
---|
888 | loStr=StringFromList(0,item,"-") //treat the range as a list |
---|
889 | hiStr=StringFromList(1,item,"-") |
---|
890 | lo=str2num(loStr) |
---|
891 | hi=str2num(hiStr) |
---|
892 | if( (numtype(lo) != 0) || (numtype(hi) !=0 ) || (lo > hi) ) |
---|
893 | numList="" |
---|
894 | return numList |
---|
895 | endif |
---|
896 | for(ii=lo;ii<=hi;ii+=1) |
---|
897 | numList += num2str(ii) + "," |
---|
898 | endfor |
---|
899 | |
---|
900 | Return numList |
---|
901 | End |
---|
902 | |
---|
903 | |
---|
904 | ////////Transmission |
---|
905 | //****************** |
---|
906 | //lookup tables for attenuator transmissions |
---|
907 | //NG3 and NG7 attenuators are physically different, so the transmissions are slightly different |
---|
908 | //NG1 - (8m SANS) is not supported |
---|
909 | // |
---|
910 | // new calibration done June 2007, John Barker |
---|
911 | // |
---|
912 | Proc MakeNG3AttenTable() |
---|
913 | |
---|
914 | NewDataFolder/O root:myGlobals:Attenuators |
---|
915 | //do explicitly to avoid data folder problems, redundant, but it must work without fail |
---|
916 | Variable num=10 //10 needed for tables after June 2007 |
---|
917 | |
---|
918 | Make/O/N=(num) root:myGlobals:Attenuators:ng3att0 |
---|
919 | Make/O/N=(num) root:myGlobals:Attenuators:ng3att1 |
---|
920 | Make/O/N=(num) root:myGlobals:Attenuators:ng3att2 |
---|
921 | Make/O/N=(num) root:myGlobals:Attenuators:ng3att3 |
---|
922 | Make/O/N=(num) root:myGlobals:Attenuators:ng3att4 |
---|
923 | Make/O/N=(num) root:myGlobals:Attenuators:ng3att5 |
---|
924 | Make/O/N=(num) root:myGlobals:Attenuators:ng3att6 |
---|
925 | Make/O/N=(num) root:myGlobals:Attenuators:ng3att7 |
---|
926 | Make/O/N=(num) root:myGlobals:Attenuators:ng3att8 |
---|
927 | Make/O/N=(num) root:myGlobals:Attenuators:ng3att9 |
---|
928 | Make/O/N=(num) root:myGlobals:Attenuators:ng3att10 |
---|
929 | |
---|
930 | //each wave has 10 elements, the transmission of att# at the wavelengths |
---|
931 | //lambda = 4,5,6,7,8,10,12,14,17,20 (4 A and 20 A are extrapolated values) |
---|
932 | Make/O/N=(num) root:myGlobals:Attenuators:ng3lambda={4,5,6,7,8,10,12,14,17,20} |
---|
933 | |
---|
934 | // new calibration done June 2007, John Barker |
---|
935 | root:myGlobals:Attenuators:ng3att0 = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } |
---|
936 | root:myGlobals:Attenuators:ng3att1 = {0.444784,0.419,0.3935,0.3682,0.3492,0.3132,0.2936,0.2767,0.2477,0.22404} |
---|
937 | root:myGlobals:Attenuators:ng3att2 = {0.207506,0.1848,0.1629,0.1447,0.1292,0.1056,0.09263,0.08171,0.06656,0.0546552} |
---|
938 | root:myGlobals:Attenuators:ng3att3 = {0.092412,0.07746,0.06422,0.05379,0.04512,0.03321,0.02707,0.02237,0.01643,0.0121969} |
---|
939 | root:myGlobals:Attenuators:ng3att4 = {0.0417722,0.03302,0.02567,0.02036,0.01604,0.01067,0.00812,0.006316,0.00419,0.00282411} |
---|
940 | root:myGlobals:Attenuators:ng3att5 = {0.0187129,0.01397,0.01017,0.007591,0.005668,0.003377,0.002423,0.001771,0.001064,0.000651257} |
---|
941 | root:myGlobals:Attenuators:ng3att6 = {0.00851048,0.005984,0.004104,0.002888,0.002029,0.001098,0.0007419,0.0005141,0.000272833,0.000150624} |
---|
942 | root:myGlobals:Attenuators:ng3att7 = {0.00170757,0.001084,0.0006469,0.0004142,0.0002607,0.0001201,7.664e-05,4.06624e-05,1.77379e-05,7.30624e-06} |
---|
943 | root:myGlobals:Attenuators:ng3att8 = {0.000320057,0.0001918,0.0001025,6.085e-05,3.681e-05,1.835e-05,6.74002e-06,3.25288e-06,1.15321e-06,3.98173e-07} |
---|
944 | root:myGlobals:Attenuators:ng3att9 = {6.27682e-05,3.69e-05,1.908e-05,1.196e-05,8.738e-06,6.996e-06,6.2901e-07,2.60221e-07,7.49748e-08,2.08029e-08} |
---|
945 | root:myGlobals:Attenuators:ng3att10 = {1.40323e-05,8.51e-06,5.161e-06,4.4e-06,4.273e-06,1.88799e-07,5.87021e-08,2.08169e-08,4.8744e-09,1.08687e-09} |
---|
946 | |
---|
947 | //old tables, pre-June 2007 |
---|
948 | // Make/O/N=9 root:myGlobals:Attenuators:ng3lambda={5,6,7,8,10,12,14,17,20} |
---|
949 | // root:myGlobals:Attenuators:ng3att0 = {1, 1, 1, 1, 1, 1, 1, 1,1 } |
---|
950 | // root:myGlobals:Attenuators:ng3att1 = {0.421, 0.394, 0.371, 0.349, 0.316, 0.293, 0.274, 0.245,0.220} |
---|
951 | // root:myGlobals:Attenuators:ng3att2 = {0.187, 0.164, 0.145, 0.130, 0.106, 0.0916, 0.0808, 0.0651,0.0531} |
---|
952 | // root:myGlobals:Attenuators:ng3att3 = {0.0777, 0.0636, 0.0534, 0.0446, 0.0330, 0.0262, 0.0217, 0.0157 ,0.0116} |
---|
953 | // root:myGlobals:Attenuators:ng3att4 = {0.0328, 0.0252, 0.0195, 0.0156, 0.0104, 7.68e-3, 5.98e-3, 3.91e-3,0.00262} |
---|
954 | // root:myGlobals:Attenuators:ng3att5 = {0.0139, 9.94e-3, 7.34e-3, 5.44e-3, 3.29e-3, 2.25e-3, 1.66e-3, 9.95e-4, 6.12e-4} |
---|
955 | // root:myGlobals:Attenuators:ng3att6 = {5.95e-3, 3.97e-3, 2.77e-3, 1.95e-3, 1.06e-3, 6.81e-4, 4.71e-4, 2.59e-4 , 1.45e-4} |
---|
956 | // root:myGlobals:Attenuators:ng3att7 = {1.07e-3, 6.24e-4, 3.90e-4, 2.44e-4, 1.14e-4, 6.55e-5, 4.10e-5, 1.64e-5 , 7.26e-6} |
---|
957 | // root:myGlobals:Attenuators:ng3att8 = {1.90e-4, 9.84e-5, 5.60e-5, 3.25e-5, 1.55e-5, 6.60e-6, 3.42e-6, 1.04e-6 , 3.48e-7} |
---|
958 | // root:myGlobals:Attenuators:ng3att9 = {3.61e-5, 1.74e-5, 9.90e-6, 6.45e-6, 2.35e-6, 6.35e-7, 2.86e-7, 6.61e-8 , 1.73e-8} |
---|
959 | // root:myGlobals:Attenuators:ng3att10 = {7.60e-6, 3.99e-6, 2.96e-6, 2.03e-6, 3.34e-7, 6.11e-8, 2.39e-8, 4.19e-9 , 8.60e-10} |
---|
960 | |
---|
961 | End |
---|
962 | |
---|
963 | // new calibration done June 2007, John Barker |
---|
964 | Proc MakeNG7AttenTable() |
---|
965 | |
---|
966 | NewDataFolder/O root:myGlobals:Attenuators |
---|
967 | |
---|
968 | Variable num=10 //10 needed for tables after June 2007 |
---|
969 | |
---|
970 | Make/O/N=(num) root:myGlobals:Attenuators:ng7att0 |
---|
971 | Make/O/N=(num) root:myGlobals:Attenuators:ng7att1 |
---|
972 | Make/O/N=(num) root:myGlobals:Attenuators:ng7att2 |
---|
973 | Make/O/N=(num) root:myGlobals:Attenuators:ng7att3 |
---|
974 | Make/O/N=(num) root:myGlobals:Attenuators:ng7att4 |
---|
975 | Make/O/N=(num) root:myGlobals:Attenuators:ng7att5 |
---|
976 | Make/O/N=(num) root:myGlobals:Attenuators:ng7att6 |
---|
977 | Make/O/N=(num) root:myGlobals:Attenuators:ng7att7 |
---|
978 | Make/O/N=(num) root:myGlobals:Attenuators:ng7att8 |
---|
979 | Make/O/N=(num) root:myGlobals:Attenuators:ng7att9 |
---|
980 | Make/O/N=(num) root:myGlobals:Attenuators:ng7att10 |
---|
981 | |
---|
982 | //NG7 wave has 10 elements, the transmission of att# at the wavelengths |
---|
983 | //lambda =4, 5,6,7,8,10,12,14,17,20 |
---|
984 | // note that some of the higher attenuations and ALL of the 4 A and 20A data is interpolated |
---|
985 | // none of these values are expected to be used in reality since the flux would be too low in practice |
---|
986 | Make/O/N=(num) root:myGlobals:Attenuators:ng7lambda={4,5,6,7,8,10,12,14,17,20} |
---|
987 | |
---|
988 | // New calibration, June 2007, John Barker |
---|
989 | root:myGlobals:Attenuators:ng7att0 = {1, 1, 1, 1, 1, 1, 1, 1 ,1,1} |
---|
990 | root:myGlobals:Attenuators:ng7att1 = {0.448656,0.4192,0.3925,0.3661,0.3458,0.3098,0.2922,0.2738,0.2544,0.251352} |
---|
991 | root:myGlobals:Attenuators:ng7att2 = {0.217193,0.1898,0.1682,0.148,0.1321,0.1076,0.0957,0.08485,0.07479,0.0735965} |
---|
992 | root:myGlobals:Attenuators:ng7att3 = {0.098019,0.07877,0.06611,0.05429,0.04548,0.03318,0.02798,0.0234,0.02004,0.0202492} |
---|
993 | root:myGlobals:Attenuators:ng7att4 = {0.0426904,0.03302,0.02617,0.02026,0.0158,0.01052,0.008327,0.006665,0.005745,0.00524807} |
---|
994 | root:myGlobals:Attenuators:ng7att5 = {0.0194353,0.01398,0.01037,0.0075496,0.005542,0.003339,0.002505,0.001936,0.001765,0.00165959} |
---|
995 | root:myGlobals:Attenuators:ng7att6 = {0.00971666,0.005979,0.004136,0.002848,0.001946,0.001079,0.0007717,0.000588,0.000487337,0.000447713} |
---|
996 | root:myGlobals:Attenuators:ng7att7 = {0.00207332,0.001054,0.0006462,0.0003957,0.0002368,0.0001111,7.642e-05,4.83076e-05,3.99401e-05,3.54814e-05} |
---|
997 | root:myGlobals:Attenuators:ng7att8 = {0.000397173,0.0001911,0.0001044,5.844e-05,3.236e-05,1.471e-05,6.88523e-06,4.06541e-06,3.27333e-06,2.81838e-06} |
---|
998 | root:myGlobals:Attenuators:ng7att9 = {9.43625e-05,3.557e-05,1.833e-05,1.014e-05,6.153e-06,1.64816e-06,6.42353e-07,3.42132e-07,2.68269e-07,2.2182e-07} |
---|
999 | root:myGlobals:Attenuators:ng7att10 = {2.1607e-05,7.521e-06,2.91221e-06,1.45252e-06,7.93451e-07,1.92309e-07,5.99279e-08,2.87928e-08,2.19862e-08,1.7559e-08} |
---|
1000 | |
---|
1001 | // Pre-June 2007 calibration values - do not use these anymore |
---|
1002 | //// root:myGlobals:Attenuators:ng7att0 = {1, 1, 1, 1, 1, 1, 1, 1 ,1} |
---|
1003 | //// root:myGlobals:Attenuators:ng7att1 = {0.418, 0.393, 0.369, 0.347, 0.313, 0.291, 0.271, 0.244, 0.219 } |
---|
1004 | //// root:myGlobals:Attenuators:ng7att2 = {0.189, 0.167, 0.148, 0.132, 0.109, 0.0945, 0.0830, 0.0681, 0.0560} |
---|
1005 | //// root:myGlobals:Attenuators:ng7att3 = {0.0784, 0.0651, 0.0541, 0.0456, 0.0340, 0.0273, 0.0223, 0.0164 , 0.0121} |
---|
1006 | //// root:myGlobals:Attenuators:ng7att4 = {0.0328, 0.0256, 0.0200, 0.0159, 0.0107, 7.98e-3, 6.14e-3, 4.09e-3 , 0.00274} |
---|
1007 | //// root:myGlobals:Attenuators:ng7att5 = {0.0139, 0.0101, 7.43e-3, 5.58e-3, 3.42e-3, 2.36e-3, 1.70e-3, 1.03e-3 , 6.27e-4} |
---|
1008 | //// root:myGlobals:Attenuators:ng7att6 = {5.90e-3, 4.07e-3, 2.79e-3, 1.99e-3, 1.11e-3, 7.13e-4, 4.91e-4, 2.59e-4 , 1.42e-4} |
---|
1009 | //// root:myGlobals:Attenuators:ng7att7 = {1.04e-3, 6.37e-4, 3.85e-4, 2.46e-4, 1.16e-4, 6.86e-5, 4.10e-5, 1.64e-5 ,7.02e-6} |
---|
1010 | //// root:myGlobals:Attenuators:ng7att8 = {1.90e-4, 1.03e-4, 5.71e-5, 3.44e-5, 1.65e-5, 6.60e-6, 3.42e-6, 1.04e-6 , 3.48e-7} |
---|
1011 | //// root:myGlobals:Attenuators:ng7att9 = {3.58e-5, 1.87e-5, 1.05e-5, 7.00e-6, 2.35e-6, 6.35e-7, 2.86e-7, 6.61e-8 , 1.73e-8} |
---|
1012 | //// root:myGlobals:Attenuators:ng7att10 = {7.76e-6, 4.56e-6, 3.25e-6, 2.03e-6, 3.34e-7, 6.11e-8, 2.39e-8, 4.19e-9, 8.60e-10} |
---|
1013 | End |
---|
1014 | |
---|
1015 | //returns the transmission of the attenuator (at NG3) given the attenuator number |
---|
1016 | //which must be an integer(to select the wave) and given the wavelength. |
---|
1017 | //the wavelength may be any value between 4 and 20 (A), and is interpolated |
---|
1018 | //between calibrated wavelengths for a given attenuator |
---|
1019 | // |
---|
1020 | // |
---|
1021 | Function LookupAttenNG3(lambda,attenNo) |
---|
1022 | Variable lambda, attenNo |
---|
1023 | |
---|
1024 | Variable trans |
---|
1025 | String attStr="root:myGlobals:Attenuators:ng3att"+num2str(trunc(attenNo)) |
---|
1026 | String lamStr = "root:myGlobals:Attenuators:ng3lambda" |
---|
1027 | |
---|
1028 | if(attenNo == 0) |
---|
1029 | return (1) //no attenuation, return trans == 1 |
---|
1030 | endif |
---|
1031 | |
---|
1032 | if( (lambda < 4) || (lambda > 20 ) ) |
---|
1033 | Abort "Wavelength out of calibration range (4,20). You must manually enter the absolute parameters" |
---|
1034 | Endif |
---|
1035 | |
---|
1036 | if(!(WaveExists($attStr)) || !(WaveExists($lamStr)) ) |
---|
1037 | Execute "MakeNG3AttenTable()" |
---|
1038 | Endif |
---|
1039 | //just in case creating the tables fails.... |
---|
1040 | if(!(WaveExists($attStr)) || !(WaveExists($lamStr)) ) |
---|
1041 | Abort "Attenuator lookup waves could not be found. You must manually enter the absolute parameters" |
---|
1042 | Endif |
---|
1043 | |
---|
1044 | //lookup the value by interpolating the wavelength |
---|
1045 | //the attenuator must always be an integer |
---|
1046 | Wave att = $attStr |
---|
1047 | Wave lam = $lamstr |
---|
1048 | trans = interp(lambda,lam,att) |
---|
1049 | |
---|
1050 | // Print "trans = ",trans |
---|
1051 | |
---|
1052 | return trans |
---|
1053 | End |
---|
1054 | |
---|
1055 | //returns the transmission of the attenuator (at NG7) given the attenuator number |
---|
1056 | //which must be an integer(to select the wave) and given the wavelength. |
---|
1057 | //the wavelength may be any value between 4 and 20 (A), and is interpolated |
---|
1058 | //between calibrated wavelengths for a given attenuator |
---|
1059 | // |
---|
1060 | // this set of tables is also used for NG5 (NG1) SANS instrument - as the attenuator has never been calibrated |
---|
1061 | // |
---|
1062 | // local function |
---|
1063 | // |
---|
1064 | Function LookupAttenNG7(lambda,attenNo) |
---|
1065 | Variable lambda, attenNo |
---|
1066 | |
---|
1067 | Variable trans |
---|
1068 | String attStr="root:myGlobals:Attenuators:ng7att"+num2str(trunc(attenNo)) |
---|
1069 | String lamStr = "root:myGlobals:Attenuators:ng7lambda" |
---|
1070 | |
---|
1071 | if(attenNo == 0) |
---|
1072 | return (1) //no attenuation, return trans == 1 |
---|
1073 | endif |
---|
1074 | |
---|
1075 | if( (lambda < 4) || (lambda > 20 ) ) |
---|
1076 | Abort "Wavelength out of calibration range (4,20). You must manually enter the absolute parameters" |
---|
1077 | Endif |
---|
1078 | |
---|
1079 | if(!(WaveExists($attStr)) || !(WaveExists($lamStr)) ) |
---|
1080 | Execute "MakeNG7AttenTable()" |
---|
1081 | Endif |
---|
1082 | //just in case creating the tables fails.... |
---|
1083 | if(!(WaveExists($attStr)) || !(WaveExists($lamStr)) ) |
---|
1084 | Abort "Attenuator lookup waves could not be found. You must manually enter the absolute parameters" |
---|
1085 | Endif |
---|
1086 | |
---|
1087 | //lookup the value by interpolating the wavelength |
---|
1088 | //the attenuator must always be an integer |
---|
1089 | Wave att = $attStr |
---|
1090 | Wave lam = $lamstr |
---|
1091 | trans = interp(lambda,lam,att) |
---|
1092 | |
---|
1093 | //Print "trans = ",trans |
---|
1094 | |
---|
1095 | return trans |
---|
1096 | |
---|
1097 | End |
---|
1098 | |
---|
1099 | //returns the proper attenuation factor based on the instrument (NG3, NG5, or NG7) |
---|
1100 | //NG5 values are taken from the NG7 tables (there is very little difference in the |
---|
1101 | //values, and NG5 attenuators have not been calibrated (as of 8/01) |
---|
1102 | // |
---|
1103 | // filestr is passed from TextRead[3] = the default directory |
---|
1104 | // lam is passed from RealsRead[26] |
---|
1105 | // AttenNo is passed from ReaslRead[3] |
---|
1106 | // |
---|
1107 | // Attenuation factor as defined here is <= 1 |
---|
1108 | // |
---|
1109 | // ORNL can pass ("",1,attenuationFactor) and have this function simply |
---|
1110 | // spit back the attenuationFactor (that was read into rw[3]) |
---|
1111 | // |
---|
1112 | // called by Correct.ipf, ProtocolAsPanel.ipf, Transmission.ipf |
---|
1113 | // |
---|
1114 | Function AttenuationFactor(fileStr,lam,attenNo) |
---|
1115 | String fileStr |
---|
1116 | Variable lam,attenNo |
---|
1117 | |
---|
1118 | Variable attenFactor=1,loc |
---|
1119 | String instr=fileStr[1,3] //filestr is "[NGnSANSn] " or "[NGnSANSnn]" (11 characters total) |
---|
1120 | |
---|
1121 | strswitch(instr) |
---|
1122 | case "NG3": |
---|
1123 | attenFactor = LookupAttenNG3(lam,attenNo) |
---|
1124 | break |
---|
1125 | case "NG5": |
---|
1126 | //using NG7 lookup Table |
---|
1127 | attenFactor = LookupAttenNG7(lam,attenNo) |
---|
1128 | break |
---|
1129 | case "NG7": |
---|
1130 | attenFactor = LookupAttenNG7(lam,attenNo) |
---|
1131 | break |
---|
1132 | default: |
---|
1133 | //return error? |
---|
1134 | attenFactor=1 |
---|
1135 | endswitch |
---|
1136 | // print "instr, lambda, attenNo,attenFactor = ",instr,lam,attenNo,attenFactor |
---|
1137 | return(attenFactor) |
---|
1138 | End |
---|
1139 | |
---|
1140 | //function called by the popups to get a file list of data that can be sorted |
---|
1141 | // this procedure simply removes the raw data files from the string - there |
---|
1142 | //can be lots of other junk present, but this is very fast... |
---|
1143 | // |
---|
1144 | // could also use the alternate procedure of keeping only file with the proper extension |
---|
1145 | // |
---|
1146 | // another possibility is to get a listing of the text files, but is unreliable on |
---|
1147 | // Windows, where the data file must be .txt (and possibly OSX) |
---|
1148 | // |
---|
1149 | // called by FIT_Ops.ipf, NSORT.ipf, PlotUtils.ipf |
---|
1150 | // |
---|
1151 | Function/S ReducedDataFileList(ctrlName) |
---|
1152 | String ctrlName |
---|
1153 | |
---|
1154 | String list="",newList="",item="" |
---|
1155 | Variable num,ii |
---|
1156 | |
---|
1157 | //check for the path |
---|
1158 | PathInfo catPathName |
---|
1159 | if(V_Flag==0) |
---|
1160 | DoAlert 0, "Data path does not exist - pick the data path from the button on the main panel" |
---|
1161 | Return("") |
---|
1162 | Endif |
---|
1163 | |
---|
1164 | list = IndexedFile(catpathName,-1,"????") |
---|
1165 | num=ItemsInList(list,";") |
---|
1166 | //print "num = ",num |
---|
1167 | for(ii=(num-1);ii>=0;ii-=1) |
---|
1168 | item = StringFromList(ii, list ,";") |
---|
1169 | //simply remove all that are not raw data files (SA1 SA2 SA3) |
---|
1170 | if( !stringmatch(item,"*.SA1*") && !stringmatch(item,"*.SA2*") && !stringmatch(item,"*.SA3*") ) |
---|
1171 | if( !stringmatch(item,".*") && !stringmatch(item,"*.pxp") && !stringmatch(item,"*.DIV")) //eliminate mac "hidden" files, pxp, and div files |
---|
1172 | newlist += item + ";" |
---|
1173 | endif |
---|
1174 | endif |
---|
1175 | endfor |
---|
1176 | //remove VAX version numbers |
---|
1177 | newList = RemoveVersNumsFromList(newList) |
---|
1178 | //sort |
---|
1179 | newList = SortList(newList,";",0) |
---|
1180 | |
---|
1181 | return newlist |
---|
1182 | End |
---|
1183 | |
---|
1184 | // returns a list of raw data files in the catPathName directory on disk |
---|
1185 | // - list is SEMICOLON-delimited |
---|
1186 | // |
---|
1187 | // does it the "cheap" way, simply finding the ".SAn" in the file name |
---|
1188 | // = does not check for proper byte length. |
---|
1189 | // |
---|
1190 | // called by PatchFiles.ipf, Tile_2D.ipf |
---|
1191 | // |
---|
1192 | Function/S GetRawDataFileList() |
---|
1193 | |
---|
1194 | //make sure that path exists |
---|
1195 | PathInfo catPathName |
---|
1196 | if (V_flag == 0) |
---|
1197 | Abort "Folder path does not exist - use Pick Path button on Main Panel" |
---|
1198 | Endif |
---|
1199 | |
---|
1200 | String list=IndexedFile(catPathName,-1,"????") |
---|
1201 | String newList="",item="" |
---|
1202 | Variable num=ItemsInList(list,";"),ii |
---|
1203 | for(ii=0;ii<num;ii+=1) |
---|
1204 | item = StringFromList(ii, list ,";") |
---|
1205 | if( stringmatch(item,"*.sa1*") ) |
---|
1206 | newlist += item + ";" |
---|
1207 | endif |
---|
1208 | if( stringmatch(item,"*.sa2*") ) |
---|
1209 | newlist += item + ";" |
---|
1210 | endif |
---|
1211 | if( stringmatch(item,"*.sa3*") ) |
---|
1212 | newlist += item + ";" |
---|
1213 | endif |
---|
1214 | //print "ii=",ii |
---|
1215 | endfor |
---|
1216 | newList = SortList(newList,";",0) |
---|
1217 | return(newList) |
---|
1218 | End |
---|