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