[575] | 1 | #pragma rtGlobals=1 // Use modern global access method. |
---|
| 2 | #pragma version=5.0 |
---|
| 3 | #pragma IgorVersion=6.1 |
---|
| 4 | |
---|
| 5 | // this file contains globals and functions that are specific to a |
---|
| 6 | // particular facility or data file format |
---|
| 7 | // branched out 29MAR07 - SRK |
---|
| 8 | // |
---|
| 9 | // functions are either labeled with the procedure file that calls them, |
---|
| 10 | // or noted that they are local to this file |
---|
| 11 | |
---|
| 12 | |
---|
| 13 | // initializes globals that are specific to a particular facility |
---|
| 14 | // - number of XY pixels |
---|
| 15 | // - pixexl resolution [cm] |
---|
| 16 | // - detector deadtime constant [s] |
---|
| 17 | // |
---|
| 18 | // called by Initialize.ipf |
---|
| 19 | // |
---|
| 20 | Function InitFacilityGlobals() |
---|
| 21 | |
---|
| 22 | //Detector -specific globals |
---|
| 23 | Variable/G root:myGlobals:gNPixelsX=192 // number of X and Y pixels |
---|
| 24 | Variable/G root:myGlobals:gNPixelsY=192 |
---|
| 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 = 3.4e-6 //deadtime in seconds ???nha |
---|
| 30 | |
---|
| 31 | Variable/G root:myGlobals:apOff = 5.0 // (cm) distance from sample aperture to sample position |
---|
| 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 | //Utility function that returns the detector resolution (in cm) |
---|
| 139 | //Global values are set in the Initialize procedure |
---|
| 140 | // |
---|
| 141 | // - called by CircSectAvg.ipf, RectAnnulAvg.ipf, and ProtocolAsPanel.ipf |
---|
| 142 | // |
---|
| 143 | // fileStr is passed as TextRead[3] |
---|
| 144 | // detStr is passed as TextRead[9] |
---|
| 145 | // |
---|
| 146 | // *** as of Jan 2008, depricated. Now detector pixel sizes are read from the file header |
---|
| 147 | // rw[10] = x size (mm); rw[13] = y size (mm) |
---|
| 148 | // |
---|
| 149 | // depricated - pixel dimensions are read directly from the file header |
---|
| 150 | Function xDetectorPixelResolution(fileStr,detStr) |
---|
| 151 | String fileStr,detStr |
---|
| 152 | |
---|
| 153 | Variable DDet |
---|
| 154 | |
---|
| 155 | //your code here |
---|
| 156 | |
---|
| 157 | return(DDet) |
---|
| 158 | End |
---|
| 159 | |
---|
| 160 | //Utility function that returns the detector deadtime (in seconds) |
---|
| 161 | //Global values are set in the Initialize procedure |
---|
| 162 | // |
---|
| 163 | // - called by WorkFileUtils.ipf |
---|
| 164 | // |
---|
| 165 | // fileStr is passed as TextRead[3] and is the filename |
---|
| 166 | // detStr is passed as TextRead[9] and is an identifier for the detector |
---|
| 167 | // |
---|
| 168 | Function DetectorDeadtime(fileStr,detStr) |
---|
| 169 | String fileStr,detStr |
---|
| 170 | |
---|
| 171 | Variable deadtime |
---|
| 172 | |
---|
| 173 | // your code here |
---|
| 174 | |
---|
| 175 | return(deadtime) |
---|
| 176 | End |
---|
| 177 | |
---|
| 178 | |
---|
[715] | 179 | //given a filename of a SANS data filename of the form |
---|
| 180 | //QKKNNNNNNN.nx.hdf |
---|
| 181 | //returns the prefix |
---|
| 182 | Function/S GetPrefixStrFromFile(item) |
---|
| 183 | String item |
---|
| 184 | String invalid = "" //"" is not a valid run prefix, since it's text |
---|
| 185 | Variable num=-1 |
---|
| 186 | |
---|
| 187 | //find the "dot" |
---|
| 188 | String runStr="" |
---|
| 189 | |
---|
| 190 | Variable pos = strsearch(item,".",0) |
---|
| 191 | if(pos == -1) |
---|
| 192 | //"dot" not found |
---|
| 193 | return (invalid) |
---|
| 194 | else |
---|
| 195 | //found, skip the three characters preceeding it |
---|
| 196 | if (pos <=7) |
---|
| 197 | //not enough characters |
---|
| 198 | return (invalid) |
---|
| 199 | else |
---|
| 200 | runStr = item[0,pos-8] |
---|
| 201 | return (runStr) |
---|
| 202 | Endif |
---|
| 203 | Endif |
---|
| 204 | End |
---|
| 205 | |
---|
| 206 | Function/S RunDigitString(num) |
---|
| 207 | Variable num |
---|
| 208 | |
---|
| 209 | String numStr="" |
---|
| 210 | |
---|
| 211 | //make 7 digit string from run number |
---|
| 212 | sprintf numStr,"%07u",num |
---|
| 213 | |
---|
| 214 | //Print "numstr = ",numstr |
---|
| 215 | return(numstr) |
---|
| 216 | End |
---|
| 217 | |
---|
| 218 | |
---|
[575] | 219 | // item is a filename |
---|
| 220 | // |
---|
| 221 | // this function extracts some sort of number from the file |
---|
| 222 | // presumably some sort of automatically incrementing run number set by the |
---|
| 223 | // acquisition system |
---|
| 224 | // |
---|
| 225 | // this run number should be a unique identifier for the file |
---|
| 226 | // |
---|
| 227 | Function GetRunNumFromFile(item) |
---|
| 228 | String item |
---|
| 229 | |
---|
[707] | 230 | Variable invalid = -1 |
---|
[575] | 231 | Variable num=-1 // an invalid return value |
---|
| 232 | |
---|
[707] | 233 | String runStr="" |
---|
| 234 | Variable pos = strsearch(item,".",0) |
---|
| 235 | if(pos == -1) |
---|
| 236 | //"dot" not found |
---|
| 237 | return (invalid) |
---|
| 238 | else |
---|
| 239 | //found, get the three characters preceeding it |
---|
| 240 | if (pos <=6) |
---|
| 241 | //not enough characters |
---|
| 242 | return (invalid) |
---|
| 243 | else |
---|
| 244 | runStr = item[pos-7,pos-1] |
---|
| 245 | //convert to a number |
---|
| 246 | num = str2num(runStr) |
---|
| 247 | //if valid, return it |
---|
| 248 | if (num == NaN) |
---|
[715] | 249 | //7 characters were not a number |
---|
[707] | 250 | return (invalid) |
---|
| 251 | else |
---|
| 252 | //run was OK |
---|
| 253 | return (num) |
---|
| 254 | Endif |
---|
| 255 | Endif |
---|
| 256 | Endif |
---|
[575] | 257 | return (num) |
---|
| 258 | End |
---|
| 259 | |
---|
| 260 | // item is a filename |
---|
| 261 | // |
---|
| 262 | // this function extracts some sort of number from the file |
---|
| 263 | // presumably some sort of automatically incrementing run number set by the |
---|
| 264 | // acquisition system |
---|
| 265 | // |
---|
| 266 | // this run number should be a unique identifier for the file |
---|
| 267 | // |
---|
| 268 | // same as GetRunNumFromFile(0), just with a string return |
---|
| 269 | // |
---|
| 270 | // "ABC" returned as an invalid result |
---|
| 271 | Function/S GetRunNumStrFromFile(item) |
---|
| 272 | String item |
---|
| 273 | |
---|
| 274 | String invalid = "ABC" //"ABC" is not a valid run number, since it's text |
---|
| 275 | String retStr |
---|
| 276 | retStr=invalid |
---|
| 277 | |
---|
[707] | 278 | String runStr = "" |
---|
| 279 | Variable pos = strsearch(item,".",0) |
---|
| 280 | if(pos == -1) |
---|
| 281 | //"dot" not found |
---|
| 282 | return (invalid) |
---|
| 283 | else |
---|
| 284 | //found, get the three characters preceeding it |
---|
| 285 | if (pos <=6) |
---|
| 286 | //not enough characters |
---|
| 287 | return (invalid) |
---|
| 288 | else |
---|
| 289 | runStr = item[pos-7,pos-1] |
---|
| 290 | return (runStr) |
---|
| 291 | Endif |
---|
| 292 | Endif |
---|
[575] | 293 | End |
---|
| 294 | |
---|
| 295 | //returns a string containing the full path to the file containing the |
---|
| 296 | //run number "num". The null string is returned if no valid file can be found. |
---|
| 297 | // |
---|
| 298 | // |
---|
| 299 | // search in the path "catPathName" (hard-wired), will abort if this path does not exist |
---|
| 300 | //the file returned will be a RAW SANS data file, other types of files are |
---|
| 301 | //filtered out. |
---|
| 302 | // |
---|
| 303 | // called by Buttons.ipf and Transmission.ipf, and locally by parsing routines |
---|
| 304 | // |
---|
| 305 | Function/S FindFileFromRunNumber(num) |
---|
| 306 | Variable num |
---|
| 307 | |
---|
[707] | 308 | String fullName="",partialName="",item="",numStr="" |
---|
[575] | 309 | |
---|
| 310 | //make sure that path exists |
---|
| 311 | PathInfo catPathName |
---|
| 312 | String path = S_path |
---|
| 313 | if (V_flag == 0) |
---|
| 314 | Abort "folder path does not exist - use Pick Path button" |
---|
| 315 | Endif |
---|
| 316 | |
---|
[707] | 317 | //make 7 digit string from run number |
---|
| 318 | sprintf numStr,"%07u",num |
---|
[575] | 319 | |
---|
[707] | 320 | //partialname = "QKK"+tmp_num+".nx.hdf" |
---|
| 321 | |
---|
| 322 | String list="",newList="",testStr="" |
---|
| 323 | |
---|
| 324 | list = IndexedFile(catPathName,-1,"????") //get all files in folder |
---|
| 325 | //find (the) one with the number in the run # location in the name |
---|
| 326 | Variable numItems,ii,runFound,isRAW |
---|
| 327 | numItems = ItemsInList(list,";") //get the new number of items in the list |
---|
| 328 | ii=0 |
---|
| 329 | do |
---|
| 330 | //parse through the list in this order: |
---|
| 331 | // 1 - does item contain run number (as a string) "QKKXXXXXXX.nx.hdf" |
---|
| 332 | // 2 - exclude by isRaw? (to minimize disk access) |
---|
| 333 | item = StringFromList(ii, list ,";" ) |
---|
| 334 | if(strlen(item) != 0) |
---|
| 335 | //find the run number, if it exists as a three character string |
---|
| 336 | testStr = GetRunNumStrFromFile(item) |
---|
| 337 | runFound= cmpstr(numStr,testStr) //compare the three character strings, 0 if equal |
---|
| 338 | if(runFound == 0) |
---|
| 339 | //the run Number was found |
---|
| 340 | //build valid filename |
---|
| 341 | partialName = FindValidFileName(item) |
---|
| 342 | if(strlen(partialName) != 0) //non-null return from FindValidFileName() |
---|
| 343 | fullName = path + partialName |
---|
| 344 | //check if RAW, if so,this must be the file! |
---|
| 345 | isRAW = CheckIfRawData(fullName) |
---|
| 346 | if(isRaw) |
---|
| 347 | //stop here |
---|
| 348 | return(fullname) |
---|
| 349 | Endif |
---|
| 350 | Endif |
---|
| 351 | Endif |
---|
| 352 | Endif |
---|
| 353 | ii+=1 |
---|
| 354 | while(ii<numItems) //process all items in list |
---|
| 355 | Return ("") //null return if file not found in list |
---|
[575] | 356 | End |
---|
| 357 | |
---|
| 358 | //function to test a file to see if it is a RAW SANS file |
---|
| 359 | // |
---|
| 360 | // returns truth 0/1 |
---|
| 361 | // |
---|
| 362 | // called by many procedures (both external and local) |
---|
| 363 | // |
---|
| 364 | Function CheckIfRawData(fname) |
---|
| 365 | String fname |
---|
| 366 | Variable value = 0 |
---|
| 367 | |
---|
[707] | 368 | Variable hdfID,hdfgID |
---|
| 369 | Variable isNXHDF = 0 |
---|
| 370 | |
---|
| 371 | //nha. look for non-NeXus files |
---|
| 372 | if (strsearch(fname, "nx.hdf", 0) >= 0) |
---|
| 373 | isNXHDF = 1 |
---|
[575] | 374 | endif |
---|
[707] | 375 | |
---|
| 376 | if(isNXHDF == 1) |
---|
| 377 | //Need to actually determine if file is RAW data. |
---|
| 378 | HDF5OpenFile/Z hdfID as fname |
---|
| 379 | HDF5OpenGroup/Z hdfID, "/data", hdfgID |
---|
| 380 | if (V_Flag == 0) |
---|
| 381 | //DIV file (with nx.hdf suffix) |
---|
| 382 | value = 0 |
---|
| 383 | else |
---|
| 384 | //Some other nx.hdf file |
---|
| 385 | value = 1 |
---|
| 386 | endif |
---|
| 387 | HDF5CloseGroup/Z hdfgID |
---|
| 388 | HDF5CloseFile/Z hdfID |
---|
| 389 | else |
---|
| 390 | value = 0 |
---|
| 391 | endif |
---|
| 392 | |
---|
[575] | 393 | return(value) |
---|
| 394 | End |
---|
| 395 | |
---|
| 396 | Function isScatFile(fname) |
---|
| 397 | String fname |
---|
| 398 | Variable isTrans, isEmp |
---|
| 399 | Variable value =1 |
---|
| 400 | |
---|
| 401 | isTrans = isTransFile(fname) |
---|
| 402 | isEmp = isEmpFile(fname) |
---|
| 403 | |
---|
| 404 | if(isTrans) |
---|
| 405 | value = 0 |
---|
| 406 | endif |
---|
| 407 | if(isEmp) |
---|
| 408 | value = 0 |
---|
| 409 | endif |
---|
| 410 | return(value) |
---|
| 411 | End |
---|
| 412 | |
---|
| 413 | Function isEmpFile(fName) |
---|
| 414 | String fname |
---|
| 415 | |
---|
| 416 | variable err |
---|
| 417 | string dfName = "" |
---|
| 418 | variable value = 0 |
---|
| 419 | |
---|
| 420 | err = hdfRead(fname, dfName) |
---|
| 421 | //err not handled here |
---|
| 422 | |
---|
[707] | 423 | Wave/T wSampleName = $(dfName+":sample:name") |
---|
[575] | 424 | String sampleName = wSampleName[0] |
---|
| 425 | |
---|
| 426 | if (cmpstr(sampleName,"MT beam")==0) |
---|
| 427 | value = 1 |
---|
| 428 | endif |
---|
| 429 | |
---|
| 430 | return(value) |
---|
| 431 | End |
---|
| 432 | |
---|
| 433 | |
---|
| 434 | // function returns 1 if file is a transmission file, 0 if not |
---|
| 435 | // |
---|
| 436 | // called by Transmission.ipf, CatVSTable.ipf, NSORT.ipf |
---|
| 437 | // |
---|
| 438 | Function isTransFile(fName) |
---|
| 439 | String fname |
---|
| 440 | |
---|
| 441 | // nha. TO DO. entry1 will have to change when the new naming convention for nxentry is implemented. |
---|
| 442 | |
---|
| 443 | variable err |
---|
| 444 | string dfName = "" |
---|
| 445 | variable value = 0 |
---|
| 446 | |
---|
| 447 | err = hdfRead(fname, dfName) |
---|
| 448 | //err not handled here |
---|
| 449 | |
---|
[707] | 450 | Wave wTransmission_Flag = $(dfName+":sample:TransmissionFlag") //is only being set after 27/5/2009. ??? |
---|
[575] | 451 | value = wTransmission_Flag[0] |
---|
[707] | 452 | // |
---|
| 453 | // AJJ June 2nd 2010 - Unclear that this check is correct. Certainly BSPosXmm is not correct parameter in current data format... |
---|
| 454 | // if (value == 0) |
---|
| 455 | // //workaround - determine by bsx position |
---|
| 456 | // Wave wBSX = $(dfName+":instrument:beam_stop:geometry:position:BSPosXmm") |
---|
| 457 | // variable bsx = wBSX[0] |
---|
| 458 | // |
---|
| 459 | // if (bsx >= -10 ) |
---|
| 460 | // value = 1 |
---|
| 461 | // endif |
---|
| 462 | // endif |
---|
[575] | 463 | |
---|
| 464 | return(value) |
---|
| 465 | End |
---|
| 466 | |
---|
| 467 | |
---|
| 468 | //function to remove all spaces from names when searching for filenames |
---|
| 469 | //the filename (as saved) will never have interior spaces (TTTTTnnn_AB _Bnnn) |
---|
| 470 | //but the text field in the header may |
---|
| 471 | // |
---|
| 472 | //returns a string identical to the original string, except with the interior spaces removed |
---|
| 473 | // |
---|
| 474 | // local function for file name manipulation |
---|
| 475 | // |
---|
| 476 | // no change needed here |
---|
| 477 | Function/S RemoveAllSpaces(str) |
---|
| 478 | String str |
---|
| 479 | |
---|
| 480 | String tempstr = str |
---|
| 481 | Variable ii,spc,len //should never be more than 2 or 3 trailing spaces in a filename |
---|
| 482 | ii=0 |
---|
| 483 | do |
---|
| 484 | len = strlen(tempStr) |
---|
| 485 | spc = strsearch(tempStr," ",0) //is the last character a space? |
---|
| 486 | if (spc == -1) |
---|
| 487 | break //no more spaces found, get out |
---|
| 488 | endif |
---|
| 489 | str = tempstr |
---|
| 490 | tempStr = str[0,(spc-1)] + str[(spc+1),(len-1)] //remove the space from the string |
---|
| 491 | While(1) //should never be more than 2 or 3 |
---|
| 492 | |
---|
| 493 | If(strlen(tempStr) < 1) |
---|
| 494 | tempStr = "" //be sure to return a null string if problem found |
---|
| 495 | Endif |
---|
| 496 | |
---|
| 497 | //Print strlen(tempstr) |
---|
| 498 | |
---|
| 499 | Return(tempStr) |
---|
| 500 | |
---|
| 501 | End |
---|
| 502 | |
---|
| 503 | |
---|
| 504 | //Function attempts to find valid filename from partial name by checking for |
---|
| 505 | // the existence of the file on disk |
---|
| 506 | // |
---|
| 507 | // returns a valid filename (No path prepended) or a null string |
---|
| 508 | // |
---|
| 509 | // called by any functions, both external and local |
---|
| 510 | // |
---|
| 511 | Function/S FindValidFilename(partialName) |
---|
| 512 | String PartialName |
---|
| 513 | |
---|
| 514 | String retStr="" |
---|
| 515 | |
---|
[715] | 516 | //try name with no changes - to allow for ABS files that have spaces in the names 12APR04 |
---|
| 517 | retStr = ValidFileString(partialName) |
---|
| 518 | if(cmpstr(retStr,"") !=0) |
---|
| 519 | //non-null return |
---|
| 520 | return(retStr) |
---|
| 521 | Endif |
---|
| 522 | |
---|
| 523 | //if the partial name is derived from the file header, there can be spaces at the beginning |
---|
| 524 | //or in the middle of the filename - depending on the prefix and initials used |
---|
| 525 | // |
---|
| 526 | //remove any leading spaces from the name before starting |
---|
| 527 | partialName = RemoveAllSpaces(partialName) |
---|
| 528 | |
---|
| 529 | //try name with no spaces |
---|
| 530 | retStr = ValidFileString(partialName) |
---|
| 531 | if(cmpstr(retStr,"") !=0) |
---|
| 532 | //non-null return |
---|
| 533 | return(retStr) |
---|
| 534 | Endif |
---|
| 535 | |
---|
| 536 | //try all UPPERCASE |
---|
| 537 | partialName = UpperStr(partialName) |
---|
| 538 | retStr = ValidFileString(partialName) |
---|
| 539 | if(cmpstr(retStr,"") !=0) |
---|
| 540 | //non-null return |
---|
| 541 | return(retStr) |
---|
| 542 | Endif |
---|
| 543 | |
---|
| 544 | //try all lowercase (ret null if failure) |
---|
| 545 | partialName = LowerStr(partialName) |
---|
| 546 | retStr = ValidFileString(partialName) |
---|
| 547 | if(cmpstr(retStr,"") !=0) |
---|
| 548 | //non-null return |
---|
| 549 | return(retStr) |
---|
| 550 | else |
---|
| 551 | return(retStr) |
---|
| 552 | Endif |
---|
[575] | 553 | |
---|
| 554 | End |
---|
| 555 | |
---|
[715] | 556 | // Function checks for the existence of a file |
---|
| 557 | // partialName;vers (to account for VAX filenaming conventions) |
---|
| 558 | // The partial name is tried first with no version number |
---|
| 559 | // |
---|
| 560 | // *** the PATH is hard-wired to catPathName (which is assumed to exist) |
---|
| 561 | // version numers up to ;10 are tried |
---|
| 562 | // only the "name;vers" is returned if successful. The path is not prepended |
---|
| 563 | // |
---|
| 564 | // local function |
---|
| 565 | // |
---|
| 566 | Function/S ValidFileString(partialName) |
---|
| 567 | String partialName |
---|
| 568 | |
---|
| 569 | String tempName = "",msg="" |
---|
| 570 | Variable ii,refnum |
---|
| 571 | |
---|
| 572 | ii=0 |
---|
| 573 | do |
---|
| 574 | if(ii==0) |
---|
| 575 | //first pass, try the partialName |
---|
| 576 | tempName = partialName |
---|
| 577 | Open/Z/R/T="????TEXT"/P=catPathName refnum tempName //Does open file (/Z flag) |
---|
| 578 | if(V_flag == 0) |
---|
| 579 | //file exists |
---|
| 580 | Close refnum //YES needed, |
---|
| 581 | break |
---|
| 582 | endif |
---|
| 583 | else |
---|
| 584 | tempName = partialName + ";" + num2str(ii) |
---|
| 585 | Open/Z/R/T="????TEXT"/P=catPathName refnum tempName |
---|
| 586 | if(V_flag == 0) |
---|
| 587 | //file exists |
---|
| 588 | Close refnum |
---|
| 589 | break |
---|
| 590 | endif |
---|
| 591 | Endif |
---|
| 592 | ii+=1 |
---|
| 593 | //print "ii=",ii |
---|
| 594 | while(ii<11) |
---|
| 595 | //go get the selected bits of information, using tempName, which exists |
---|
| 596 | if(ii>=11) |
---|
| 597 | //msg = partialName + " not found. is version number > 11?" |
---|
| 598 | //DoAlert 0, msg |
---|
| 599 | //PathInfo catPathName |
---|
| 600 | //Print S_Path |
---|
| 601 | Return ("") //use null string as error condition |
---|
| 602 | Endif |
---|
| 603 | |
---|
| 604 | Return (tempName) |
---|
| 605 | End |
---|
[575] | 606 | |
---|
[715] | 607 | |
---|
[575] | 608 | //returns a string containing filename (WITHOUT the ;vers) |
---|
| 609 | //the input string is a full path to the file (Mac-style, still works on Win in IGOR) |
---|
| 610 | //with the folders separated by colons |
---|
| 611 | // |
---|
| 612 | // called by MaskUtils.ipf, ProtocolAsPanel.ipf, WriteQIS.ipf |
---|
| 613 | // |
---|
| 614 | // NEEDS NO CHANGES |
---|
| 615 | // |
---|
| 616 | Function/S GetFileNameFromPathNoSemi(fullPath) |
---|
| 617 | String fullPath |
---|
| 618 | |
---|
| 619 | Variable offset1,offset2 |
---|
| 620 | String filename="" |
---|
| 621 | //String PartialPath |
---|
| 622 | offset1 = 0 |
---|
| 623 | do |
---|
| 624 | offset2 = StrSearch(fullPath, ":", offset1) |
---|
| 625 | if (offset2 == -1) // no more colons ? |
---|
| 626 | fileName = FullPath[offset1,strlen(FullPath) ] |
---|
| 627 | //PartialPath = FullPath[0, offset1-1] |
---|
| 628 | break |
---|
| 629 | endif |
---|
| 630 | offset1 = offset2+1 |
---|
| 631 | while (1) |
---|
| 632 | |
---|
| 633 | //remove version number from name, if it's there - format should be: filename;N |
---|
| 634 | filename = StringFromList(0,filename,";") //returns null if error |
---|
| 635 | |
---|
| 636 | Return filename |
---|
| 637 | End |
---|
| 638 | |
---|
| 639 | //returns a string containing filename (INCLUDING the ;vers) |
---|
| 640 | //the input string is a full path to the file (Mac-style, still works on Win in IGOR) |
---|
| 641 | //with the folders separated by colons |
---|
| 642 | // |
---|
| 643 | // local, currently unused |
---|
| 644 | // |
---|
| 645 | // NEEDS NO CHANGES |
---|
| 646 | // |
---|
| 647 | Function/S GetFileNameFromPathKeepSemi(fullPath) |
---|
| 648 | String fullPath |
---|
| 649 | |
---|
| 650 | Variable offset1,offset2 |
---|
| 651 | String filename |
---|
| 652 | //String PartialPath |
---|
| 653 | offset1 = 0 |
---|
| 654 | do |
---|
| 655 | offset2 = StrSearch(fullPath, ":", offset1) |
---|
| 656 | if (offset2 == -1) // no more colons ? |
---|
| 657 | fileName = FullPath[offset1,strlen(FullPath) ] |
---|
| 658 | //PartialPath = FullPath[0, offset1-1] |
---|
| 659 | break |
---|
| 660 | endif |
---|
| 661 | offset1 = offset2+1 |
---|
| 662 | while (1) |
---|
| 663 | |
---|
| 664 | //keep version number from name, if it's there - format should be: filename;N |
---|
| 665 | |
---|
| 666 | Return filename |
---|
| 667 | End |
---|
| 668 | |
---|
| 669 | //given the full path and filename (fullPath), strips the data path |
---|
| 670 | //(Mac-style, separated by colons) and returns this path |
---|
| 671 | //this partial path is the same string that would be returned from PathInfo, for example |
---|
| 672 | // |
---|
| 673 | // - allows the user to save to a different path than catPathName |
---|
| 674 | // |
---|
| 675 | // called by WriteQIS.ipf |
---|
| 676 | // |
---|
| 677 | // NEEDS NO CHANGES |
---|
| 678 | // |
---|
| 679 | Function/S GetPathStrFromfullName(fullPath) |
---|
| 680 | String fullPath |
---|
| 681 | |
---|
| 682 | Variable offset1,offset2 |
---|
| 683 | //String filename |
---|
| 684 | String PartialPath |
---|
| 685 | offset1 = 0 |
---|
| 686 | do |
---|
| 687 | offset2 = StrSearch(fullPath, ":", offset1) |
---|
| 688 | if (offset2 == -1) // no more colons ? |
---|
| 689 | //fileName = FullPath[offset1,strlen(FullPath) ] |
---|
| 690 | PartialPath = FullPath[0, offset1-1] |
---|
| 691 | break |
---|
| 692 | endif |
---|
| 693 | offset1 = offset2+1 |
---|
| 694 | while (1) |
---|
| 695 | |
---|
| 696 | Return PartialPath |
---|
| 697 | End |
---|
| 698 | |
---|
| 699 | //given the filename trim or modify the filename to get a new |
---|
| 700 | //file string that can be used for naming averaged 1-d files |
---|
| 701 | // |
---|
| 702 | // called by ProtocolAsPanel.ipf and Tile_2D.ipf |
---|
| 703 | // |
---|
| 704 | Function/S GetNameFromHeader(fullName) |
---|
[707] | 705 | // given the fully qualified path and filename ie. fullName, return just the filename |
---|
[575] | 706 | String fullName |
---|
| 707 | String newName = "" |
---|
| 708 | |
---|
| 709 | //your code here |
---|
[707] | 710 | newName = ParseFilePath(0, fullName, ":", 1, 0) |
---|
| 711 | |
---|
[575] | 712 | Return(newName) |
---|
| 713 | End |
---|
| 714 | |
---|
| 715 | //list (input) is a list, typically returned from IndexedFile() |
---|
| 716 | //which is semicolon-delimited, and may contain filenames from the VAX |
---|
| 717 | //that contain version numbers, where the version number appears as a separate list item |
---|
| 718 | //(and also as a non-existent file) |
---|
| 719 | //these numbers must be purged from the list, especially for display in a popup |
---|
| 720 | //or list processing of filenames |
---|
| 721 | //the function returns the list, cleaned of version numbers (up to 11) |
---|
| 722 | //raw data files will typically never have a version number other than 1. |
---|
| 723 | // |
---|
| 724 | // if there are no version numbers in the list, the input list is returned |
---|
| 725 | // |
---|
| 726 | // called by CatVSTable.ipf, NSORT.ipf, Transmission.ipf, WorkFileUtils.ipf |
---|
| 727 | // |
---|
| 728 | // |
---|
| 729 | // NO CHANGE NEEDED |
---|
| 730 | // |
---|
| 731 | Function/S RemoveVersNumsFromList(list) |
---|
| 732 | String list |
---|
| 733 | |
---|
| 734 | //get rid of version numbers first (up to 11) |
---|
| 735 | Variable ii,num |
---|
| 736 | String item |
---|
| 737 | num = ItemsInList(list,";") |
---|
| 738 | ii=1 |
---|
| 739 | do |
---|
| 740 | item = num2str(ii) |
---|
| 741 | list = RemoveFromList(item, list ,";" ) |
---|
| 742 | ii+=1 |
---|
| 743 | while(ii<12) |
---|
| 744 | |
---|
| 745 | return (list) |
---|
| 746 | End |
---|
| 747 | |
---|
| 748 | //input is a list of run numbers, and output is a list of filenames (not the full path) |
---|
| 749 | //*** input list must be COMMA delimited*** |
---|
| 750 | //output is equivalent to selecting from the CAT table |
---|
| 751 | //if some or all of the list items are valid filenames, keep them... |
---|
| 752 | //if an error is encountered, notify of the offending element and return a null list |
---|
| 753 | // |
---|
| 754 | //output is COMMA delimited |
---|
| 755 | // |
---|
| 756 | // this routine is expecting that the "ask", "none" special cases are handled elsewhere |
---|
| 757 | //and not passed here |
---|
| 758 | // |
---|
| 759 | // called by Marquee.ipf, MultipleReduce.ipf, ProtocolAsPanel.ipf |
---|
| 760 | // |
---|
| 761 | // NO CHANGE NEEDED |
---|
| 762 | // |
---|
| 763 | Function/S ParseRunNumberList(list) |
---|
| 764 | String list |
---|
| 765 | |
---|
| 766 | String newList="",item="",tempStr="" |
---|
| 767 | Variable num,ii,runNum |
---|
| 768 | |
---|
| 769 | //expand number ranges, if any |
---|
| 770 | list = ExpandNumRanges(list) |
---|
| 771 | |
---|
| 772 | num=itemsinlist(list,",") |
---|
| 773 | |
---|
| 774 | for(ii=0;ii<num;ii+=1) |
---|
| 775 | //get the item |
---|
| 776 | item = StringFromList(ii,list,",") |
---|
| 777 | |
---|
| 778 | tempStr=FindValidFilename(item) //returns filename if good, null if error |
---|
[707] | 779 | |
---|
[575] | 780 | if(strlen(tempstr)!=0) |
---|
| 781 | //valid name, add to list |
---|
| 782 | //Print "it's a file" |
---|
[707] | 783 | if(strlen(newList)==0) |
---|
| 784 | newList = tempStr |
---|
| 785 | else |
---|
| 786 | newList += "," + tempStr |
---|
| 787 | endif |
---|
| 788 | else |
---|
[575] | 789 | //not a valid name |
---|
| 790 | //is it a number? |
---|
| 791 | runNum=str2num(item) |
---|
| 792 | //print runnum |
---|
| 793 | if(numtype(runNum) != 0) |
---|
| 794 | //not a number - maybe an error |
---|
| 795 | DoAlert 0,"List item "+item+" is not a valid run number or filename. Please enter a valid number or filename." |
---|
| 796 | return("") |
---|
| 797 | else |
---|
| 798 | //a run number or an error |
---|
| 799 | tempStr = GetFileNameFromPathNoSemi( FindFileFromRunNumber(runNum) ) |
---|
| 800 | if(strlen(tempstr)==0) |
---|
| 801 | //file not found, error |
---|
| 802 | DoAlert 0,"List item "+item+" is not a valid run number. Please enter a valid number." |
---|
| 803 | return("") |
---|
| 804 | else |
---|
| 805 | newList += tempStr + "," |
---|
| 806 | endif |
---|
| 807 | endif |
---|
| 808 | endif |
---|
| 809 | endfor //loop over all items in list |
---|
| 810 | |
---|
| 811 | return(newList) |
---|
| 812 | End |
---|
| 813 | |
---|
| 814 | //takes a comma delimited list that MAY contain number range, and |
---|
| 815 | //expands any range of run numbers into a comma-delimited list... |
---|
| 816 | //and returns the new list - if not a range, return unchanged |
---|
| 817 | // |
---|
| 818 | // local function |
---|
| 819 | // |
---|
| 820 | // NO CHANGE NEEDED |
---|
| 821 | // |
---|
| 822 | Function/S ExpandNumRanges(list) |
---|
| 823 | String list |
---|
| 824 | |
---|
| 825 | String newList="",dash="-",item,str |
---|
| 826 | Variable num,ii,hasDash |
---|
| 827 | |
---|
| 828 | num=itemsinlist(list,",") |
---|
| 829 | // print num |
---|
| 830 | for(ii=0;ii<num;ii+=1) |
---|
| 831 | //get the item |
---|
| 832 | item = StringFromList(ii,list,",") |
---|
| 833 | //does it contain a dash? |
---|
| 834 | hasDash = strsearch(item,dash,0) //-1 if no dash found |
---|
| 835 | if(hasDash == -1) |
---|
| 836 | //not a range, keep it in the list |
---|
| 837 | newList += item + "," |
---|
| 838 | else |
---|
| 839 | //has a dash (so it's a range), expand (or add null) |
---|
| 840 | newList += ListFromDash(item) |
---|
| 841 | endif |
---|
| 842 | endfor |
---|
| 843 | |
---|
| 844 | return newList |
---|
| 845 | End |
---|
| 846 | |
---|
| 847 | //be sure to add a trailing comma to the return string... |
---|
| 848 | // |
---|
| 849 | // local function |
---|
| 850 | // |
---|
| 851 | // NO CHANGE NEEDED |
---|
| 852 | // |
---|
| 853 | Function/S ListFromDash(item) |
---|
| 854 | String item |
---|
| 855 | |
---|
| 856 | String numList="",loStr="",hiStr="" |
---|
| 857 | Variable lo,hi,ii |
---|
| 858 | |
---|
| 859 | loStr=StringFromList(0,item,"-") //treat the range as a list |
---|
| 860 | hiStr=StringFromList(1,item,"-") |
---|
| 861 | lo=str2num(loStr) |
---|
| 862 | hi=str2num(hiStr) |
---|
| 863 | if( (numtype(lo) != 0) || (numtype(hi) !=0 ) || (lo > hi) ) |
---|
| 864 | numList="" |
---|
| 865 | return numList |
---|
| 866 | endif |
---|
| 867 | for(ii=lo;ii<=hi;ii+=1) |
---|
| 868 | numList += num2str(ii) + "," |
---|
| 869 | endfor |
---|
| 870 | |
---|
| 871 | Return numList |
---|
| 872 | End |
---|
| 873 | |
---|
| 874 | |
---|
| 875 | //returns the proper attenuation factor based on the instrument |
---|
| 876 | // |
---|
| 877 | // filestr is passed from TextRead[3] = the default directory, used to identify the instrument |
---|
| 878 | // lam is passed from RealsRead[26] |
---|
| 879 | // AttenNo is passed from ReaslRead[3] |
---|
| 880 | // |
---|
| 881 | // Attenuation factor as defined here is <= 1 |
---|
| 882 | // |
---|
| 883 | // Facilities can pass ("",1,attenuationFactor) and have this function simply |
---|
| 884 | // spit back the attenuationFactor (that was read into rw[3]) |
---|
| 885 | // |
---|
| 886 | // called by Correct.ipf, ProtocolAsPanel.ipf, Transmission.ipf |
---|
| 887 | // |
---|
| 888 | Function AttenuationFactor(fileStr,lam,attenNo) |
---|
| 889 | |
---|
| 890 | // |
---|
| 891 | String fileStr // |
---|
| 892 | Variable lam,attenNo |
---|
| 893 | |
---|
| 894 | Variable attenFactor=1 |
---|
| 895 | |
---|
| 896 | // your code here |
---|
| 897 | attenFactor = LookupAtten(lam,attenNo) |
---|
| 898 | |
---|
| 899 | return(attenFactor) |
---|
| 900 | End |
---|
| 901 | |
---|
| 902 | Function LookupAtten(lambda,attenNo) |
---|
| 903 | Variable lambda, attenNo |
---|
| 904 | |
---|
| 905 | Variable trans |
---|
| 906 | String attStr="root:myGlobals:Attenuators:att"+num2str(trunc(attenNo)) |
---|
| 907 | String lamStr = "root:myGlobals:Attenuators:lambda" |
---|
| 908 | |
---|
| 909 | if(attenNo == 0) |
---|
| 910 | return (1) //no attenuation, return trans == 1 |
---|
| 911 | endif |
---|
| 912 | |
---|
[707] | 913 | // if( (lambda < 5) || (lambda > 5 ) ) |
---|
| 914 | // Abort "Wavelength out of calibration range (5A). You must manually enter the absolute parameters" |
---|
| 915 | // Endif |
---|
[575] | 916 | |
---|
| 917 | if(!(WaveExists($attStr)) || !(WaveExists($lamStr)) ) |
---|
| 918 | Execute "MakeAttenTable()" |
---|
| 919 | Endif |
---|
| 920 | //just in case creating the tables fails.... |
---|
| 921 | if(!(WaveExists($attStr)) || !(WaveExists($lamStr)) ) |
---|
| 922 | Abort "Attenuator lookup waves could not be found. You must manually enter the absolute parameters" |
---|
| 923 | Endif |
---|
| 924 | |
---|
| 925 | //lookup the value by interpolating the wavelength |
---|
| 926 | //the attenuator must always be an integer |
---|
| 927 | |
---|
| 928 | |
---|
| 929 | Wave att = $attStr |
---|
| 930 | Wave lam = $lamstr |
---|
| 931 | //nha - commented below out until we have attenuation factors over multiple lambda values |
---|
| 932 | //trans = interp(lambda,lam,att) |
---|
| 933 | |
---|
| 934 | // Print "trans = ",trans |
---|
| 935 | //nha - delete this line when multiple lambda values |
---|
| 936 | trans = att |
---|
| 937 | |
---|
| 938 | return trans |
---|
| 939 | End |
---|
| 940 | |
---|
| 941 | Proc MakeAttenTable() |
---|
| 942 | |
---|
| 943 | NewDataFolder/O root:myGlobals:Attenuators |
---|
| 944 | //do explicitly to avoid data folder problems, redundant, but it must work without fail |
---|
| 945 | |
---|
| 946 | //Quokka specific nha. |
---|
| 947 | Variable num=12 |
---|
| 948 | |
---|
| 949 | Make/O/N=(num) root:myGlobals:Attenuators:att0 |
---|
| 950 | Make/O/N=(num) root:myGlobals:Attenuators:att1 |
---|
| 951 | Make/O/N=(num) root:myGlobals:Attenuators:att2 |
---|
| 952 | Make/O/N=(num) root:myGlobals:Attenuators:att3 |
---|
| 953 | Make/O/N=(num) root:myGlobals:Attenuators:att4 |
---|
| 954 | Make/O/N=(num) root:myGlobals:Attenuators:att5 |
---|
| 955 | Make/O/N=(num) root:myGlobals:Attenuators:att6 |
---|
| 956 | Make/O/N=(num) root:myGlobals:Attenuators:att7 |
---|
| 957 | Make/O/N=(num) root:myGlobals:Attenuators:att8 |
---|
| 958 | Make/O/N=(num) root:myGlobals:Attenuators:att9 |
---|
| 959 | Make/O/N=(num) root:myGlobals:Attenuators:att10 |
---|
| 960 | Make/O/N=(num) root:myGlobals:Attenuators:att11 |
---|
| 961 | |
---|
| 962 | // epg |
---|
| 963 | // note 5A only at this stage but other wavelengths as measured |
---|
| 964 | // these values have to be re-determined as were measured on time and not monitor counts |
---|
[707] | 965 | //Make/O/N=(num) root:myGlobals:Attenuators:lambda={5} |
---|
| 966 | Make/O/N=(num) root:myGlobals:Attenuators:lambda={4.94} |
---|
[575] | 967 | |
---|
| 968 | //Quokka attenuator factors. 19/1/09 nha |
---|
| 969 | //20/3/09 nha updated to |
---|
| 970 | //file://fianna/Sections/Bragg/Data_Analysis_Team/Project/P025 Quokka Commissioning DRV/3_Development/ATTest-timeseries.pdf |
---|
[707] | 971 | //updated by epg 13-02-2010 to reflect kwo measurements at g7 |
---|
[575] | 972 | |
---|
[707] | 973 | root:myGlobals:Attenuators:att0 = {1} |
---|
| 974 | root:myGlobals:Attenuators:att1 = {0.498782} |
---|
| 975 | root:myGlobals:Attenuators:att2 = {0.176433} |
---|
| 976 | root:myGlobals:Attenuators:att3 = {0.0761367} |
---|
| 977 | root:myGlobals:Attenuators:att4 = {0.0353985} |
---|
| 978 | root:myGlobals:Attenuators:att5 = {0.0137137} |
---|
| 979 | root:myGlobals:Attenuators:att6 = {0.00614167} |
---|
| 980 | root:myGlobals:Attenuators:att7 = {0.00264554} |
---|
| 981 | root:myGlobals:Attenuators:att8 = {0.000994504} |
---|
| 982 | root:myGlobals:Attenuators:att9 = {0.000358897} |
---|
| 983 | root:myGlobals:Attenuators:att10 = {7.2845e-05} |
---|
| 984 | root:myGlobals:Attenuators:att11 = {1.67827e-06} |
---|
[575] | 985 | |
---|
| 986 | End |
---|
| 987 | |
---|
| 988 | //function called by the popups to get a file list of data that can be sorted |
---|
| 989 | // this procedure simply removes the raw data files from the string - there |
---|
| 990 | //can be lots of other junk present, but this is very fast... |
---|
| 991 | // |
---|
| 992 | // could also use the alternate procedure of keeping only file with the proper extension |
---|
| 993 | // |
---|
| 994 | // another possibility is to get a listing of the text files, but is unreliable on |
---|
| 995 | // Windows, where the data file must be .txt (and possibly OSX) |
---|
| 996 | // |
---|
| 997 | // called by FIT_Ops.ipf, NSORT.ipf, PlotUtils.ipf |
---|
| 998 | // |
---|
| 999 | // modify for specific facilities by changing the "*.SA1*","*.SA2*","*.SA3*" stringmatch |
---|
| 1000 | // items which are specific to NCNR |
---|
| 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 | //print "num = ",num |
---|
| 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,"*.SA1*") && !stringmatch(item,"*.SA2*") && !stringmatch(item,"*.SA3*") ) |
---|
| 1022 | if( !stringmatch(item,".*") && !stringmatch(item,"*.pxp") && !stringmatch(item,"*.DIV")) //eliminate mac "hidden" files, pxp, and div files |
---|
[715] | 1023 | if (!stringmatch(item,"*.nx.hdf") && !stringmatch(item,"*.bin") && !stringmatch(item,"*.mask")) |
---|
| 1024 | newlist += item + ";" |
---|
| 1025 | endif |
---|
[575] | 1026 | endif |
---|
| 1027 | endif |
---|
| 1028 | endfor |
---|
| 1029 | //remove VAX version numbers |
---|
| 1030 | newList = RemoveVersNumsFromList(newList) |
---|
| 1031 | //sort |
---|
| 1032 | newList = SortList(newList,";",0) |
---|
| 1033 | |
---|
| 1034 | return newlist |
---|
| 1035 | End |
---|
| 1036 | |
---|
| 1037 | // returns a list of raw data files in the catPathName directory on disk |
---|
| 1038 | // - list is SEMICOLON-delimited |
---|
| 1039 | // |
---|
| 1040 | // called by PatchFiles.ipf, Tile_2D.ipf |
---|
| 1041 | // |
---|
| 1042 | Function/S GetRawDataFileList() |
---|
| 1043 | |
---|
| 1044 | //nha. Reads Quokka file names 5/2/09 |
---|
| 1045 | |
---|
| 1046 | //make sure that path exists |
---|
| 1047 | PathInfo catPathName |
---|
| 1048 | if (V_flag == 0) |
---|
| 1049 | Abort "Folder path does not exist - use Pick Path button on Main Panel" |
---|
| 1050 | Endif |
---|
| 1051 | |
---|
| 1052 | String list=IndexedFile(catPathName,-1,"????") |
---|
| 1053 | String newList="",item="" |
---|
| 1054 | Variable num=ItemsInList(list,";"),ii |
---|
| 1055 | for(ii=0;ii<num;ii+=1) |
---|
| 1056 | item = StringFromList(ii, list ,";") |
---|
| 1057 | if( stringmatch(item,"*.nx.hdf") ) |
---|
| 1058 | newlist += item + ";" |
---|
| 1059 | endif |
---|
| 1060 | //print "ii=",ii |
---|
| 1061 | endfor |
---|
| 1062 | newList = SortList(newList,";",0) |
---|
| 1063 | return(newList) |
---|
| 1064 | |
---|
| 1065 | // your code here |
---|
| 1066 | |
---|
| 1067 | return(list) |
---|
| 1068 | End |
---|
| 1069 | |
---|
| 1070 | //********************** |
---|
| 1071 | // 2D resolution function calculation - in terms of X and Y |
---|
| 1072 | // |
---|
| 1073 | // based on notes from David Mildner, 2008 |
---|
| 1074 | // |
---|
| 1075 | // the final NCNR version is located in NCNR_Utils.ipf |
---|
| 1076 | // |
---|
| 1077 | Function/S get2DResolution(inQ,phi,lambda,lambdaWidth,DDet,apOff,S1,S2,L1,L2,BS,del_r,usingLenses,r_dist,SigmaQX,SigmaQY,fSubS) |
---|
| 1078 | Variable inQ, phi,lambda, lambdaWidth, DDet, apOff, S1, S2, L1, L2, BS, del_r,usingLenses,r_dist |
---|
| 1079 | Variable &SigmaQX,&SigmaQY,&fSubS //these are the output quantities at the input Q value |
---|
| 1080 | |
---|
| 1081 | return("Function Empty") |
---|
| 1082 | End |
---|
[683] | 1083 | |
---|
| 1084 | // Return the filename that represents the previous or next file. |
---|
| 1085 | // Input is current filename and increment. |
---|
| 1086 | // Increment should be -1 or 1 |
---|
| 1087 | // -1 => previous file |
---|
| 1088 | // 1 => next file |
---|
| 1089 | Function/S GetPrevNextRawFile(curfilename, prevnext) |
---|
| 1090 | String curfilename |
---|
| 1091 | Variable prevnext |
---|
| 1092 | |
---|
| 1093 | String filename |
---|
| 1094 | |
---|
| 1095 | //get the run number |
---|
| 1096 | Variable num = GetRunNumFromFile(curfilename) |
---|
| 1097 | |
---|
| 1098 | //find the next specified file by number |
---|
| 1099 | fileName = FindFileFromRunNumber(num+prevnext) |
---|
| 1100 | |
---|
| 1101 | if(cmpstr(fileName,"")==0) |
---|
| 1102 | //null return, do nothing |
---|
| 1103 | fileName = FindFileFromRunNumber(num) |
---|
| 1104 | Endif |
---|
| 1105 | |
---|
| 1106 | // print "in FU "+filename |
---|
| 1107 | |
---|
| 1108 | Return filename |
---|
| 1109 | End |
---|