1 | #pragma rtGlobals=1 // Use modern global access method. |
---|
2 | #pragma version=5.0 |
---|
3 | #pragma IgorVersion=6.1 |
---|
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 // number of X and Y pixels |
---|
24 | Variable/G root:myGlobals:gNPixelsY=128 |
---|
25 | |
---|
26 | // pixel dimensions are now read directly from the file header. |
---|
27 | // Variable/G root:myGlobals:PixelResDefault = 0.5 //pixel resolution in cm |
---|
28 | |
---|
29 | Variable/G root:myGlobals:DeadtimeDefault = (0.9e-6 )/128 //deadtime in seconds |
---|
30 | |
---|
31 | Variable/G root:myGlobals:BeamstopYTol = 100 |
---|
32 | |
---|
33 | Variable/G root:myGlobals:apOff = 5.0 // (cm) distance from sample aperture to sample position |
---|
34 | |
---|
35 | // changing behavior specific to ILL correction of data |
---|
36 | Variable/G root:myGlobals:gDoDetectorEffCorr = 1 //default state is ==1 |
---|
37 | |
---|
38 | |
---|
39 | End |
---|
40 | |
---|
41 | |
---|
42 | //********************** |
---|
43 | // Resolution calculation - used by the averaging routines |
---|
44 | // to calculate the resolution function at each q-value |
---|
45 | // - the return value is not used |
---|
46 | // |
---|
47 | // equivalent to John's routine on the VAX Q_SIGMA_AVE.FOR |
---|
48 | // Incorporates eqn. 3-15 from J. Appl. Cryst. (1995) v. 28 p105-114 |
---|
49 | // |
---|
50 | // - 21 MAR 07 uses projected BS diameter on the detector |
---|
51 | // - APR 07 still need to add resolution with lenses. currently there is no flag in the |
---|
52 | // raw data header to indicate the presence of lenses. |
---|
53 | // |
---|
54 | // - Aug 07 - added input to switch calculation based on lenses (==1 if in) |
---|
55 | // |
---|
56 | // - called by CircSectAvg.ipf and RectAnnulAvg.ipf |
---|
57 | // |
---|
58 | // passed values are read from RealsRead |
---|
59 | // except DDet and apOff, which are set from globals before passing |
---|
60 | // |
---|
61 | // |
---|
62 | Function/S getResolution(inQ,lambda,lambdaWidth,DDet,apOff,S1,S2,L1,L2,BS,del_r,usingLenses,SigmaQ,QBar,fSubS) |
---|
63 | Variable inQ, lambda, lambdaWidth, DDet, apOff, S1, S2, L1, L2, BS, del_r,usingLenses |
---|
64 | Variable &fSubS, &QBar, &SigmaQ //these are the output quantities at the input Q value |
---|
65 | |
---|
66 | //lots of calculation variables |
---|
67 | Variable a2, q_small, lp, v_lambda, v_b, v_d, vz, yg, v_g |
---|
68 | Variable r0, delta, inc_gamma, fr, fv, rmd, v_r1, rm, v_r |
---|
69 | |
---|
70 | //Constants |
---|
71 | Variable vz_1 = 3.956e5 //velocity [cm/s] of 1 A neutron |
---|
72 | Variable g = 981.0 //gravity acceleration [cm/s^2] |
---|
73 | |
---|
74 | String results |
---|
75 | results ="Failure" |
---|
76 | |
---|
77 | S1 *= 0.5*0.1 //convert to radius and [cm] |
---|
78 | S2 *= 0.5*0.1 |
---|
79 | |
---|
80 | L1 *= 100.0 // [cm] |
---|
81 | L1 -= apOff //correct the distance |
---|
82 | |
---|
83 | L2 *= 100.0 |
---|
84 | L2 += apOff |
---|
85 | del_r *= 0.1 //width of annulus, convert mm to [cm] |
---|
86 | |
---|
87 | BS *= 0.5*0.1 //nominal BS diameter passed in, convert to radius and [cm] |
---|
88 | // 21 MAR 07 SRK - use the projected BS diameter, based on a point sample aperture |
---|
89 | Variable LB |
---|
90 | LB = 20.1 + 1.61*BS //distance in cm from beamstop to anode plane (empirical) |
---|
91 | BS = bs + bs*lb/(l2-lb) //adjusted diameter of shadow from parallax |
---|
92 | |
---|
93 | //Start resolution calculation |
---|
94 | a2 = S1*L2/L1 + S2*(L1+L2)/L1 |
---|
95 | q_small = 2.0*Pi*(BS-a2)*(1.0-lambdaWidth)/(lambda*L2) |
---|
96 | lp = 1.0/( 1.0/L1 + 1.0/L2) |
---|
97 | |
---|
98 | v_lambda = lambdaWidth^2/6.0 |
---|
99 | |
---|
100 | // if(usingLenses==1) //SRK 2007 |
---|
101 | if(usingLenses != 0) //SRK 2008 allows for the possibility of different numbers of lenses in header |
---|
102 | v_b = 0.25*(S1*L2/L1)^2 +0.25*(2/3)*(lambdaWidth/lambda)^2*(S2*L2/lp)^2 //correction to 2nd term |
---|
103 | else |
---|
104 | v_b = 0.25*(S1*L2/L1)^2 +0.25*(S2*L2/lp)^2 //original form |
---|
105 | endif |
---|
106 | |
---|
107 | v_d = (DDet/2.3548)^2 + del_r^2/12.0 |
---|
108 | vz = vz_1 / lambda |
---|
109 | yg = 0.5*g*L2*(L1+L2)/vz^2 |
---|
110 | v_g = 2.0*(2.0*yg^2*v_lambda) //factor of 2 correction, B. Hammouda, 2007 |
---|
111 | |
---|
112 | r0 = L2*tan(2.0*asin(lambda*inQ/(4.0*Pi) )) |
---|
113 | delta = 0.5*(BS - r0)^2/v_d |
---|
114 | |
---|
115 | if (r0 < BS) |
---|
116 | inc_gamma=exp(gammln(1.5))*(1-gammp(1.5,delta)) |
---|
117 | else |
---|
118 | inc_gamma=exp(gammln(1.5))*(1+gammp(1.5,delta)) |
---|
119 | endif |
---|
120 | |
---|
121 | fSubS = 0.5*(1.0+erf( (r0-BS)/sqrt(2.0*v_d) ) ) |
---|
122 | if (fSubS <= 0.0) |
---|
123 | fSubS = 1.e-10 |
---|
124 | endif |
---|
125 | fr = 1.0 + sqrt(v_d)*exp(-1.0*delta) /(r0*fSubS*sqrt(2.0*Pi)) |
---|
126 | fv = inc_gamma/(fSubS*sqrt(Pi)) - r0^2*(fr-1.0)^2/v_d |
---|
127 | |
---|
128 | rmd = fr*r0 |
---|
129 | v_r1 = v_b + fv*v_d +v_g |
---|
130 | |
---|
131 | rm = rmd + 0.5*v_r1/rmd |
---|
132 | v_r = v_r1 - 0.5*(v_r1/rmd)^2 |
---|
133 | if (v_r < 0.0) |
---|
134 | v_r = 0.0 |
---|
135 | endif |
---|
136 | QBar = (4.0*Pi/lambda)*sin(0.5*atan(rm/L2)) |
---|
137 | SigmaQ = QBar*sqrt(v_r/rmd^2 +v_lambda) |
---|
138 | |
---|
139 | results = "success" |
---|
140 | Return results |
---|
141 | End |
---|
142 | |
---|
143 | |
---|
144 | //Utility function that returns the detector resolution (in cm) |
---|
145 | //Global values are set in the Initialize procedure |
---|
146 | // |
---|
147 | // - called by CircSectAvg.ipf, RectAnnulAvg.ipf, and ProtocolAsPanel.ipf |
---|
148 | // |
---|
149 | // fileStr is passed as TextRead[3] |
---|
150 | // detStr is passed as TextRead[9] |
---|
151 | // |
---|
152 | // *** as of Jan 2008, depricated. Now detector pixel sizes are read from the file header |
---|
153 | // rw[10] = x size (mm); rw[13] = y size (mm) |
---|
154 | // |
---|
155 | // depricated - pixel dimensions are read directly from the file header |
---|
156 | Function xDetectorPixelResolution(fileStr,detStr) |
---|
157 | String fileStr,detStr |
---|
158 | |
---|
159 | Variable DDet |
---|
160 | |
---|
161 | //your code here |
---|
162 | // DDet= getRealValueFromHeader_2(fileStr,60,28,5,11,5) |
---|
163 | |
---|
164 | DDet = getRealValueFromHeader(filestr,55) |
---|
165 | |
---|
166 | return(DDet) |
---|
167 | End |
---|
168 | |
---|
169 | //Utility function that returns the detector deadtime (in seconds) |
---|
170 | //Global values are set in the Initialize procedure |
---|
171 | // |
---|
172 | // - called by WorkFileUtils.ipf |
---|
173 | // |
---|
174 | // fileStr is passed as TextRead[3] and is the filename |
---|
175 | // detStr is passed as TextRead[9] and is an identifier for the detector |
---|
176 | // |
---|
177 | Function DetectorDeadtime(fileStr,detStr) |
---|
178 | String fileStr,detStr |
---|
179 | |
---|
180 | Variable deadtime |
---|
181 | |
---|
182 | // your code here |
---|
183 | deadtime = (2e-6) |
---|
184 | |
---|
185 | return(deadtime) |
---|
186 | End |
---|
187 | |
---|
188 | |
---|
189 | // item is a filename |
---|
190 | // |
---|
191 | // this function extracts some sort of number from the file |
---|
192 | // presumably some sort of automatically incrementing run number set by the |
---|
193 | // acquisition system |
---|
194 | // |
---|
195 | // this run number should be a unique identifier for the file |
---|
196 | // |
---|
197 | |
---|
198 | // |
---|
199 | Function GetRunNumFromFile(item) |
---|
200 | String item |
---|
201 | |
---|
202 | Variable num=-1 // an invalid return value |
---|
203 | |
---|
204 | String runStr="" |
---|
205 | |
---|
206 | runStr = ParseFilePath(0, item, ":", 1, 0) |
---|
207 | // runstr = item |
---|
208 | num = str2num(runstr) |
---|
209 | |
---|
210 | |
---|
211 | //your code here |
---|
212 | |
---|
213 | return (num) |
---|
214 | End |
---|
215 | |
---|
216 | // item is a filename |
---|
217 | // |
---|
218 | // this function extracts some sort of number from the file |
---|
219 | // presumably some sort of automatically incrementing run number set by the |
---|
220 | // acquisition system |
---|
221 | // |
---|
222 | // this run number should be a unique identifier for the file |
---|
223 | // |
---|
224 | // same as GetRunNumFromFile(0), just with a string return |
---|
225 | // |
---|
226 | // "ABC" returned as an invalid result |
---|
227 | Function/S GetRunNumStrFromFile(item) |
---|
228 | String item |
---|
229 | |
---|
230 | String invalid = "ABC" //"ABC" is not a valid run number, since it's text |
---|
231 | String retStr |
---|
232 | retStr=invalid |
---|
233 | |
---|
234 | retstr = ParseFilePath(0, item, ":", 1, 0) |
---|
235 | //your code here |
---|
236 | |
---|
237 | |
---|
238 | |
---|
239 | return(retStr) |
---|
240 | End |
---|
241 | |
---|
242 | //returns a string containing the full path to the file containing the |
---|
243 | //run number "num". The null string is returned if no valid file can be found. |
---|
244 | // |
---|
245 | // |
---|
246 | // search in the path "catPathName" (hard-wired), will abort if this path does not exist |
---|
247 | //the file returned will be a RAW SANS data file, other types of files are |
---|
248 | //filtered out. |
---|
249 | // |
---|
250 | // called by Buttons.ipf and Transmission.ipf, and locally by parsing routines |
---|
251 | // |
---|
252 | Function/S FindFileFromRunNumber(num) |
---|
253 | Variable num |
---|
254 | |
---|
255 | String fullName="",partialName="",item="" |
---|
256 | String numStr="" |
---|
257 | |
---|
258 | numStr = num2str(num) |
---|
259 | // pad to 6 characters |
---|
260 | switch(strlen(numstr)) // numeric switch |
---|
261 | case 6: // execute if case matches expression |
---|
262 | break // exit from switch |
---|
263 | case 5: |
---|
264 | numStr = "0"+numStr |
---|
265 | break |
---|
266 | case 4: |
---|
267 | numStr = "00"+numStr |
---|
268 | break |
---|
269 | case 3: |
---|
270 | numStr = "000"+numStr |
---|
271 | break |
---|
272 | case 2: |
---|
273 | numStr = "0000"+numStr |
---|
274 | break |
---|
275 | case 1: |
---|
276 | numStr = "00000"+numStr |
---|
277 | break |
---|
278 | default: // optional default expression executed |
---|
279 | endswitch |
---|
280 | |
---|
281 | // Print "numstr = ",numstr |
---|
282 | |
---|
283 | //make sure that path exists |
---|
284 | PathInfo catPathName |
---|
285 | String path = S_path |
---|
286 | if (V_flag == 0) |
---|
287 | Abort "folder path does not exist - use Pick Path button" |
---|
288 | Endif |
---|
289 | |
---|
290 | String list="",newList="",testStr="" |
---|
291 | |
---|
292 | |
---|
293 | |
---|
294 | list = IndexedFile(catPathName,-1,"????") //get all files in folder |
---|
295 | //find (the) one with the number in the run # location in the name |
---|
296 | Variable numItems,ii,runFound,isRAW |
---|
297 | numItems = ItemsInList(list,";") //get the new number of items in the list |
---|
298 | ii=0 |
---|
299 | |
---|
300 | do |
---|
301 | //parse through the list in this order: |
---|
302 | // 1 - does item contain run number (as a string) "TTTTTnnn.SAn_XXX_Tyyy" |
---|
303 | // 2 - exclude by isRaw? (to minimize disk access) |
---|
304 | item = StringFromList(ii, list ,";" ) |
---|
305 | if(strlen(item) != 0) |
---|
306 | //find the run number, if it exists as a three character string |
---|
307 | testStr = GetRunNumStrFromFile(item) |
---|
308 | runFound = cmpstr(numStr,testStr) |
---|
309 | if(runFound == 0) |
---|
310 | partialName = FindValidFileName(item) |
---|
311 | if(strlen(partialName) != 0) //non-null return from FindValidFileName() |
---|
312 | fullName = path + partialName |
---|
313 | //check if RAW, if so,this must be the file! |
---|
314 | isRAW = CheckIfRawData(fullName) |
---|
315 | if(isRaw) |
---|
316 | //stop here |
---|
317 | //print fullname |
---|
318 | return(fullname) |
---|
319 | Endif |
---|
320 | Endif |
---|
321 | Endif |
---|
322 | Endif |
---|
323 | ii+=1 |
---|
324 | while(ii<numItems) //process all items in list |
---|
325 | Return ("") //null return if file not found in list |
---|
326 | |
---|
327 | //your code here |
---|
328 | |
---|
329 | End |
---|
330 | |
---|
331 | |
---|
332 | //make an (N) character string of the run number |
---|
333 | //Moved to facility utils |
---|
334 | // |
---|
335 | // same scheme to get 6-character string as in GetRunNumStrFromFile(item) |
---|
336 | // |
---|
337 | Function/S RunDigitString(num) |
---|
338 | Variable num |
---|
339 | |
---|
340 | // String fullName="",partialName="",item="" |
---|
341 | // String numStr="" |
---|
342 | // |
---|
343 | // numStr = num2istr(num) |
---|
344 | // // pad to 6 characters |
---|
345 | // switch(strlen(numstr)) // numeric switch |
---|
346 | // case 6: // execute if case matches expression |
---|
347 | // break // exit from switch |
---|
348 | // case 5: |
---|
349 | // numStr = "0"+numStr |
---|
350 | // break |
---|
351 | // case 4: |
---|
352 | // numStr = "00"+numStr |
---|
353 | // break |
---|
354 | // case 3: |
---|
355 | // numStr = "000"+numStr |
---|
356 | // break |
---|
357 | // case 2: |
---|
358 | // numStr = "0000"+numStr |
---|
359 | // break |
---|
360 | // case 1: |
---|
361 | // numStr = "00000"+numStr |
---|
362 | // break |
---|
363 | // default: // optional default expression executed |
---|
364 | // endswitch |
---|
365 | // |
---|
366 | |
---|
367 | String numStr="" |
---|
368 | |
---|
369 | //make 6 digit string from run number |
---|
370 | sprintf numStr,"%06u",num |
---|
371 | |
---|
372 | //Print "numstr = ",numstr |
---|
373 | if(strlen(numstr) > 6) |
---|
374 | return("") |
---|
375 | else |
---|
376 | return(numstr) |
---|
377 | endif |
---|
378 | |
---|
379 | End |
---|
380 | |
---|
381 | return(numstr) |
---|
382 | End |
---|
383 | |
---|
384 | // there is no prefix on D22 data files - they're just a run number |
---|
385 | // |
---|
386 | // so return null |
---|
387 | // |
---|
388 | // NCNR-specifc, does not really belong here - it's a beta procedure used for the |
---|
389 | // Combine Files Panel, and I'm not sure of how I'm really going to get this to work properly |
---|
390 | // since the .ABS file written is not of the form that NSORT->Set3NSORTFiles(low,med,hi,pref) |
---|
391 | // is trying to construct |
---|
392 | // |
---|
393 | Function/S GetPrefixStrFromFile(item) |
---|
394 | String item |
---|
395 | return("") |
---|
396 | End |
---|
397 | |
---|
398 | |
---|
399 | |
---|
400 | //function to test a file to see if it is a RAW SANS file |
---|
401 | // |
---|
402 | // returns truth 0/1 |
---|
403 | // |
---|
404 | // called by many procedures (both external and local) |
---|
405 | // |
---|
406 | Function CheckIfRawData(fname) |
---|
407 | String fname |
---|
408 | |
---|
409 | |
---|
410 | Variable refnum,totalBytes |
---|
411 | String testStr="" |
---|
412 | |
---|
413 | Open/R/T="????" refNum as fname |
---|
414 | //get the total number of bytes in the file |
---|
415 | FStatus refNum |
---|
416 | totalBytes = V_logEOF |
---|
417 | // Print totalBytes |
---|
418 | FSetPos refNum,75 |
---|
419 | FReadLine/N=3 refNum,testStr |
---|
420 | // print teststr |
---|
421 | Close refNum |
---|
422 | |
---|
423 | if(totalBytes == 142317 && cmpstr(testStr,"RRR")==0) |
---|
424 | //true, is raw data file |
---|
425 | |
---|
426 | // print "yes" |
---|
427 | Return(1) |
---|
428 | |
---|
429 | |
---|
430 | else |
---|
431 | //some other file |
---|
432 | |
---|
433 | // print "no" |
---|
434 | Return(0) |
---|
435 | Endif |
---|
436 | |
---|
437 | |
---|
438 | |
---|
439 | |
---|
440 | // if() |
---|
441 | // //true, is raw data file |
---|
442 | // Return(1) |
---|
443 | // else |
---|
444 | // //some other file |
---|
445 | // Return(0) |
---|
446 | // Endif |
---|
447 | |
---|
448 | End |
---|
449 | |
---|
450 | |
---|
451 | // function returns 1 if file is a transmission file, 0 if not |
---|
452 | // |
---|
453 | // called by Transmission.ipf, CatVSTable.ipf, NSORT.ipf |
---|
454 | // |
---|
455 | Function isTransFile(fName) |
---|
456 | String fname |
---|
457 | |
---|
458 | variable ypos |
---|
459 | NVAR yTol = root:myGlobals:BeamstopYTol |
---|
460 | |
---|
461 | ypos = getRealValueFromHeader(fname,15) |
---|
462 | |
---|
463 | // print ypos |
---|
464 | |
---|
465 | // print ytol |
---|
466 | |
---|
467 | if(abs(ypos)>=ytol) |
---|
468 | // //yes, its a transmisison file |
---|
469 | |
---|
470 | //print "yes" |
---|
471 | Return(1) |
---|
472 | else |
---|
473 | // //some other file |
---|
474 | |
---|
475 | //print "no" |
---|
476 | Return(0) |
---|
477 | Endif |
---|
478 | End |
---|
479 | |
---|
480 | |
---|
481 | //function to remove all spaces from names when searching for filenames |
---|
482 | //the filename (as saved) will never have interior spaces (TTTTTnnn_AB _Bnnn) |
---|
483 | //but the text field in the header may |
---|
484 | // |
---|
485 | //returns a string identical to the original string, except with the interior spaces removed |
---|
486 | // |
---|
487 | // local function for file name manipulation |
---|
488 | // |
---|
489 | // no change needed here |
---|
490 | Function/S RemoveAllSpaces(str) |
---|
491 | String str |
---|
492 | |
---|
493 | String tempstr = str |
---|
494 | Variable ii,spc,len //should never be more than 2 or 3 trailing spaces in a filename |
---|
495 | ii=0 |
---|
496 | do |
---|
497 | len = strlen(tempStr) |
---|
498 | spc = strsearch(tempStr," ",0) //is the last character a space? |
---|
499 | if (spc == -1) |
---|
500 | break //no more spaces found, get out |
---|
501 | endif |
---|
502 | str = tempstr |
---|
503 | tempStr = str[0,(spc-1)] + str[(spc+1),(len-1)] //remove the space from the string |
---|
504 | While(1) //should never be more than 2 or 3 |
---|
505 | |
---|
506 | If(strlen(tempStr) < 1) |
---|
507 | tempStr = "" //be sure to return a null string if problem found |
---|
508 | Endif |
---|
509 | |
---|
510 | //Print strlen(tempstr) |
---|
511 | |
---|
512 | Return(tempStr) |
---|
513 | |
---|
514 | End |
---|
515 | |
---|
516 | |
---|
517 | //Function attempts to find valid filename from partial name by checking for |
---|
518 | // the existence of the file on disk |
---|
519 | // |
---|
520 | // returns a valid filename (No path prepended) or a null string |
---|
521 | // |
---|
522 | // called by any functions, both external and local |
---|
523 | // |
---|
524 | Function/S FindValidFilename(partialName) |
---|
525 | String PartialName |
---|
526 | |
---|
527 | String retStr="" |
---|
528 | |
---|
529 | //your code here |
---|
530 | |
---|
531 | |
---|
532 | |
---|
533 | //try name with no changes - to allow for ABS files that have spaces in the names 12APR04 |
---|
534 | retStr = ValidFileString(partialName) |
---|
535 | if(cmpstr(retStr,"") !=0) |
---|
536 | //non-null return |
---|
537 | return(retStr) |
---|
538 | Endif |
---|
539 | |
---|
540 | //if the partial name is derived from the file header, there can be spaces at the beginning |
---|
541 | //or in the middle of the filename - depending on the prefix and initials used |
---|
542 | // |
---|
543 | //remove any leading spaces from the name before starting |
---|
544 | partialName = RemoveAllSpaces(partialName) |
---|
545 | |
---|
546 | //try name with no spaces |
---|
547 | retStr = ValidFileString(partialName) |
---|
548 | if(cmpstr(retStr,"") !=0) |
---|
549 | //non-null return |
---|
550 | return(retStr) |
---|
551 | Endif |
---|
552 | |
---|
553 | //try all UPPERCASE |
---|
554 | partialName = UpperStr(partialName) |
---|
555 | retStr = ValidFileString(partialName) |
---|
556 | if(cmpstr(retStr,"") !=0) |
---|
557 | //non-null return |
---|
558 | return(retStr) |
---|
559 | Endif |
---|
560 | |
---|
561 | //try all lowercase (ret null if failure) |
---|
562 | partialName = LowerStr(partialName) |
---|
563 | retStr = ValidFileString(partialName) |
---|
564 | if(cmpstr(retStr,"") !=0) |
---|
565 | //non-null return |
---|
566 | return(retStr) |
---|
567 | else |
---|
568 | return(retStr) |
---|
569 | Endif |
---|
570 | End |
---|
571 | |
---|
572 | // Function checks for the existence of a file |
---|
573 | // partialName;vers (to account for VAX filenaming conventions) |
---|
574 | // The partial name is tried first with no version number |
---|
575 | // |
---|
576 | // *** the PATH is hard-wired to catPathName (which is assumed to exist) |
---|
577 | // version numers up to ;10 are tried |
---|
578 | // only the "name;vers" is returned if successful. The path is not prepended |
---|
579 | // |
---|
580 | // local function |
---|
581 | // |
---|
582 | |
---|
583 | |
---|
584 | |
---|
585 | Function/S ValidFileString(partialName) |
---|
586 | String partialName |
---|
587 | |
---|
588 | String tempName = "",msg="" |
---|
589 | Variable ii,refnum |
---|
590 | |
---|
591 | ii=0 |
---|
592 | do |
---|
593 | if(ii==0) |
---|
594 | //first pass, try the partialName |
---|
595 | tempName = partialName |
---|
596 | Open/Z/R/T="????TEXT"/P=catPathName refnum tempName //Does open file (/Z flag) |
---|
597 | if(V_flag == 0) |
---|
598 | //file exists |
---|
599 | Close refnum //YES needed, |
---|
600 | break |
---|
601 | endif |
---|
602 | else |
---|
603 | tempName = partialName + ";" + num2str(ii) |
---|
604 | Open/Z/R/T="????TEXT"/P=catPathName refnum tempName |
---|
605 | if(V_flag == 0) |
---|
606 | //file exists |
---|
607 | Close refnum |
---|
608 | break |
---|
609 | endif |
---|
610 | Endif |
---|
611 | ii+=1 |
---|
612 | //print "ii=",ii |
---|
613 | while(ii<11) |
---|
614 | //go get the selected bits of information, using tempName, which exists |
---|
615 | if(ii>=11) |
---|
616 | //msg = partialName + " not found. is version number > 11?" |
---|
617 | //DoAlert 0, msg |
---|
618 | //PathInfo catPathName |
---|
619 | //Print S_Path |
---|
620 | Return ("") //use null string as error condition |
---|
621 | Endif |
---|
622 | |
---|
623 | Return (tempName) |
---|
624 | End |
---|
625 | |
---|
626 | |
---|
627 | |
---|
628 | |
---|
629 | //returns a string containing filename (WITHOUT the ;vers) |
---|
630 | //the input string is a full path to the file (Mac-style, still works on Win in IGOR) |
---|
631 | //with the folders separated by colons |
---|
632 | // |
---|
633 | // called by MaskUtils.ipf, ProtocolAsPanel.ipf, WriteQIS.ipf |
---|
634 | // |
---|
635 | // NEEDS NO CHANGES |
---|
636 | // |
---|
637 | Function/S GetFileNameFromPathNoSemi(fullPath) |
---|
638 | String fullPath |
---|
639 | |
---|
640 | Variable offset1,offset2 |
---|
641 | String filename="" |
---|
642 | //String PartialPath |
---|
643 | offset1 = 0 |
---|
644 | do |
---|
645 | offset2 = StrSearch(fullPath, ":", offset1) |
---|
646 | if (offset2 == -1) // no more colons ? |
---|
647 | fileName = FullPath[offset1,strlen(FullPath) ] |
---|
648 | //PartialPath = FullPath[0, offset1-1] |
---|
649 | break |
---|
650 | endif |
---|
651 | offset1 = offset2+1 |
---|
652 | while (1) |
---|
653 | |
---|
654 | //remove version number from name, if it's there - format should be: filename;N |
---|
655 | filename = StringFromList(0,filename,";") //returns null if error |
---|
656 | |
---|
657 | Return filename |
---|
658 | End |
---|
659 | |
---|
660 | //returns a string containing filename (INCLUDING the ;vers) |
---|
661 | //the input string is a full path to the file (Mac-style, still works on Win in IGOR) |
---|
662 | //with the folders separated by colons |
---|
663 | // |
---|
664 | // local, currently unused |
---|
665 | // |
---|
666 | // NEEDS NO CHANGES |
---|
667 | // |
---|
668 | Function/S GetFileNameFromPathKeepSemi(fullPath) |
---|
669 | String fullPath |
---|
670 | |
---|
671 | Variable offset1,offset2 |
---|
672 | String filename |
---|
673 | //String PartialPath |
---|
674 | offset1 = 0 |
---|
675 | do |
---|
676 | offset2 = StrSearch(fullPath, ":", offset1) |
---|
677 | if (offset2 == -1) // no more colons ? |
---|
678 | fileName = FullPath[offset1,strlen(FullPath) ] |
---|
679 | //PartialPath = FullPath[0, offset1-1] |
---|
680 | break |
---|
681 | endif |
---|
682 | offset1 = offset2+1 |
---|
683 | while (1) |
---|
684 | |
---|
685 | //keep version number from name, if it's there - format should be: filename;N |
---|
686 | |
---|
687 | Return filename |
---|
688 | End |
---|
689 | |
---|
690 | //given the full path and filename (fullPath), strips the data path |
---|
691 | //(Mac-style, separated by colons) and returns this path |
---|
692 | //this partial path is the same string that would be returned from PathInfo, for example |
---|
693 | // |
---|
694 | // - allows the user to save to a different path than catPathName |
---|
695 | // |
---|
696 | // called by WriteQIS.ipf |
---|
697 | // |
---|
698 | // NEEDS NO CHANGES |
---|
699 | // |
---|
700 | Function/S GetPathStrFromfullName(fullPath) |
---|
701 | String fullPath |
---|
702 | |
---|
703 | Variable offset1,offset2 |
---|
704 | //String filename |
---|
705 | String PartialPath |
---|
706 | offset1 = 0 |
---|
707 | do |
---|
708 | offset2 = StrSearch(fullPath, ":", offset1) |
---|
709 | if (offset2 == -1) // no more colons ? |
---|
710 | //fileName = FullPath[offset1,strlen(FullPath) ] |
---|
711 | PartialPath = FullPath[0, offset1-1] |
---|
712 | break |
---|
713 | endif |
---|
714 | offset1 = offset2+1 |
---|
715 | while (1) |
---|
716 | |
---|
717 | Return PartialPath |
---|
718 | End |
---|
719 | |
---|
720 | //given the filename trim or modify the filename to get a new |
---|
721 | //file string that can be used for naming averaged 1-d files |
---|
722 | // |
---|
723 | // called by ProtocolAsPanel.ipf and Tile_2D.ipf |
---|
724 | // |
---|
725 | Function/S GetNameFromHeader(fullName) |
---|
726 | String fullName |
---|
727 | String temp,newName = "" |
---|
728 | |
---|
729 | Variable spc,ii=0 |
---|
730 | |
---|
731 | //filename is 20 characters NNNNNxxx.SAn_NNN_NNN |
---|
732 | //want the first 8 characters, NNNNNxxx, then strip off any spaces at the beginning |
---|
733 | //NNNNN was entered as less than 5 characters |
---|
734 | //returns a null string if no name can be found |
---|
735 | do |
---|
736 | temp = fullname[ii,7] //characters ii,7 of the name |
---|
737 | spc = strsearch(temp," ",0) |
---|
738 | if (spc == -1) |
---|
739 | break //no more spaces found |
---|
740 | endif |
---|
741 | ii+=1 |
---|
742 | While(ii<8) |
---|
743 | |
---|
744 | If(strlen(temp) < 1) |
---|
745 | newName = "" //be sure to return a null string if problem found |
---|
746 | else |
---|
747 | newName = temp |
---|
748 | Endif |
---|
749 | |
---|
750 | // print newname |
---|
751 | //your code here |
---|
752 | |
---|
753 | Return(newName) |
---|
754 | End |
---|
755 | |
---|
756 | //list (input) is a list, typically returned from IndexedFile() |
---|
757 | //which is semicolon-delimited, and may contain filenames from the VAX |
---|
758 | //that contain version numbers, where the version number appears as a separate list item |
---|
759 | //(and also as a non-existent file) |
---|
760 | //these numbers must be purged from the list, especially for display in a popup |
---|
761 | //or list processing of filenames |
---|
762 | //the function returns the list, cleaned of version numbers (up to 11) |
---|
763 | //raw data files will typically never have a version number other than 1. |
---|
764 | // |
---|
765 | // if there are no version numbers in the list, the input list is returned |
---|
766 | // |
---|
767 | // called by CatVSTable.ipf, NSORT.ipf, Transmission.ipf, WorkFileUtils.ipf |
---|
768 | // |
---|
769 | // |
---|
770 | // NO CHANGE NEEDED |
---|
771 | // |
---|
772 | Function/S RemoveVersNumsFromList(list) |
---|
773 | String list |
---|
774 | |
---|
775 | //get rid of version numbers first (up to 11) |
---|
776 | Variable ii,num |
---|
777 | String item |
---|
778 | num = ItemsInList(list,";") |
---|
779 | ii=1 |
---|
780 | do |
---|
781 | item = num2str(ii) |
---|
782 | list = RemoveFromList(item, list ,";" ) |
---|
783 | ii+=1 |
---|
784 | while(ii<12) |
---|
785 | |
---|
786 | return (list) |
---|
787 | End |
---|
788 | |
---|
789 | //input is a list of run numbers, and output is a list of filenames (not the full path) |
---|
790 | //*** input list must be COMMA delimited*** |
---|
791 | //output is equivalent to selecting from the CAT table |
---|
792 | //if some or all of the list items are valid filenames, keep them... |
---|
793 | //if an error is encountered, notify of the offending element and return a null list |
---|
794 | // |
---|
795 | //output is COMMA delimited |
---|
796 | // |
---|
797 | // this routine is expecting that the "ask", "none" special cases are handled elsewhere |
---|
798 | //and not passed here |
---|
799 | // |
---|
800 | // called by Marquee.ipf, MultipleReduce.ipf, ProtocolAsPanel.ipf |
---|
801 | // |
---|
802 | // NO CHANGE NEEDED |
---|
803 | // |
---|
804 | Function/S ParseRunNumberList(list) |
---|
805 | String list |
---|
806 | |
---|
807 | String newList="",item="",tempStr="" |
---|
808 | Variable num,ii,runNum |
---|
809 | |
---|
810 | //expand number ranges, if any |
---|
811 | list = ExpandNumRanges(list) |
---|
812 | |
---|
813 | num=itemsinlist(list,",") |
---|
814 | |
---|
815 | for(ii=0;ii<num;ii+=1) |
---|
816 | //get the item |
---|
817 | item = StringFromList(ii,list,",") |
---|
818 | //is it already a valid filename? |
---|
819 | tempStr=FindValidFilename(item) //returns filename if good, null if error |
---|
820 | if(strlen(tempstr)!=0) |
---|
821 | //valid name, add to list |
---|
822 | //Print "it's a file" |
---|
823 | newList += tempStr + "," |
---|
824 | else |
---|
825 | //not a valid name |
---|
826 | //is it a number? |
---|
827 | runNum=str2num(item) |
---|
828 | //print runnum |
---|
829 | if(numtype(runNum) != 0) |
---|
830 | //not a number - maybe an error |
---|
831 | DoAlert 0,"List item "+item+" is not a valid run number or filename. Please enter a valid number or filename." |
---|
832 | return("") |
---|
833 | else |
---|
834 | //a run number or an error |
---|
835 | tempStr = GetFileNameFromPathNoSemi( FindFileFromRunNumber(runNum) ) |
---|
836 | if(strlen(tempstr)==0) |
---|
837 | //file not found, error |
---|
838 | DoAlert 0,"List item "+item+" is not a valid run number. Please enter a valid number." |
---|
839 | return("") |
---|
840 | else |
---|
841 | newList += tempStr + "," |
---|
842 | endif |
---|
843 | endif |
---|
844 | endif |
---|
845 | endfor //loop over all items in list |
---|
846 | |
---|
847 | return(newList) |
---|
848 | End |
---|
849 | |
---|
850 | //takes a comma delimited list that MAY contain number range, and |
---|
851 | //expands any range of run numbers into a comma-delimited list... |
---|
852 | //and returns the new list - if not a range, return unchanged |
---|
853 | // |
---|
854 | // local function |
---|
855 | // |
---|
856 | // NO CHANGE NEEDED |
---|
857 | // |
---|
858 | Function/S ExpandNumRanges(list) |
---|
859 | String list |
---|
860 | |
---|
861 | String newList="",dash="-",item,str |
---|
862 | Variable num,ii,hasDash |
---|
863 | |
---|
864 | num=itemsinlist(list,",") |
---|
865 | // print num |
---|
866 | for(ii=0;ii<num;ii+=1) |
---|
867 | //get the item |
---|
868 | item = StringFromList(ii,list,",") |
---|
869 | //does it contain a dash? |
---|
870 | hasDash = strsearch(item,dash,0) //-1 if no dash found |
---|
871 | if(hasDash == -1) |
---|
872 | //not a range, keep it in the list |
---|
873 | newList += item + "," |
---|
874 | else |
---|
875 | //has a dash (so it's a range), expand (or add null) |
---|
876 | newList += ListFromDash(item) |
---|
877 | endif |
---|
878 | endfor |
---|
879 | |
---|
880 | return newList |
---|
881 | End |
---|
882 | |
---|
883 | //be sure to add a trailing comma to the return string... |
---|
884 | // |
---|
885 | // local function |
---|
886 | // |
---|
887 | // NO CHANGE NEEDED |
---|
888 | // |
---|
889 | Function/S ListFromDash(item) |
---|
890 | String item |
---|
891 | |
---|
892 | String numList="",loStr="",hiStr="" |
---|
893 | Variable lo,hi,ii |
---|
894 | |
---|
895 | loStr=StringFromList(0,item,"-") //treat the range as a list |
---|
896 | hiStr=StringFromList(1,item,"-") |
---|
897 | lo=str2num(loStr) |
---|
898 | hi=str2num(hiStr) |
---|
899 | if( (numtype(lo) != 0) || (numtype(hi) !=0 ) || (lo > hi) ) |
---|
900 | numList="" |
---|
901 | return numList |
---|
902 | endif |
---|
903 | for(ii=lo;ii<=hi;ii+=1) |
---|
904 | numList += num2str(ii) + "," |
---|
905 | endfor |
---|
906 | |
---|
907 | Return numList |
---|
908 | End |
---|
909 | |
---|
910 | |
---|
911 | //returns the proper attenuation factor based on the instrument |
---|
912 | // |
---|
913 | // filestr is passed from TextRead[3] = the default directory, used to identify the instrument |
---|
914 | // lam is passed from RealsRead[26] |
---|
915 | // AttenNo is passed from ReaslRead[3] |
---|
916 | // |
---|
917 | // Attenuation factor as defined here is <= 1 |
---|
918 | // |
---|
919 | // Facilities can pass ("",1,attenuationFactor) and have this function simply |
---|
920 | // spit back the attenuationFactor (that was read into rw[3]) |
---|
921 | // |
---|
922 | // called by Correct.ipf, ProtocolAsPanel.ipf, Transmission.ipf |
---|
923 | // |
---|
924 | Function AttenuationFactor(fileStr,lam,attenNo) |
---|
925 | String fileStr |
---|
926 | Variable lam,attenNo |
---|
927 | |
---|
928 | Variable attenFactor |
---|
929 | make/O/N=4 Attenuators_ILL={1,147,902,2874} |
---|
930 | |
---|
931 | attenFactor = Attenuators_ILL[attenNo] |
---|
932 | |
---|
933 | // print attenfactor |
---|
934 | |
---|
935 | // your code here |
---|
936 | |
---|
937 | return(1/attenFactor) |
---|
938 | End |
---|
939 | |
---|
940 | //function called by the popups to get a file list of data that can be sorted |
---|
941 | // this procedure simply removes the raw data files from the string - there |
---|
942 | //can be lots of other junk present, but this is very fast... |
---|
943 | // |
---|
944 | // could also use the alternate procedure of keeping only file with the proper extension |
---|
945 | // |
---|
946 | // another possibility is to get a listing of the text files, but is unreliable on |
---|
947 | // Windows, where the data file must be .txt (and possibly OSX) |
---|
948 | // |
---|
949 | // called by FIT_Ops.ipf, NSORT.ipf, PlotUtils.ipf |
---|
950 | // |
---|
951 | // modify for specific facilities by changing the "*.SA1*","*.SA2*","*.SA3*" stringmatch |
---|
952 | // items which are specific to NCNR |
---|
953 | // |
---|
954 | Function/S ReducedDataFileList(ctrlName) |
---|
955 | String ctrlName |
---|
956 | |
---|
957 | String list="",newList="",item="" |
---|
958 | Variable num,ii |
---|
959 | |
---|
960 | //check for the path |
---|
961 | PathInfo catPathName |
---|
962 | if(V_Flag==0) |
---|
963 | DoAlert 0, "Data path does not exist - pick the data path from the button on the main panel" |
---|
964 | Return("") |
---|
965 | Endif |
---|
966 | |
---|
967 | list = IndexedFile(catpathName,-1,"????") |
---|
968 | num=ItemsInList(list,";") |
---|
969 | //print "num = ",num |
---|
970 | for(ii=(num-1);ii>=0;ii-=1) |
---|
971 | item = StringFromList(ii, list ,";") |
---|
972 | //simply remove all that are not raw data files (SA1 SA2 SA3) |
---|
973 | if( !stringmatch(item,"*.SA1*") && !stringmatch(item,"*.SA2*") && !stringmatch(item,"*.SA3*") ) |
---|
974 | if( !stringmatch(item,".*") && !stringmatch(item,"*.pxp") && !stringmatch(item,"*.DIV")) //eliminate mac "hidden" files, pxp, and div files |
---|
975 | newlist += item + ";" |
---|
976 | endif |
---|
977 | endif |
---|
978 | endfor |
---|
979 | //remove VAX version numbers |
---|
980 | newList = RemoveVersNumsFromList(newList) |
---|
981 | //sort |
---|
982 | newList = SortList(newList,";",0) |
---|
983 | |
---|
984 | return newlist |
---|
985 | End |
---|
986 | |
---|
987 | // returns a list of raw data files in the catPathName directory on disk |
---|
988 | // - list is SEMICOLON-delimited |
---|
989 | // |
---|
990 | // called by PatchFiles.ipf, Tile_2D.ipf |
---|
991 | // |
---|
992 | Function/S GetRawDataFileList() |
---|
993 | |
---|
994 | //make sure that path exists |
---|
995 | PathInfo catPathName |
---|
996 | if (V_flag == 0) |
---|
997 | Abort "Folder path does not exist - use Pick Path button on Main Panel" |
---|
998 | Endif |
---|
999 | |
---|
1000 | String list=IndexedFile(catPathName,-1,"????") |
---|
1001 | |
---|
1002 | String newList="",item="" |
---|
1003 | Variable num=ItemsInList(list,";"),ii |
---|
1004 | |
---|
1005 | |
---|
1006 | for(ii=0;ii<num;ii+=1) |
---|
1007 | item = StringFromList(ii, list ,";") |
---|
1008 | // if( stringmatch(item,"*") ) |
---|
1009 | // newlist += item + ";" |
---|
1010 | // endif |
---|
1011 | if( stringmatch(item,"!*.*") ) |
---|
1012 | newlist += item + ";" |
---|
1013 | |
---|
1014 | |
---|
1015 | endif |
---|
1016 | |
---|
1017 | |
---|
1018 | endfor |
---|
1019 | |
---|
1020 | // your code here |
---|
1021 | newList = SortList(newList,";",0) |
---|
1022 | |
---|
1023 | // print newlist |
---|
1024 | |
---|
1025 | return(newlist) |
---|
1026 | End |
---|
1027 | |
---|
1028 | //********************** |
---|
1029 | // 2D resolution function calculation - in terms of X and Y |
---|
1030 | // |
---|
1031 | // based on notes from David Mildner, 2008 |
---|
1032 | // |
---|
1033 | // the final NCNR version is located in NCNR_Utils.ipf |
---|
1034 | // |
---|
1035 | Function/S get2DResolution(inQ,phi,lambda,lambdaWidth,DDet,apOff,S1,S2,L1,L2,BS,del_r,usingLenses,r_dist,SigmaQX,SigmaQY,fSubS) |
---|
1036 | Variable inQ, phi,lambda, lambdaWidth, DDet, apOff, S1, S2, L1, L2, BS, del_r,usingLenses,r_dist |
---|
1037 | Variable &SigmaQX,&SigmaQY,&fSubS //these are the output quantities at the input Q value |
---|
1038 | |
---|
1039 | return("Function Empty") |
---|
1040 | End |
---|
1041 | |
---|
1042 | // a tube-by-tube correction that replaces our area detecor correction |
---|
1043 | Function DetEffCorrILL(lambda,dtdist,xd) |
---|
1044 | Variable lambda,dtdist,xd |
---|
1045 | Variable ff=1,theta |
---|
1046 | |
---|
1047 | theta =360* atan( xd/dtdist )/(2*Pi) |
---|
1048 | |
---|
1049 | if (lambda <=5.1 && lambda>=4.9) |
---|
1050 | ff= 1.000087- 7.094023e-5*abs(theta) + 8.622997e-5*abs(theta^2) + 9.262026e-6*abs(theta^3) -3.216369e-7*abs(theta^4) +2.142398e-9*abs(theta^5) |
---|
1051 | elseif (lambda <=8.1 && lambda>=7.9) |
---|
1052 | ff= 0.9993575- 0.0002320264*abs(theta) + 9.751713e-5*abs(theta^2) + 1.018564e-5*abs(theta^3) -3.977445e-7*abs(theta^4) +2.960205e-9*abs(theta^5) |
---|
1053 | endif |
---|
1054 | ff= 0.9992674-0.0001808763*abs(theta) +8.134414e-05*abs(theta^2) +1.151734e-05*abs(theta^3) - 4.401022e-07*abs(theta^4)+3.71246e-09*abs(theta^5) |
---|
1055 | |
---|
1056 | return(ff) |
---|
1057 | End |
---|
1058 | |
---|
1059 | |
---|
1060 | // Return the filename that represents the previous or next file. |
---|
1061 | // Input is current filename and increment. |
---|
1062 | // Increment should be -1 or 1 |
---|
1063 | // -1 => previous file |
---|
1064 | // 1 => next file |
---|
1065 | Function/S GetPrevNextRawFile(curfilename, prevnext) |
---|
1066 | String curfilename |
---|
1067 | Variable prevnext |
---|
1068 | |
---|
1069 | String filename |
---|
1070 | |
---|
1071 | //get the run number |
---|
1072 | Variable num = GetRunNumFromFile(curfilename) |
---|
1073 | |
---|
1074 | //find the next specified file by number |
---|
1075 | fileName = FindFileFromRunNumber(num+prevnext) |
---|
1076 | |
---|
1077 | if(cmpstr(fileName,"")==0) |
---|
1078 | //null return, do nothing |
---|
1079 | fileName = FindFileFromRunNumber(num) |
---|
1080 | Endif |
---|
1081 | |
---|
1082 | // print "in FU "+filename |
---|
1083 | |
---|
1084 | Return filename |
---|
1085 | End |
---|