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