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 | Function GetRunNumFromFile(item) |
---|
198 | String item |
---|
199 | |
---|
200 | Variable num=-1 // an invalid return value |
---|
201 | |
---|
202 | String runStr="" |
---|
203 | |
---|
204 | runstr = item |
---|
205 | num = str2num(runstr) |
---|
206 | |
---|
207 | |
---|
208 | //your code here |
---|
209 | |
---|
210 | return (num) |
---|
211 | End |
---|
212 | |
---|
213 | // item is a filename |
---|
214 | // |
---|
215 | // this function extracts some sort of number from the file |
---|
216 | // presumably some sort of automatically incrementing run number set by the |
---|
217 | // acquisition system |
---|
218 | // |
---|
219 | // this run number should be a unique identifier for the file |
---|
220 | // |
---|
221 | // same as GetRunNumFromFile(0), just with a string return |
---|
222 | // |
---|
223 | // "ABC" returned as an invalid result |
---|
224 | Function/S GetRunNumStrFromFile(item) |
---|
225 | String item |
---|
226 | |
---|
227 | String invalid = "ABC" //"ABC" is not a valid run number, since it's text |
---|
228 | String retStr |
---|
229 | retStr=invalid |
---|
230 | |
---|
231 | retstr = item |
---|
232 | //your code here |
---|
233 | |
---|
234 | |
---|
235 | |
---|
236 | return(retStr) |
---|
237 | End |
---|
238 | |
---|
239 | //returns a string containing the full path to the file containing the |
---|
240 | //run number "num". The null string is returned if no valid file can be found. |
---|
241 | // |
---|
242 | // |
---|
243 | // search in the path "catPathName" (hard-wired), will abort if this path does not exist |
---|
244 | //the file returned will be a RAW SANS data file, other types of files are |
---|
245 | //filtered out. |
---|
246 | // |
---|
247 | // called by Buttons.ipf and Transmission.ipf, and locally by parsing routines |
---|
248 | // |
---|
249 | Function/S FindFileFromRunNumber(num) |
---|
250 | Variable num |
---|
251 | |
---|
252 | String fullName="",partialName="",item="" |
---|
253 | String numStr="" |
---|
254 | |
---|
255 | numStr = num2str(num) |
---|
256 | // pad to 6 characters |
---|
257 | switch(strlen(numstr)) // numeric switch |
---|
258 | case 6: // execute if case matches expression |
---|
259 | break // exit from switch |
---|
260 | case 5: |
---|
261 | numStr = "0"+numStr |
---|
262 | break |
---|
263 | case 4: |
---|
264 | numStr = "00"+numStr |
---|
265 | break |
---|
266 | case 3: |
---|
267 | numStr = "000"+numStr |
---|
268 | break |
---|
269 | case 2: |
---|
270 | numStr = "0000"+numStr |
---|
271 | break |
---|
272 | case 1: |
---|
273 | numStr = "00000"+numStr |
---|
274 | break |
---|
275 | default: // optional default expression executed |
---|
276 | endswitch |
---|
277 | |
---|
278 | // Print "numstr = ",numstr |
---|
279 | |
---|
280 | //make sure that path exists |
---|
281 | PathInfo catPathName |
---|
282 | String path = S_path |
---|
283 | if (V_flag == 0) |
---|
284 | Abort "folder path does not exist - use Pick Path button" |
---|
285 | Endif |
---|
286 | |
---|
287 | String list="",newList="",testStr="" |
---|
288 | |
---|
289 | |
---|
290 | |
---|
291 | list = IndexedFile(catPathName,-1,"????") //get all files in folder |
---|
292 | //find (the) one with the number in the run # location in the name |
---|
293 | Variable numItems,ii,runFound,isRAW |
---|
294 | numItems = ItemsInList(list,";") //get the new number of items in the list |
---|
295 | ii=0 |
---|
296 | |
---|
297 | do |
---|
298 | //parse through the list in this order: |
---|
299 | // 1 - does item contain run number (as a string) "TTTTTnnn.SAn_XXX_Tyyy" |
---|
300 | // 2 - exclude by isRaw? (to minimize disk access) |
---|
301 | item = StringFromList(ii, list ,";" ) |
---|
302 | if(strlen(item) != 0) |
---|
303 | //find the run number, if it exists as a three character string |
---|
304 | testStr = GetRunNumStrFromFile(item) |
---|
305 | runFound = cmpstr(numStr,testStr) |
---|
306 | if(runFound == 0) |
---|
307 | partialName = FindValidFileName(item) |
---|
308 | if(strlen(partialName) != 0) //non-null return from FindValidFileName() |
---|
309 | fullName = path + partialName |
---|
310 | //check if RAW, if so,this must be the file! |
---|
311 | isRAW = CheckIfRawData(fullName) |
---|
312 | if(isRaw) |
---|
313 | //stop here |
---|
314 | //print fullname |
---|
315 | return(fullname) |
---|
316 | Endif |
---|
317 | Endif |
---|
318 | Endif |
---|
319 | Endif |
---|
320 | ii+=1 |
---|
321 | while(ii<numItems) //process all items in list |
---|
322 | Return ("") //null return if file not found in list |
---|
323 | |
---|
324 | //your code here |
---|
325 | |
---|
326 | End |
---|
327 | |
---|
328 | |
---|
329 | |
---|
330 | |
---|
331 | |
---|
332 | //function to test a file to see if it is a RAW SANS file |
---|
333 | // |
---|
334 | // returns truth 0/1 |
---|
335 | // |
---|
336 | // called by many procedures (both external and local) |
---|
337 | // |
---|
338 | Function CheckIfRawData(fname) |
---|
339 | String fname |
---|
340 | |
---|
341 | |
---|
342 | Variable refnum,totalBytes |
---|
343 | String testStr="" |
---|
344 | |
---|
345 | Open/R/T="????" refNum as fname |
---|
346 | //get the total number of bytes in the file |
---|
347 | FStatus refNum |
---|
348 | totalBytes = V_logEOF |
---|
349 | // Print totalBytes |
---|
350 | FSetPos refNum,75 |
---|
351 | FReadLine/N=3 refNum,testStr |
---|
352 | // print teststr |
---|
353 | Close refNum |
---|
354 | |
---|
355 | if(totalBytes == 142317 && cmpstr(testStr,"RRR")==0) |
---|
356 | //true, is raw data file |
---|
357 | |
---|
358 | // print "yes" |
---|
359 | Return(1) |
---|
360 | |
---|
361 | |
---|
362 | else |
---|
363 | //some other file |
---|
364 | |
---|
365 | // print "no" |
---|
366 | Return(0) |
---|
367 | Endif |
---|
368 | |
---|
369 | |
---|
370 | |
---|
371 | |
---|
372 | // if() |
---|
373 | // //true, is raw data file |
---|
374 | // Return(1) |
---|
375 | // else |
---|
376 | // //some other file |
---|
377 | // Return(0) |
---|
378 | // Endif |
---|
379 | |
---|
380 | End |
---|
381 | |
---|
382 | |
---|
383 | // function returns 1 if file is a transmission file, 0 if not |
---|
384 | // |
---|
385 | // called by Transmission.ipf, CatVSTable.ipf, NSORT.ipf |
---|
386 | // |
---|
387 | Function isTransFile(fName) |
---|
388 | String fname |
---|
389 | |
---|
390 | variable ypos |
---|
391 | NVAR yTol = root:myGlobals:BeamstopYTol |
---|
392 | |
---|
393 | ypos = getRealValueFromHeader(fname,15) |
---|
394 | |
---|
395 | // print ypos |
---|
396 | |
---|
397 | // print ytol |
---|
398 | |
---|
399 | if(abs(ypos)>=ytol) |
---|
400 | // //yes, its a transmisison file |
---|
401 | |
---|
402 | //print "yes" |
---|
403 | Return(1) |
---|
404 | else |
---|
405 | // //some other file |
---|
406 | |
---|
407 | //print "no" |
---|
408 | Return(0) |
---|
409 | Endif |
---|
410 | End |
---|
411 | |
---|
412 | |
---|
413 | //function to remove all spaces from names when searching for filenames |
---|
414 | //the filename (as saved) will never have interior spaces (TTTTTnnn_AB _Bnnn) |
---|
415 | //but the text field in the header may |
---|
416 | // |
---|
417 | //returns a string identical to the original string, except with the interior spaces removed |
---|
418 | // |
---|
419 | // local function for file name manipulation |
---|
420 | // |
---|
421 | // no change needed here |
---|
422 | Function/S RemoveAllSpaces(str) |
---|
423 | String str |
---|
424 | |
---|
425 | String tempstr = str |
---|
426 | Variable ii,spc,len //should never be more than 2 or 3 trailing spaces in a filename |
---|
427 | ii=0 |
---|
428 | do |
---|
429 | len = strlen(tempStr) |
---|
430 | spc = strsearch(tempStr," ",0) //is the last character a space? |
---|
431 | if (spc == -1) |
---|
432 | break //no more spaces found, get out |
---|
433 | endif |
---|
434 | str = tempstr |
---|
435 | tempStr = str[0,(spc-1)] + str[(spc+1),(len-1)] //remove the space from the string |
---|
436 | While(1) //should never be more than 2 or 3 |
---|
437 | |
---|
438 | If(strlen(tempStr) < 1) |
---|
439 | tempStr = "" //be sure to return a null string if problem found |
---|
440 | Endif |
---|
441 | |
---|
442 | //Print strlen(tempstr) |
---|
443 | |
---|
444 | Return(tempStr) |
---|
445 | |
---|
446 | End |
---|
447 | |
---|
448 | |
---|
449 | //Function attempts to find valid filename from partial name by checking for |
---|
450 | // the existence of the file on disk |
---|
451 | // |
---|
452 | // returns a valid filename (No path prepended) or a null string |
---|
453 | // |
---|
454 | // called by any functions, both external and local |
---|
455 | // |
---|
456 | Function/S FindValidFilename(partialName) |
---|
457 | String PartialName |
---|
458 | |
---|
459 | String retStr="" |
---|
460 | |
---|
461 | //your code here |
---|
462 | |
---|
463 | |
---|
464 | |
---|
465 | //try name with no changes - to allow for ABS files that have spaces in the names 12APR04 |
---|
466 | retStr = ValidFileString(partialName) |
---|
467 | if(cmpstr(retStr,"") !=0) |
---|
468 | //non-null return |
---|
469 | return(retStr) |
---|
470 | Endif |
---|
471 | |
---|
472 | //if the partial name is derived from the file header, there can be spaces at the beginning |
---|
473 | //or in the middle of the filename - depending on the prefix and initials used |
---|
474 | // |
---|
475 | //remove any leading spaces from the name before starting |
---|
476 | partialName = RemoveAllSpaces(partialName) |
---|
477 | |
---|
478 | //try name with no spaces |
---|
479 | retStr = ValidFileString(partialName) |
---|
480 | if(cmpstr(retStr,"") !=0) |
---|
481 | //non-null return |
---|
482 | return(retStr) |
---|
483 | Endif |
---|
484 | |
---|
485 | //try all UPPERCASE |
---|
486 | partialName = UpperStr(partialName) |
---|
487 | retStr = ValidFileString(partialName) |
---|
488 | if(cmpstr(retStr,"") !=0) |
---|
489 | //non-null return |
---|
490 | return(retStr) |
---|
491 | Endif |
---|
492 | |
---|
493 | //try all lowercase (ret null if failure) |
---|
494 | partialName = LowerStr(partialName) |
---|
495 | retStr = ValidFileString(partialName) |
---|
496 | if(cmpstr(retStr,"") !=0) |
---|
497 | //non-null return |
---|
498 | return(retStr) |
---|
499 | else |
---|
500 | return(retStr) |
---|
501 | Endif |
---|
502 | End |
---|
503 | |
---|
504 | // Function checks for the existence of a file |
---|
505 | // partialName;vers (to account for VAX filenaming conventions) |
---|
506 | // The partial name is tried first with no version number |
---|
507 | // |
---|
508 | // *** the PATH is hard-wired to catPathName (which is assumed to exist) |
---|
509 | // version numers up to ;10 are tried |
---|
510 | // only the "name;vers" is returned if successful. The path is not prepended |
---|
511 | // |
---|
512 | // local function |
---|
513 | // |
---|
514 | |
---|
515 | |
---|
516 | |
---|
517 | Function/S ValidFileString(partialName) |
---|
518 | String partialName |
---|
519 | |
---|
520 | String tempName = "",msg="" |
---|
521 | Variable ii,refnum |
---|
522 | |
---|
523 | ii=0 |
---|
524 | do |
---|
525 | if(ii==0) |
---|
526 | //first pass, try the partialName |
---|
527 | tempName = partialName |
---|
528 | Open/Z/R/T="????TEXT"/P=catPathName refnum tempName //Does open file (/Z flag) |
---|
529 | if(V_flag == 0) |
---|
530 | //file exists |
---|
531 | Close refnum //YES needed, |
---|
532 | break |
---|
533 | endif |
---|
534 | else |
---|
535 | tempName = partialName + ";" + num2str(ii) |
---|
536 | Open/Z/R/T="????TEXT"/P=catPathName refnum tempName |
---|
537 | if(V_flag == 0) |
---|
538 | //file exists |
---|
539 | Close refnum |
---|
540 | break |
---|
541 | endif |
---|
542 | Endif |
---|
543 | ii+=1 |
---|
544 | //print "ii=",ii |
---|
545 | while(ii<11) |
---|
546 | //go get the selected bits of information, using tempName, which exists |
---|
547 | if(ii>=11) |
---|
548 | //msg = partialName + " not found. is version number > 11?" |
---|
549 | //DoAlert 0, msg |
---|
550 | //PathInfo catPathName |
---|
551 | //Print S_Path |
---|
552 | Return ("") //use null string as error condition |
---|
553 | Endif |
---|
554 | |
---|
555 | Return (tempName) |
---|
556 | End |
---|
557 | |
---|
558 | |
---|
559 | |
---|
560 | |
---|
561 | //returns a string containing filename (WITHOUT the ;vers) |
---|
562 | //the input string is a full path to the file (Mac-style, still works on Win in IGOR) |
---|
563 | //with the folders separated by colons |
---|
564 | // |
---|
565 | // called by MaskUtils.ipf, ProtocolAsPanel.ipf, WriteQIS.ipf |
---|
566 | // |
---|
567 | // NEEDS NO CHANGES |
---|
568 | // |
---|
569 | Function/S GetFileNameFromPathNoSemi(fullPath) |
---|
570 | String fullPath |
---|
571 | |
---|
572 | Variable offset1,offset2 |
---|
573 | String filename="" |
---|
574 | //String PartialPath |
---|
575 | offset1 = 0 |
---|
576 | do |
---|
577 | offset2 = StrSearch(fullPath, ":", offset1) |
---|
578 | if (offset2 == -1) // no more colons ? |
---|
579 | fileName = FullPath[offset1,strlen(FullPath) ] |
---|
580 | //PartialPath = FullPath[0, offset1-1] |
---|
581 | break |
---|
582 | endif |
---|
583 | offset1 = offset2+1 |
---|
584 | while (1) |
---|
585 | |
---|
586 | //remove version number from name, if it's there - format should be: filename;N |
---|
587 | filename = StringFromList(0,filename,";") //returns null if error |
---|
588 | |
---|
589 | Return filename |
---|
590 | End |
---|
591 | |
---|
592 | //returns a string containing filename (INCLUDING the ;vers) |
---|
593 | //the input string is a full path to the file (Mac-style, still works on Win in IGOR) |
---|
594 | //with the folders separated by colons |
---|
595 | // |
---|
596 | // local, currently unused |
---|
597 | // |
---|
598 | // NEEDS NO CHANGES |
---|
599 | // |
---|
600 | Function/S GetFileNameFromPathKeepSemi(fullPath) |
---|
601 | String fullPath |
---|
602 | |
---|
603 | Variable offset1,offset2 |
---|
604 | String filename |
---|
605 | //String PartialPath |
---|
606 | offset1 = 0 |
---|
607 | do |
---|
608 | offset2 = StrSearch(fullPath, ":", offset1) |
---|
609 | if (offset2 == -1) // no more colons ? |
---|
610 | fileName = FullPath[offset1,strlen(FullPath) ] |
---|
611 | //PartialPath = FullPath[0, offset1-1] |
---|
612 | break |
---|
613 | endif |
---|
614 | offset1 = offset2+1 |
---|
615 | while (1) |
---|
616 | |
---|
617 | //keep version number from name, if it's there - format should be: filename;N |
---|
618 | |
---|
619 | Return filename |
---|
620 | End |
---|
621 | |
---|
622 | //given the full path and filename (fullPath), strips the data path |
---|
623 | //(Mac-style, separated by colons) and returns this path |
---|
624 | //this partial path is the same string that would be returned from PathInfo, for example |
---|
625 | // |
---|
626 | // - allows the user to save to a different path than catPathName |
---|
627 | // |
---|
628 | // called by WriteQIS.ipf |
---|
629 | // |
---|
630 | // NEEDS NO CHANGES |
---|
631 | // |
---|
632 | Function/S GetPathStrFromfullName(fullPath) |
---|
633 | String fullPath |
---|
634 | |
---|
635 | Variable offset1,offset2 |
---|
636 | //String filename |
---|
637 | String PartialPath |
---|
638 | offset1 = 0 |
---|
639 | do |
---|
640 | offset2 = StrSearch(fullPath, ":", offset1) |
---|
641 | if (offset2 == -1) // no more colons ? |
---|
642 | //fileName = FullPath[offset1,strlen(FullPath) ] |
---|
643 | PartialPath = FullPath[0, offset1-1] |
---|
644 | break |
---|
645 | endif |
---|
646 | offset1 = offset2+1 |
---|
647 | while (1) |
---|
648 | |
---|
649 | Return PartialPath |
---|
650 | End |
---|
651 | |
---|
652 | //given the filename trim or modify the filename to get a new |
---|
653 | //file string that can be used for naming averaged 1-d files |
---|
654 | // |
---|
655 | // called by ProtocolAsPanel.ipf and Tile_2D.ipf |
---|
656 | // |
---|
657 | Function/S GetNameFromHeader(fullName) |
---|
658 | String fullName |
---|
659 | String temp,newName = "" |
---|
660 | |
---|
661 | Variable spc,ii=0 |
---|
662 | |
---|
663 | //filename is 20 characters NNNNNxxx.SAn_NNN_NNN |
---|
664 | //want the first 8 characters, NNNNNxxx, then strip off any spaces at the beginning |
---|
665 | //NNNNN was entered as less than 5 characters |
---|
666 | //returns a null string if no name can be found |
---|
667 | do |
---|
668 | temp = fullname[ii,7] //characters ii,7 of the name |
---|
669 | spc = strsearch(temp," ",0) |
---|
670 | if (spc == -1) |
---|
671 | break //no more spaces found |
---|
672 | endif |
---|
673 | ii+=1 |
---|
674 | While(ii<8) |
---|
675 | |
---|
676 | If(strlen(temp) < 1) |
---|
677 | newName = "" //be sure to return a null string if problem found |
---|
678 | else |
---|
679 | newName = temp |
---|
680 | Endif |
---|
681 | |
---|
682 | // print newname |
---|
683 | //your code here |
---|
684 | |
---|
685 | Return(newName) |
---|
686 | End |
---|
687 | |
---|
688 | //list (input) is a list, typically returned from IndexedFile() |
---|
689 | //which is semicolon-delimited, and may contain filenames from the VAX |
---|
690 | //that contain version numbers, where the version number appears as a separate list item |
---|
691 | //(and also as a non-existent file) |
---|
692 | //these numbers must be purged from the list, especially for display in a popup |
---|
693 | //or list processing of filenames |
---|
694 | //the function returns the list, cleaned of version numbers (up to 11) |
---|
695 | //raw data files will typically never have a version number other than 1. |
---|
696 | // |
---|
697 | // if there are no version numbers in the list, the input list is returned |
---|
698 | // |
---|
699 | // called by CatVSTable.ipf, NSORT.ipf, Transmission.ipf, WorkFileUtils.ipf |
---|
700 | // |
---|
701 | // |
---|
702 | // NO CHANGE NEEDED |
---|
703 | // |
---|
704 | Function/S RemoveVersNumsFromList(list) |
---|
705 | String list |
---|
706 | |
---|
707 | //get rid of version numbers first (up to 11) |
---|
708 | Variable ii,num |
---|
709 | String item |
---|
710 | num = ItemsInList(list,";") |
---|
711 | ii=1 |
---|
712 | do |
---|
713 | item = num2str(ii) |
---|
714 | list = RemoveFromList(item, list ,";" ) |
---|
715 | ii+=1 |
---|
716 | while(ii<12) |
---|
717 | |
---|
718 | return (list) |
---|
719 | End |
---|
720 | |
---|
721 | //input is a list of run numbers, and output is a list of filenames (not the full path) |
---|
722 | //*** input list must be COMMA delimited*** |
---|
723 | //output is equivalent to selecting from the CAT table |
---|
724 | //if some or all of the list items are valid filenames, keep them... |
---|
725 | //if an error is encountered, notify of the offending element and return a null list |
---|
726 | // |
---|
727 | //output is COMMA delimited |
---|
728 | // |
---|
729 | // this routine is expecting that the "ask", "none" special cases are handled elsewhere |
---|
730 | //and not passed here |
---|
731 | // |
---|
732 | // called by Marquee.ipf, MultipleReduce.ipf, ProtocolAsPanel.ipf |
---|
733 | // |
---|
734 | // NO CHANGE NEEDED |
---|
735 | // |
---|
736 | Function/S ParseRunNumberList(list) |
---|
737 | String list |
---|
738 | |
---|
739 | String newList="",item="",tempStr="" |
---|
740 | Variable num,ii,runNum |
---|
741 | |
---|
742 | //expand number ranges, if any |
---|
743 | list = ExpandNumRanges(list) |
---|
744 | |
---|
745 | num=itemsinlist(list,",") |
---|
746 | |
---|
747 | for(ii=0;ii<num;ii+=1) |
---|
748 | //get the item |
---|
749 | item = StringFromList(ii,list,",") |
---|
750 | //is it already a valid filename? |
---|
751 | tempStr=FindValidFilename(item) //returns filename if good, null if error |
---|
752 | if(strlen(tempstr)!=0) |
---|
753 | //valid name, add to list |
---|
754 | //Print "it's a file" |
---|
755 | newList += tempStr + "," |
---|
756 | else |
---|
757 | //not a valid name |
---|
758 | //is it a number? |
---|
759 | runNum=str2num(item) |
---|
760 | //print runnum |
---|
761 | if(numtype(runNum) != 0) |
---|
762 | //not a number - maybe an error |
---|
763 | DoAlert 0,"List item "+item+" is not a valid run number or filename. Please enter a valid number or filename." |
---|
764 | return("") |
---|
765 | else |
---|
766 | //a run number or an error |
---|
767 | tempStr = GetFileNameFromPathNoSemi( FindFileFromRunNumber(runNum) ) |
---|
768 | if(strlen(tempstr)==0) |
---|
769 | //file not found, error |
---|
770 | DoAlert 0,"List item "+item+" is not a valid run number. Please enter a valid number." |
---|
771 | return("") |
---|
772 | else |
---|
773 | newList += tempStr + "," |
---|
774 | endif |
---|
775 | endif |
---|
776 | endif |
---|
777 | endfor //loop over all items in list |
---|
778 | |
---|
779 | return(newList) |
---|
780 | End |
---|
781 | |
---|
782 | //takes a comma delimited list that MAY contain number range, and |
---|
783 | //expands any range of run numbers into a comma-delimited list... |
---|
784 | //and returns the new list - if not a range, return unchanged |
---|
785 | // |
---|
786 | // local function |
---|
787 | // |
---|
788 | // NO CHANGE NEEDED |
---|
789 | // |
---|
790 | Function/S ExpandNumRanges(list) |
---|
791 | String list |
---|
792 | |
---|
793 | String newList="",dash="-",item,str |
---|
794 | Variable num,ii,hasDash |
---|
795 | |
---|
796 | num=itemsinlist(list,",") |
---|
797 | // print num |
---|
798 | for(ii=0;ii<num;ii+=1) |
---|
799 | //get the item |
---|
800 | item = StringFromList(ii,list,",") |
---|
801 | //does it contain a dash? |
---|
802 | hasDash = strsearch(item,dash,0) //-1 if no dash found |
---|
803 | if(hasDash == -1) |
---|
804 | //not a range, keep it in the list |
---|
805 | newList += item + "," |
---|
806 | else |
---|
807 | //has a dash (so it's a range), expand (or add null) |
---|
808 | newList += ListFromDash(item) |
---|
809 | endif |
---|
810 | endfor |
---|
811 | |
---|
812 | return newList |
---|
813 | End |
---|
814 | |
---|
815 | //be sure to add a trailing comma to the return string... |
---|
816 | // |
---|
817 | // local function |
---|
818 | // |
---|
819 | // NO CHANGE NEEDED |
---|
820 | // |
---|
821 | Function/S ListFromDash(item) |
---|
822 | String item |
---|
823 | |
---|
824 | String numList="",loStr="",hiStr="" |
---|
825 | Variable lo,hi,ii |
---|
826 | |
---|
827 | loStr=StringFromList(0,item,"-") //treat the range as a list |
---|
828 | hiStr=StringFromList(1,item,"-") |
---|
829 | lo=str2num(loStr) |
---|
830 | hi=str2num(hiStr) |
---|
831 | if( (numtype(lo) != 0) || (numtype(hi) !=0 ) || (lo > hi) ) |
---|
832 | numList="" |
---|
833 | return numList |
---|
834 | endif |
---|
835 | for(ii=lo;ii<=hi;ii+=1) |
---|
836 | numList += num2str(ii) + "," |
---|
837 | endfor |
---|
838 | |
---|
839 | Return numList |
---|
840 | End |
---|
841 | |
---|
842 | |
---|
843 | //returns the proper attenuation factor based on the instrument |
---|
844 | // |
---|
845 | // filestr is passed from TextRead[3] = the default directory, used to identify the instrument |
---|
846 | // lam is passed from RealsRead[26] |
---|
847 | // AttenNo is passed from ReaslRead[3] |
---|
848 | // |
---|
849 | // Attenuation factor as defined here is <= 1 |
---|
850 | // |
---|
851 | // Facilities can pass ("",1,attenuationFactor) and have this function simply |
---|
852 | // spit back the attenuationFactor (that was read into rw[3]) |
---|
853 | // |
---|
854 | // called by Correct.ipf, ProtocolAsPanel.ipf, Transmission.ipf |
---|
855 | // |
---|
856 | Function AttenuationFactor(fileStr,lam,attenNo) |
---|
857 | String fileStr |
---|
858 | Variable lam,attenNo |
---|
859 | |
---|
860 | Variable attenFactor |
---|
861 | make/O/N=4 Attenuators_ILL={1,147,902,2874} |
---|
862 | |
---|
863 | attenFactor = Attenuators_ILL[attenNo] |
---|
864 | |
---|
865 | // print attenfactor |
---|
866 | |
---|
867 | // your code here |
---|
868 | |
---|
869 | return(1/attenFactor) |
---|
870 | End |
---|
871 | |
---|
872 | //function called by the popups to get a file list of data that can be sorted |
---|
873 | // this procedure simply removes the raw data files from the string - there |
---|
874 | //can be lots of other junk present, but this is very fast... |
---|
875 | // |
---|
876 | // could also use the alternate procedure of keeping only file with the proper extension |
---|
877 | // |
---|
878 | // another possibility is to get a listing of the text files, but is unreliable on |
---|
879 | // Windows, where the data file must be .txt (and possibly OSX) |
---|
880 | // |
---|
881 | // called by FIT_Ops.ipf, NSORT.ipf, PlotUtils.ipf |
---|
882 | // |
---|
883 | // modify for specific facilities by changing the "*.SA1*","*.SA2*","*.SA3*" stringmatch |
---|
884 | // items which are specific to NCNR |
---|
885 | // |
---|
886 | Function/S ReducedDataFileList(ctrlName) |
---|
887 | String ctrlName |
---|
888 | |
---|
889 | String list="",newList="",item="" |
---|
890 | Variable num,ii |
---|
891 | |
---|
892 | //check for the path |
---|
893 | PathInfo catPathName |
---|
894 | if(V_Flag==0) |
---|
895 | DoAlert 0, "Data path does not exist - pick the data path from the button on the main panel" |
---|
896 | Return("") |
---|
897 | Endif |
---|
898 | |
---|
899 | list = IndexedFile(catpathName,-1,"????") |
---|
900 | num=ItemsInList(list,";") |
---|
901 | //print "num = ",num |
---|
902 | for(ii=(num-1);ii>=0;ii-=1) |
---|
903 | item = StringFromList(ii, list ,";") |
---|
904 | //simply remove all that are not raw data files (SA1 SA2 SA3) |
---|
905 | if( !stringmatch(item,"*.SA1*") && !stringmatch(item,"*.SA2*") && !stringmatch(item,"*.SA3*") ) |
---|
906 | if( !stringmatch(item,".*") && !stringmatch(item,"*.pxp") && !stringmatch(item,"*.DIV")) //eliminate mac "hidden" files, pxp, and div files |
---|
907 | newlist += item + ";" |
---|
908 | endif |
---|
909 | endif |
---|
910 | endfor |
---|
911 | //remove VAX version numbers |
---|
912 | newList = RemoveVersNumsFromList(newList) |
---|
913 | //sort |
---|
914 | newList = SortList(newList,";",0) |
---|
915 | |
---|
916 | return newlist |
---|
917 | End |
---|
918 | |
---|
919 | // returns a list of raw data files in the catPathName directory on disk |
---|
920 | // - list is SEMICOLON-delimited |
---|
921 | // |
---|
922 | // called by PatchFiles.ipf, Tile_2D.ipf |
---|
923 | // |
---|
924 | Function/S GetRawDataFileList() |
---|
925 | |
---|
926 | //make sure that path exists |
---|
927 | PathInfo catPathName |
---|
928 | if (V_flag == 0) |
---|
929 | Abort "Folder path does not exist - use Pick Path button on Main Panel" |
---|
930 | Endif |
---|
931 | |
---|
932 | String list=IndexedFile(catPathName,-1,"????") |
---|
933 | |
---|
934 | String newList="",item="" |
---|
935 | Variable num=ItemsInList(list,";"),ii |
---|
936 | |
---|
937 | |
---|
938 | for(ii=0;ii<num;ii+=1) |
---|
939 | item = StringFromList(ii, list ,";") |
---|
940 | // if( stringmatch(item,"*") ) |
---|
941 | // newlist += item + ";" |
---|
942 | // endif |
---|
943 | if( stringmatch(item,"!*.*") ) |
---|
944 | newlist += item + ";" |
---|
945 | |
---|
946 | |
---|
947 | endif |
---|
948 | |
---|
949 | |
---|
950 | endfor |
---|
951 | |
---|
952 | // your code here |
---|
953 | newList = SortList(newList,";",0) |
---|
954 | |
---|
955 | // print newlist |
---|
956 | |
---|
957 | return(newlist) |
---|
958 | End |
---|
959 | |
---|
960 | //********************** |
---|
961 | // 2D resolution function calculation - in terms of X and Y |
---|
962 | // |
---|
963 | // based on notes from David Mildner, 2008 |
---|
964 | // |
---|
965 | // the final NCNR version is located in NCNR_Utils.ipf |
---|
966 | // |
---|
967 | Function/S get2DResolution(inQ,phi,lambda,lambdaWidth,DDet,apOff,S1,S2,L1,L2,BS,del_r,usingLenses,r_dist,SigmaQX,SigmaQY,fSubS) |
---|
968 | Variable inQ, phi,lambda, lambdaWidth, DDet, apOff, S1, S2, L1, L2, BS, del_r,usingLenses,r_dist |
---|
969 | Variable &SigmaQX,&SigmaQY,&fSubS //these are the output quantities at the input Q value |
---|
970 | |
---|
971 | return("Function Empty") |
---|
972 | End |
---|
973 | |
---|
974 | // a tube-by-tube correction that replaces our area detecor correction |
---|
975 | Function DetEffCorrILL(lambda,dtdist,xd) |
---|
976 | Variable lambda,dtdist,xd |
---|
977 | Variable ff=1,theta |
---|
978 | |
---|
979 | theta =360* atan( xd/dtdist )/(2*Pi) |
---|
980 | |
---|
981 | if (lambda <=5.1 && lambda>=4.9) |
---|
982 | 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) |
---|
983 | elseif (lambda <=8.1 && lambda>=7.9) |
---|
984 | 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) |
---|
985 | endif |
---|
986 | |
---|
987 | return(ff) |
---|
988 | End |
---|