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