Changeset 69 for sans/SANSReduction/branches
- Timestamp:
- Mar 29, 2007 1:45:45 PM (16 years ago)
- Location:
- sans/SANSReduction/branches/kline_29MAR07/Put in User Procedures/SANS_Reduction_v5.00
- Files:
-
- 3 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
sans/SANSReduction/branches/kline_29MAR07/Put in User Procedures/SANS_Reduction_v5.00/Includes_v500.ipf
r59 r69 29 29 #include "ProDiv" version>=5.0 30 30 #include "ProtocolAsPanel" version>=5.0 31 #include "RawDataReader" version>=5.0 31 //#include "RawDataReader" version>=5.0 //branched 29MAR07 32 32 #include "RawWindowHook" version>=5.0 33 33 #include "RectAnnulAvg" version>=5.0 … … 35 35 #include "Tile_2D" version>=5.0 36 36 #include "Transmission" version>=5.0 37 #include "VAXFileUtils" version>=5.0 37 //#include "VAXFileUtils" version>=5.0 //branched 29MAR07 38 38 #include "WorkFileUtils" version>=5.0 39 39 #include "WriteQIS" version>=5.0 40 #include "RealTimeUpdate_RT" version>=5.0 //removed button from main panel AUG2006 40 // removed RT button from main panel AUG2006 41 // removed RT ipf file in 29MAR07 branch (do not delete, but do not include or maintain) 42 //#include "RealTimeUpdate_RT" version>=5.0 41 43 #include "SANSPreferences" version>=5.0 //NEW 05MAY03 42 44 #include "Subtract_1D" version>=5.0 //NEW 14MAY03 45 46 #include "NCNR_Utils" //new in the 29MAR07 branch 47 #include "NCNR_DataReadWrite" //new in the 29MAR07 branch 48 #include "SANS_Utilities" //new in the 29MAR07 branch 43 49 44 50 // to include the analysis packages, uncomment the following -
sans/SANSReduction/branches/kline_29MAR07/Put in User Procedures/SANS_Reduction_v5.00/Initialize.ipf
r41 r69 33 33 InitFakeProtocols() 34 34 InitGlobals() 35 InitFacilityGlobals() 35 36 DoWindow/F Main_Panel 36 37 If(V_flag == 0) … … 68 69 //return data folder to root: before leaving 69 70 // 70 //now contains global parameters used for detector constants 71 // global parameters used for detector constants are facility specific 72 // and have been moved 71 73 // 72 74 Function InitGlobals() … … 95 97 Variable/G root:myGlobals:gBinWidth=1 96 98 Variable/G root:myGlobals:gNPhiSteps=72 97 Variable/G root:myGlobals:gNPixelsX=128 98 Variable/G root:myGlobals:gNPixelsY=128 99 100 //Detector -specific globals 101 Variable/G root:myGlobals:PixelResNG3_ILL = 1.0 //pixel resolution in cm 102 Variable/G root:myGlobals:PixelResNG5_ILL = 1.0 103 Variable/G root:myGlobals:PixelResNG7_ILL = 1.0 104 Variable/G root:myGlobals:PixelResNG3_ORNL = 0.5 105 Variable/G root:myGlobals:PixelResNG5_ORNL = 0.5 106 Variable/G root:myGlobals:PixelResNG7_ORNL = 0.5 107 Variable/G root:myGlobals:PixelResDefault = 0.5 108 109 Variable/G root:myGlobals:DeadtimeNG3_ILL = 3.0e-6 //deadtime in seconds 110 Variable/G root:myGlobals:DeadtimeNG5_ILL = 3.0e-6 111 Variable/G root:myGlobals:DeadtimeNG7_ILL = 3.0e-6 112 Variable/G root:myGlobals:DeadtimeNG3_ORNL = 3.4e-6 113 Variable/G root:myGlobals:DeadtimeNG5_ORNL = 0.6e-6 //as of 9 MAY 2002 114 Variable/G root:myGlobals:DeadtimeNG7_ORNL = 3.4e-6 115 Variable/G root:myGlobals:DeadtimeDefault = 3.4e-6 116 99 117 100 //set flag if Demo Version is detected 118 101 Variable/G root:myGlobals:isDemoVersion = isDemo() -
sans/SANSReduction/branches/kline_29MAR07/Put in User Procedures/SANS_Reduction_v5.00/RawDataReader.ipf
r41 r69 3 3 #pragma IgorVersion=4.0 4 4 5 //**************************6 //7 // Vers. 1.2 0921018 //9 // functions for reading raw data files from the VAX10 // - RAW data files are read into the RAW folder - integer data from the detector11 // is decompressed and given the proper orientation12 // - header information is placed into real,integer, or text waves in the order they appear13 // in the file header14 //15 // Work data (DIV File) is read into the DIV folder16 //17 //*****************************18 5 19 //simple, main entry procedure that will load a RAW sans data file (not a work file)20 //into the RAW dataFolder21 //(typically called from main panel button)22 //23 Proc LoadSANSData()24 String msgStr = "Select a SANS data file"25 26 Variable err27 err = ReadBinarySANS(msgStr) //will prompt for file28 //ignore the error here29 End30 31 //function that does the guts of reading the binary data file32 //fname is the full path:name;vers required to open the file33 //VAX record markers are skipped as needed34 //the data as read in is in compressed I*2 format, and is decompressed35 //immediately after being read in. The final root:RAW:data wave is the real36 //neutron counts and can be directly operated on37 //header information is put into three wave, integers,reals, and text38 //logicals in the header are currently skipped, since they are no use in the39 //data reduction process. the logicals, however are left untouched.40 //41 Function ReadHeaderAndData(fname)42 String fname43 //this function is for reading in RAW data only, so it will always put data in RAW folder44 String curPath = "root:RAW"45 SetDataFolder curPath //use the full path, so it will always work46 Variable/G root:RAW:gIsLogScale = 0 //initial state is linear, keep this in RAW folder47 48 Variable refNum,integer,realval49 String sansfname,textstr50 51 Make/O/N=23 $"root:RAW:IntegersRead"52 Make/O/N=52 $"root:RAW:RealsRead"53 Make/O/T/N=11 $"root:RAW:TextRead"54 55 Wave intw=$"root:RAW:IntegersRead"56 Wave realw=$"root:RAW:RealsRead"57 Wave/T textw=$"root:RAW:TextRead"58 59 //***NOTE ****60 // the "current path" gets mysteriously reset to "root:" after the SECOND pass through61 // this read routine, after the open dialog is presented62 // the "--read" waves end up in the correct folder, but the data does not! Why?63 //must re-set data folder before writing data array (done below)64 65 //full filename and path is now passed in...66 //actually open the file67 Open/R refNum as fname68 //skip first two bytes (VAX record length markers, not needed here)69 FSetPos refNum, 270 //read the next 21 bytes as characters (fname)71 FReadLine/N=21 refNum,textstr72 textw[0]= textstr73 //read four i*4 values /F=3 flag, B=3 flag74 FBinRead/F=3/B=3 refNum, integer75 intw[0] = integer76 //77 FBinRead/F=3/B=3 refNum, integer78 intw[1] = integer79 //80 FBinRead/F=3/B=3 refNum, integer81 intw[2] = integer82 //83 FBinRead/F=3/B=3 refNum, integer84 intw[3] = integer85 // 6 text fields86 FSetPos refNum,55 //will start reading at byte 5687 FReadLine/N=20 refNum,textstr88 textw[1]= textstr89 FReadLine/N=3 refNum,textstr90 textw[2]= textstr91 FReadLine/N=11 refNum,textstr92 textw[3]= textstr93 FReadLine/N=1 refNum,textstr94 textw[4]= textstr95 FReadLine/N=8 refNum,textstr96 textw[5]= textstr97 FReadLine/N=60 refNum,textstr98 textw[6]= textstr99 100 //3 integers101 FSetPos refNum,174102 FBinRead/F=3/B=3 refNum, integer103 intw[4] = integer104 FBinRead/F=3/B=3 refNum, integer105 intw[5] = integer106 FBinRead/F=3/B=3 refNum, integer107 intw[6] = integer108 109 //2 integers, 3 text fields110 FSetPos refNum,194111 FBinRead/F=3/B=3 refNum, integer112 intw[7] = integer113 FBinRead/F=3/B=3 refNum, integer114 intw[8] = integer115 FReadLine/N=6 refNum,textstr116 textw[7]= textstr117 FReadLine/N=6 refNum,textstr118 textw[8]= textstr119 FReadLine/N=6 refNum,textstr120 textw[9]= textstr121 122 //2 integers123 FSetPos refNum,244124 FBinRead/F=3/B=3 refNum, integer125 intw[9] = integer126 FBinRead/F=3/B=3 refNum, integer127 intw[10] = integer128 129 //2 integers130 FSetPos refNum,308131 FBinRead/F=3/B=3 refNum, integer132 intw[11] = integer133 FBinRead/F=3/B=3 refNum, integer134 intw[12] = integer135 136 //2 integers137 FSetPos refNum,332138 FBinRead/F=3/B=3 refNum, integer139 intw[13] = integer140 FBinRead/F=3/B=3 refNum, integer141 intw[14] = integer142 143 //3 integers144 FSetPos refNum,376145 FBinRead/F=3/B=3 refNum, integer146 intw[15] = integer147 FBinRead/F=3/B=3 refNum, integer148 intw[16] = integer149 FBinRead/F=3/B=3 refNum, integer150 intw[17] = integer151 152 //1 text field153 FSetPos refNum,404154 FReadLine/N=42 refNum,textstr155 textw[10]= textstr156 157 //1 integer158 FSetPos refNum,458159 FBinRead/F=3/B=3 refNum, integer160 intw[18] = integer161 162 //4 integers163 FSetPos refNum,478164 FBinRead/F=3/B=3 refNum, integer165 intw[19] = integer166 FBinRead/F=3/B=3 refNum, integer167 intw[20] = integer168 FBinRead/F=3/B=3 refNum, integer169 intw[21] = integer170 FBinRead/F=3/B=3 refNum, integer171 intw[22] = integer172 173 Close refNum174 175 //now get all of the reals176 //177 //Do all the GBLoadWaves at the end178 //179 //FBinRead Cannot handle 32 bit VAX floating point180 //GBLoadWave, however, can properly read it181 String GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=2/W=1/Q"182 String strToExecute183 //append "/S=offset/U=numofreals" to control the read184 // then append fname to give the full file path185 // then execute186 187 Variable a=0,b=0188 189 SetDataFolder curPath190 191 // 4 R*4 values192 strToExecute = GBLoadStr + "/S=39/U=4" + "\"" + fname + "\""193 Execute strToExecute194 Wave w=$"root:RAW:tempGBWave0"195 b=4 //num of reals read196 realw[a,a+b-1] = w[p-a]197 a+=b198 199 // 4 R*4 values200 SetDataFolder curPath201 strToExecute = GBLoadStr + "/S=158/U=4" + "\"" + fname + "\""202 Execute strToExecute203 b=4204 realw[a,a+b-1] = w[p-a]205 a+=b206 207 ///////////208 // 2 R*4 values209 SetDataFolder curPath210 strToExecute = GBLoadStr + "/S=186/U=2" + "\"" + fname + "\""211 Execute strToExecute212 b=2213 realw[a,a+b-1] = w[p-a]214 a+=b215 216 // 6 R*4 values217 SetDataFolder curPath218 strToExecute = GBLoadStr + "/S=220/U=6" + "\"" + fname + "\""219 Execute strToExecute220 b=6221 realw[a,a+b-1] = w[p-a]222 a+=b223 224 // 13 R*4 values225 SetDataFolder curPath226 strToExecute = GBLoadStr + "/S=252/U=13" + "\"" + fname + "\""227 Execute strToExecute228 b=13229 realw[a,a+b-1] = w[p-a]230 a+=b231 232 // 3 R*4 values233 SetDataFolder curPath234 strToExecute = GBLoadStr + "/S=320/U=3" + "\"" + fname + "\""235 Execute strToExecute236 b=3237 realw[a,a+b-1] = w[p-a]238 a+=b239 240 // 7 R*4 values241 SetDataFolder curPath242 strToExecute = GBLoadStr + "/S=348/U=7" + "\"" + fname + "\""243 Execute strToExecute244 b=7245 realw[a,a+b-1] = w[p-a]246 a+=b247 248 // 4 R*4 values249 SetDataFolder curPath250 strToExecute = GBLoadStr + "/S=388/U=4" + "\"" + fname + "\""251 Execute strToExecute252 b=4253 realw[a,a+b-1] = w[p-a]254 a+=b255 256 // 2 R*4 values257 SetDataFolder curPath258 strToExecute = GBLoadStr + "/S=450/U=2" + "\"" + fname + "\""259 Execute strToExecute260 b=2261 realw[a,a+b-1] = w[p-a]262 a+=b263 264 // 2 R*4 values265 SetDataFolder curPath266 strToExecute = GBLoadStr + "/S=470/U=2" + "\"" + fname + "\""267 Execute strToExecute268 b=2269 realw[a,a+b-1] = w[p-a]270 a+=b271 272 // 5 R*4 values273 SetDataFolder curPath274 strToExecute = GBLoadStr + "/S=494/U=5" + "\"" + fname + "\""275 Execute strToExecute276 b=5277 realw[a,a+b-1] = w[p-a]278 279 //if the binary VAX data ws transferred to a MAC, all is OK280 //if the data was trasnferred to an Intel machine (IBM), all the real values must be281 //divided by 4 to get the correct floating point values282 // I can't find any combination of settings in GBLoadWave or FBinRead to read data in correctly283 // on an Intel machine.284 //With the corrected version of GBLoadWave XOP (v. 1.43 or higher) Mac and PC both read285 //VAX reals correctly, and no checking is necessary 12 APR 99286 //if(cmpstr("Macintosh",IgorInfo(2)) == 0)287 //do nothing288 //else289 //either Windows or Windows NT290 //realw /= 4291 //endif292 293 SetDataFolder curPath294 //read in the data295 strToExecute = "GBLoadWave/O/N=tempGBwave/B/T={16,2}/S=514/Q" + "\"" + fname + "\""296 Execute strToExecute297 298 SetDataFolder curPath //use the full path, so it will always work299 300 Make/O/N=16384 $"root:RAW:data"301 WAVE data=$"root:RAW:data"302 SkipAndDecompressVAX(w,data)303 Redimension/N=(128,128) data //NIST raw data is 128x128 - do not generalize304 305 //keep a string with the filename in the RAW folder306 String/G root:RAW:fileList = textw[0]307 308 //set the globals to the detector dimensions (pixels)309 Variable/G root:myGlobals:gNPixelsX=128 //default for Ordela data (also set in Initialize.ipf)310 Variable/G root:myGlobals:gNPixelsY=128311 // if(cmpstr(textW[9],"ILL ")==0) //override if OLD Cerca data312 // Variable/G root:myGlobals:gNPixelsX=64313 // Variable/G root:myGlobals:gNPixelsY=64314 // endif315 316 //clean up - get rid of w = $"root:RAW:tempGBWave0"317 KillWaves/Z w318 319 //return the data folder to root320 SetDataFolder root:321 322 Return 0323 324 End325 326 //function called by the main entry procedure327 //sets global display variable, reads in the data, and displays it328 //displays alert, and returns error if no file was selected329 //330 // calling routine must decide whether to abort the execution or not...331 Function ReadBinarySANS(msgStr)332 String msgStr333 334 String filename=""335 336 //each routine is responsible for checking the current (displayed) data folder337 //selecting it, and returning to root when done338 PathInfo/S catPathName //should set the next dialog to the proper path...339 //get the filename, then read it in340 filename = PromptForPath(msgStr)341 //check for cancel from dialog342 if(strlen(filename)==0)343 //user cancelled, abort344 SetDataFolder root:345 DoAlert 0, "No file selected, action aborted"346 return(1)347 Endif348 //Print "GetFileNameFromPath(filename) = " + GetFileNameFromPathNoSemi(filename)349 ReadHeaderAndData(filename) //this is the full Path+file350 351 //the calling macro must change the display type352 String/G root:myGlobals:gDataDisplayType="RAW" //displayed data type is raw353 354 //data is displayed here355 fRawWindowHook()356 357 Return(0)358 End359 360 //function to take the I*2 data that was read in, in VAX format361 //where the integers are "normal", but there are 2-byte record markers362 //sprinkled evenly through the data363 //there are skipped, leaving 128x128=16384 data values364 //the input array (in) is larger than 16384365 //(out) is 128x128 data (single precision) as defined in ReadHeaderAndData()366 //367 Function SkipAndDecompressVAX(in,out)368 Wave in,out369 370 Variable skip,ii371 372 ii=0373 skip=0374 do375 if(mod(ii+skip,1022)==0)376 skip+=1377 endif378 out[ii] = Decompress(in[ii+skip])379 ii+=1380 while(ii<16384)381 return(0)382 End383 384 //decompresses each I*2 data value to its real I*4 value385 //using the decompression routine written by Jim Ryhne, many moons ago386 //387 // the compression routine (not shown here, contained in the VAX fortran RW_DATAFILE.FOR) maps I4 to I2 values.388 // (back in the days where disk space *really* mattered). the I4toI2 function spit out:389 // I4toI2 = I4 when I4 in [0,32767]390 // I4toI2 = -777 when I4 in [2,767,000,...]391 // I4toI2 mapped to -13277 to -32768 otherwise392 //393 // the mapped values [-776,-1] and [-13276,-778] are not used.394 // in this compression scheme, only 4 significant digits are retained (to allow room for the exponent)395 // technically, the maximum value should be 2,768,499 since this maps to -32768. But this is of396 // little consequence. If you have individual pixel values on the detector that are that large, you need397 // to re-think your experiment.398 Function Decompress(val)399 Variable val400 401 Variable i4,npw,ipw,ib,nd402 403 ib=10404 nd=4405 ipw=ib^nd406 i4=val407 408 if (i4 <= -ipw)409 npw=trunc(-i4/ipw)410 i4=mod(-i4,ipw)*(ib^npw)411 return i4412 else413 return i4414 endif415 End416 417 //****************418 //main entry procedure for reading a "WORK.DIV" file419 //displays a quick image of the file, to check that it's correct420 //data is deposited in root:DIV data folder421 //422 Proc ReadWork_DIV()423 // Silent 1424 425 String fname = PromptForPath("Select detector sensitivity file")426 ReadHeaderAndWork("DIV",fname) //puts what is read in work.div427 428 String waveStr = "root:DIV:data"429 NewImage/F/K=1/S=2 $waveStr //this is an experimental IGOR operation430 ModifyImage '' ctab= {*,*,YellowHot,0}431 //Display;AppendImage $waveStr432 433 //change the title string to WORK.DIV, rather than PLEXnnn_TST_asdfa garbage434 String/G root:DIV:fileList = "WORK.DIV"435 436 SetDataFolder root: //(redundant)437 // Silent 0438 End439 440 //testing procedure that is not called anymore and is out-of-date441 //with the new data structures. update before re-implementing442 Proc ReadBinaryWork() //this procedure is not called anymore443 444 // Silent 1445 446 //make sure the globals are reset properly447 Variable/G root:myGlobals:gIsLogScale=0 //image is linearly scaled to begin with448 String/G root:myGlobals:gDataDisplayType="RAW" //displayed data type is raw449 450 //each routine is responsible for checking the current (displayed) data folder451 //selecting it, and returning to root when done452 453 ReadHeaderAndWork()454 455 SetDataFolder root:RAW456 //data is displayed here457 Display;AppendImage data458 459 // Silent 0460 461 //data folder was changed from root in this macro462 SetDataFolder root:463 End464 465 //this function is the guts of reading a rinary VAX file of real (4-byte) values466 // (i.e. a WORK.aaa file)467 // work files have the same header structure as RAW SANS data, just with468 //different data (real, rather than compressed integer data)469 //470 //************471 //this routine incorrectly reads in several data values where the VAX record472 //marker splits the 4-byte real (at alternating record markers)473 //this error seems to not be severe, but shoud be corrected (at great pain)474 //************475 //476 Function ReadHeaderAndWork(type,fname)477 String type,fname478 479 //type is the desired folder to read the workfile to480 //this data will NOT be automatically displayed gDataDisplayType is unchanged481 482 // SVAR cur_folder=root:myGlobals:gDataDisplayType483 String cur_folder = type484 String curPath = "root:"+cur_folder485 SetDataFolder curPath //use the full path, so it will always work486 487 Variable refNum,integer,realval488 String sansfname,textstr489 Variable/G $(curPath + ":gIsLogScale") = 0 //initial state is linear, keep this in DIV folder490 491 Make/O/N=23 $(curPath + ":IntegersRead")492 Make/O/N=52 $(curPath + ":RealsRead")493 Make/O/T/N=11 $(curPath + ":TextRead")494 495 WAVE intw=$(curPath + ":IntegersRead")496 WAVE realw=$(curPath + ":RealsRead")497 WAVE/T textw=$(curPath + ":TextRead")498 499 //***NOTE ****500 // the "current path" gets mysteriously reset to "root:" after the SECOND pass through501 // this read routine, after the open dialog is presented502 // the "--read" waves end up in the correct folder, but the data does not! Why?503 //must re-set data folder before writing data array (done below)504 505 SetDataFolder curPath506 507 //actually open the file508 Open/R refNum as fname509 //skip first two bytes510 FSetPos refNum, 2511 //read the next 21 bytes as characters (fname)512 FReadLine/N=21 refNum,textstr513 textw[0]= textstr514 //read four i*4 values /F=3 flag, B=3 flag515 FBinRead/F=3/B=3 refNum, integer516 intw[0] = integer517 //518 FBinRead/F=3/B=3 refNum, integer519 intw[1] = integer520 //521 FBinRead/F=3/B=3 refNum, integer522 intw[2] = integer523 //524 FBinRead/F=3/B=3 refNum, integer525 intw[3] = integer526 // 6 text fields527 FSetPos refNum,55 //will start reading at byte 56528 FReadLine/N=20 refNum,textstr529 textw[1]= textstr530 FReadLine/N=3 refNum,textstr531 textw[2]= textstr532 FReadLine/N=11 refNum,textstr533 textw[3]= textstr534 FReadLine/N=1 refNum,textstr535 textw[4]= textstr536 FReadLine/N=8 refNum,textstr537 textw[5]= textstr538 FReadLine/N=60 refNum,textstr539 textw[6]= textstr540 541 //3 integers542 FSetPos refNum,174543 FBinRead/F=3/B=3 refNum, integer544 intw[4] = integer545 FBinRead/F=3/B=3 refNum, integer546 intw[5] = integer547 FBinRead/F=3/B=3 refNum, integer548 intw[6] = integer549 550 //2 integers, 3 text fields551 FSetPos refNum,194552 FBinRead/F=3/B=3 refNum, integer553 intw[7] = integer554 FBinRead/F=3/B=3 refNum, integer555 intw[8] = integer556 FReadLine/N=6 refNum,textstr557 textw[7]= textstr558 FReadLine/N=6 refNum,textstr559 textw[8]= textstr560 FReadLine/N=6 refNum,textstr561 textw[9]= textstr562 563 //2 integers564 FSetPos refNum,244565 FBinRead/F=3/B=3 refNum, integer566 intw[9] = integer567 FBinRead/F=3/B=3 refNum, integer568 intw[10] = integer569 570 //2 integers571 FSetPos refNum,308572 FBinRead/F=3/B=3 refNum, integer573 intw[11] = integer574 FBinRead/F=3/B=3 refNum, integer575 intw[12] = integer576 577 //2 integers578 FSetPos refNum,332579 FBinRead/F=3/B=3 refNum, integer580 intw[13] = integer581 FBinRead/F=3/B=3 refNum, integer582 intw[14] = integer583 584 //3 integers585 FSetPos refNum,376586 FBinRead/F=3/B=3 refNum, integer587 intw[15] = integer588 FBinRead/F=3/B=3 refNum, integer589 intw[16] = integer590 FBinRead/F=3/B=3 refNum, integer591 intw[17] = integer592 593 //1 text field594 FSetPos refNum,404595 FReadLine/N=42 refNum,textstr596 textw[10]= textstr597 598 //1 integer599 FSetPos refNum,458600 FBinRead/F=3/B=3 refNum, integer601 intw[18] = integer602 603 //4 integers604 FSetPos refNum,478605 FBinRead/F=3/B=3 refNum, integer606 intw[19] = integer607 FBinRead/F=3/B=3 refNum, integer608 intw[20] = integer609 FBinRead/F=3/B=3 refNum, integer610 intw[21] = integer611 FBinRead/F=3/B=3 refNum, integer612 intw[22] = integer613 614 Close refNum615 616 //now get all of the reals617 //618 //Do all the GBLoadWaves at the end619 //620 //FBinRead Cannot handle 32 bit VAX floating point621 //GBLoadWave, however, can properly read it622 String GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=2/W=1/Q"623 String strToExecute624 //append "/S=offset/U=numofreals" to control the read625 // then append fname to give the full file path626 // then execute627 628 Variable a=0,b=0629 630 SetDataFolder curPath631 // 4 R*4 values632 strToExecute = GBLoadStr + "/S=39/U=4" + "\"" + fname + "\""633 Execute strToExecute634 635 SetDataFolder curPath636 Wave w=$(curPath + ":tempGBWave0")637 b=4 //num of reals read638 realw[a,a+b-1] = w[p-a]639 a+=b640 641 // 4 R*4 values642 SetDataFolder curPath643 strToExecute = GBLoadStr + "/S=158/U=4" + "\"" + fname + "\""644 Execute strToExecute645 b=4646 realw[a,a+b-1] = w[p-a]647 a+=b648 649 ///////////650 // 2 R*4 values651 SetDataFolder curPath652 strToExecute = GBLoadStr + "/S=186/U=2" + "\"" + fname + "\""653 Execute strToExecute654 b=2655 realw[a,a+b-1] = w[p-a]656 a+=b657 658 // 6 R*4 values659 SetDataFolder curPath660 strToExecute = GBLoadStr + "/S=220/U=6" + "\"" + fname + "\""661 Execute strToExecute662 b=6663 realw[a,a+b-1] = w[p-a]664 a+=b665 666 // 13 R*4 values667 SetDataFolder curPath668 strToExecute = GBLoadStr + "/S=252/U=13" + "\"" + fname + "\""669 Execute strToExecute670 b=13671 realw[a,a+b-1] = w[p-a]672 a+=b673 674 // 3 R*4 values675 SetDataFolder curPath676 strToExecute = GBLoadStr + "/S=320/U=3" + "\"" + fname + "\""677 Execute strToExecute678 b=3679 realw[a,a+b-1] = w[p-a]680 a+=b681 682 // 7 R*4 values683 SetDataFolder curPath684 strToExecute = GBLoadStr + "/S=348/U=7" + "\"" + fname + "\""685 Execute strToExecute686 b=7687 realw[a,a+b-1] = w[p-a]688 a+=b689 690 // 4 R*4 values691 SetDataFolder curPath692 strToExecute = GBLoadStr + "/S=388/U=4" + "\"" + fname + "\""693 Execute strToExecute694 b=4695 realw[a,a+b-1] = w[p-a]696 a+=b697 698 // 2 R*4 values699 SetDataFolder curPath700 strToExecute = GBLoadStr + "/S=450/U=2" + "\"" + fname + "\""701 Execute strToExecute702 b=2703 realw[a,a+b-1] = w[p-a]704 a+=b705 706 // 2 R*4 values707 SetDataFolder curPath708 strToExecute = GBLoadStr + "/S=470/U=2" + "\"" + fname + "\""709 Execute strToExecute710 b=2711 realw[a,a+b-1] = w[p-a]712 a+=b713 714 // 5 R*4 values715 SetDataFolder curPath716 strToExecute = GBLoadStr + "/S=494/U=5" + "\"" + fname + "\""717 Execute strToExecute718 b=5719 realw[a,a+b-1] = w[p-a]720 721 //if the binary VAX data ws transferred to a MAC, all is OK722 //if the data was trasnferred to an Intel machine (IBM), all the real values must be723 //divided by 4 to get the correct floating point values724 // I can't find any combination of settings in GBLoadWave or FBinRead to read data in correctly725 // on an Intel machine.726 //With the corrected version of GBLoadWave XOP (v. 1.43 or higher) Mac and PC both read727 //VAX reals correctly, and no checking is necessary 12 APR 99728 //if(cmpstr("Macintosh",IgorInfo(2)) == 0)729 //do nothing730 //else731 //either Windows or Windows NT732 //realw /= 4733 //endif734 735 //read in the data736 GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=2/W=1/Q"737 738 curPath = "root:"+cur_folder739 SetDataFolder curPath //use the full path, so it will always work740 741 Make/O/N=16384 $(curPath + ":data")742 WAVE data = $(curPath + ":data")743 744 Variable skip,ii,offset745 746 //read in a total of 16384 values (ii)747 //as follows :748 // skip first 2 bytes749 // skip 512 byte header750 // skip first 2 bytes of data751 //(read 511 reals, skip 2b, 510 reals, skip 2b) -16 times = 16336 values752 // read the final 48 values in seperately to avoid EOF error753 754 /////////////755 SetDataFolder curPath756 skip = 0757 ii=0758 offset = 514 +2759 a=0760 do761 SetDataFolder curPath762 763 strToExecute = GBLoadStr + "/S="+num2str(offset)+"/U=511" + "\"" + fname + "\""764 Execute strToExecute765 //Print strToExecute766 b=511767 data[a,a+b-1] = w[p-a]768 a+=b769 770 offset += 511*4 +2771 772 strToExecute = GBLoadStr + "/S="+num2str(offset)+"/U=510" + "\"" + fname + "\""773 SetDataFolder curPath774 Execute strToExecute775 //Print strToExecute776 b=510777 data[a,a+b-1] = w[p-a]778 a+=b779 780 offset += 510*4 +2781 782 ii+=1783 //Print "inside do, data[2] =",data[2]784 //Print "inside do, tempGBwave0[0] = ",w[0]785 while(ii<16)786 787 // 16336 values have been read in --788 //read in last 64 values789 strToExecute = GBLoadStr + "/S="+num2str(offset)+"/U=48" + "\"" + fname + "\""790 791 SetDataFolder curPath792 Execute strToExecute793 b=48794 data[a,a+b-1] = w[p-a]795 a+=b796 //797 /// done reading in raw data798 //799 //Print "in workdatareader , data = ", data[1][1]800 801 Redimension/n=(128,128) data802 803 //clean up - get rid of w = $"tempGBWave0"804 KillWaves w805 806 //divide the FP data by 4 if read from a PC (not since GBLoadWave update)807 //if(cmpstr("Macintosh",IgorInfo(2)) == 0)808 //do nothing809 //else810 //either Windows or Windows NT811 //data /= 4812 //endif813 814 //keep a string with the filename in the DIV folder815 String/G $(curPath + ":fileList") = textw[0]816 817 //return the data folder to root818 SetDataFolder root:819 820 Return(0)821 End822 823 //returns the path to the file, or null if cancel824 Function/S DoOpenFileDialog(msg)825 String msg826 827 Variable refNum828 // String message = "Select a file"829 String outputPath830 831 Open/D/R/T="????"/M=msg refNum832 outputPath = S_fileName833 834 return outputPath835 End836 837 // returns the path to the file, or null if the user cancelled838 Function/S DoSaveFileDialog(msg)839 String msg840 Variable refNum841 // String message = "Save the file as"842 String outputPath843 844 Open/D/M=msg refNum845 outputPath = S_fileName846 847 return outputPath848 End -
sans/SANSReduction/branches/kline_29MAR07/Put in User Procedures/SANS_Reduction_v5.00/SANSPreferences.ipf
r41 r69 88 88 // SetVariable setvar3,limits={1,2000,1},value= root:myGlobals:gNPixelsY 89 89 90 End Macro90 End 91 91 -
sans/SANSReduction/branches/kline_29MAR07/Put in User Procedures/SANS_Reduction_v5.00/Transmission.ipf
r47 r69 1807 1807 End 1808 1808 1809 //****************** 1810 //lookup tables for attenuator transmissions 1811 //NG3 and NG7 attenuators are physically different, so the transmissions are slightly different 1812 //NG1 - (8m SANS) is not supported 1813 1814 Proc MakeNG3AttenTable() 1815 1816 NewDataFolder/O root:myGlobals:Attenuators 1817 //do explicitly to avoid data folder problems, redundant, but it must work without fail 1818 Make/O/N=9 root:myGlobals:Attenuators:ng3att0 1819 Make/O/N=9 root:myGlobals:Attenuators:ng3att1 1820 Make/O/N=9 root:myGlobals:Attenuators:ng3att2 1821 Make/O/N=9 root:myGlobals:Attenuators:ng3att3 1822 Make/O/N=9 root:myGlobals:Attenuators:ng3att4 1823 Make/O/N=9 root:myGlobals:Attenuators:ng3att5 1824 Make/O/N=9 root:myGlobals:Attenuators:ng3att6 1825 Make/O/N=9 root:myGlobals:Attenuators:ng3att7 1826 Make/O/N=9 root:myGlobals:Attenuators:ng3att8 1827 Make/O/N=9 root:myGlobals:Attenuators:ng3att9 1828 Make/O/N=9 root:myGlobals:Attenuators:ng3att10 1829 1830 //each wave has 8 elements, the transmission of att# at the wavelengths 1831 //lambda = 5,6,7,8,10,12,14,17 1832 Make/O/N=9 root:myGlobals:Attenuators:ng3lambda={5,6,7,8,10,12,14,17,20} 1833 root:myGlobals:Attenuators:ng3att0 = {1, 1, 1, 1, 1, 1, 1, 1,1 } 1834 root:myGlobals:Attenuators:ng3att1 = {0.421, 0.394, 0.371, 0.349, 0.316, 0.293, 0.274, 0.245,0.220} 1835 root:myGlobals:Attenuators:ng3att2 = {0.187, 0.164, 0.145, 0.130, 0.106, 0.0916, 0.0808, 0.0651,0.0531} 1836 root:myGlobals:Attenuators:ng3att3 = {0.0777, 0.0636, 0.0534, 0.0446, 0.0330, 0.0262, 0.0217, 0.0157 ,0.0116} 1837 root:myGlobals:Attenuators:ng3att4 = {0.0328, 0.0252, 0.0195, 0.0156, 0.0104, 7.68e-3, 5.98e-3, 3.91e-3,0.00262} 1838 root:myGlobals:Attenuators:ng3att5 = {0.0139, 9.94e-3, 7.34e-3, 5.44e-3, 3.29e-3, 2.25e-3, 1.66e-3, 9.95e-4, 6.12e-4} 1839 root:myGlobals:Attenuators:ng3att6 = {5.95e-3, 3.97e-3, 2.77e-3, 1.95e-3, 1.06e-3, 6.81e-4, 4.71e-4, 2.59e-4 , 1.45e-4} 1840 root:myGlobals:Attenuators:ng3att7 = {1.07e-3, 6.24e-4, 3.90e-4, 2.44e-4, 1.14e-4, 6.55e-5, 4.10e-5, 1.64e-5 , 7.26e-6} 1841 root:myGlobals:Attenuators:ng3att8 = {1.90e-4, 9.84e-5, 5.60e-5, 3.25e-5, 1.55e-5, 6.60e-6, 3.42e-6, 1.04e-6 , 3.48e-7} 1842 root:myGlobals:Attenuators:ng3att9 = {3.61e-5, 1.74e-5, 9.90e-6, 6.45e-6, 2.35e-6, 6.35e-7, 2.86e-7, 6.61e-8 , 1.73e-8} 1843 root:myGlobals:Attenuators:ng3att10 = {7.60e-6, 3.99e-6, 2.96e-6, 2.03e-6, 3.34e-7, 6.11e-8, 2.39e-8, 4.19e-9 , 8.60e-10} 1844 1845 End 1846 1847 Proc MakeNG7AttenTable() 1848 1849 NewDataFolder/O root:myGlobals:Attenuators 1850 1851 Make/O/N=9 root:myGlobals:Attenuators:ng7att0 1852 Make/O/N=9 root:myGlobals:Attenuators:ng7att1 1853 Make/O/N=9 root:myGlobals:Attenuators:ng7att2 1854 Make/O/N=9 root:myGlobals:Attenuators:ng7att3 1855 Make/O/N=9 root:myGlobals:Attenuators:ng7att4 1856 Make/O/N=9 root:myGlobals:Attenuators:ng7att5 1857 Make/O/N=9 root:myGlobals:Attenuators:ng7att6 1858 Make/O/N=9 root:myGlobals:Attenuators:ng7att7 1859 Make/O/N=9 root:myGlobals:Attenuators:ng7att8 1860 Make/O/N=9 root:myGlobals:Attenuators:ng7att9 1861 Make/O/N=9 root:myGlobals:Attenuators:ng7att10 1862 1863 //each wave has 8 elements, the transmission of att# at the wavelengths 1864 //lambda = 5,6,7,8,10,12,14,17 1865 Make/O/N=9 root:myGlobals:Attenuators:ng7lambda={5,6,7,8,10,12,14,17,20} 1866 root:myGlobals:Attenuators:ng7att0 = {1, 1, 1, 1, 1, 1, 1, 1 ,1} 1867 root:myGlobals:Attenuators:ng7att1 = {0.418, 0.393, 0.369, 0.347, 0.313, 0.291, 0.271, 0.244, 0.219 } 1868 root:myGlobals:Attenuators:ng7att2 = {0.189, 0.167, 0.148, 0.132, 0.109, 0.0945, 0.0830, 0.0681, 0.0560} 1869 root:myGlobals:Attenuators:ng7att3 = {0.0784, 0.0651, 0.0541, 0.0456, 0.0340, 0.0273, 0.0223, 0.0164 , 0.0121} 1870 root:myGlobals:Attenuators:ng7att4 = {0.0328, 0.0256, 0.0200, 0.0159, 0.0107, 7.98e-3, 6.14e-3, 4.09e-3 , 0.00274} 1871 root:myGlobals:Attenuators:ng7att5 = {0.0139, 0.0101, 7.43e-3, 5.58e-3, 3.42e-3, 2.36e-3, 1.70e-3, 1.03e-3 , 6.27e-4} 1872 root:myGlobals:Attenuators:ng7att6 = {5.90e-3, 4.07e-3, 2.79e-3, 1.99e-3, 1.11e-3, 7.13e-4, 4.91e-4, 2.59e-4 , 1.42e-4} 1873 root:myGlobals:Attenuators:ng7att7 = {1.04e-3, 6.37e-4, 3.85e-4, 2.46e-4, 1.16e-4, 6.86e-5, 4.10e-5, 1.64e-5 ,7.02e-6} 1874 root:myGlobals:Attenuators:ng7att8 = {1.90e-4, 1.03e-4, 5.71e-5, 3.44e-5, 1.65e-5, 6.60e-6, 3.42e-6, 1.04e-6 , 3.48e-7} 1875 root:myGlobals:Attenuators:ng7att9 = {3.58e-5, 1.87e-5, 1.05e-5, 7.00e-6, 2.35e-6, 6.35e-7, 2.86e-7, 6.61e-8 , 1.73e-8} 1876 root:myGlobals:Attenuators:ng7att10 = {7.76e-6, 4.56e-6, 3.25e-6, 2.03e-6, 3.34e-7, 6.11e-8, 2.39e-8, 4.19e-9, 8.60e-10} 1877 1878 End 1879 1880 //returns the transmission of the attenuator (at NG3) given the attenuator number 1881 //which must be an integer(to select the wave) and given the wavelength. 1882 //the wavelength may be any value between 5 and 20 (A), and is interpolated 1883 //between calibrated wavelengths for a given attenuator 1884 Function LookupAttenNG3(lambda,attenNo) 1885 Variable lambda, attenNo 1886 1887 Variable trans 1888 String attStr="root:myGlobals:Attenuators:ng3att"+num2str(trunc(attenNo)) 1889 String lamStr = "root:myGlobals:Attenuators:ng3lambda" 1890 1891 if(attenNo == 0) 1892 return (1) //no attenuation, return trans == 1 1893 endif 1894 1895 if( (lambda < 5) || (lambda > 20 ) ) 1896 Abort "Wavelength out of calibration range (5,20). You must manually enter the absolute parameters" 1897 Endif 1898 1899 if(!(WaveExists($attStr)) || !(WaveExists($lamStr)) ) 1900 Execute "MakeNG3AttenTable()" 1901 Endif 1902 //just in case creating the tables fails.... 1903 if(!(WaveExists($attStr)) || !(WaveExists($lamStr)) ) 1904 Abort "Attenuator lookup waves could not be found. You must manually enter the absolute parameters" 1905 Endif 1906 1907 //lookup the value by interpolating the wavelength 1908 //the attenuator must always be an integer 1909 Wave att = $attStr 1910 Wave lam = $lamstr 1911 trans = interp(lambda,lam,att) 1912 1913 // Print "trans = ",trans 1914 1915 return trans 1916 End 1917 1918 //returns the transmission of the attenuator (at NG7) given the attenuator number 1919 //which must be an integer(to select the wave) and given the wavelength. 1920 //the wavelength may be any value between 5 and 20 (A), and is interpolated 1921 //between calibrated wavelengths for a given attenuator 1922 // 1923 // this set of tables is also used for NG5 (NG1) SANS instrument - as the attenuator has yet to be calibrated 1924 Function LookupAttenNG7(lambda,attenNo) 1925 Variable lambda, attenNo 1926 1927 Variable trans 1928 String attStr="root:myGlobals:Attenuators:ng7att"+num2str(trunc(attenNo)) 1929 String lamStr = "root:myGlobals:Attenuators:ng7lambda" 1930 1931 if(attenNo == 0) 1932 return (1) //no attenuation, return trans == 1 1933 endif 1934 1935 if( (lambda < 5) || (lambda > 20 ) ) 1936 Abort "Wavelength out of calibration range (5,20). You must manually enter the absolute parameters" 1937 Endif 1938 1939 if(!(WaveExists($attStr)) || !(WaveExists($lamStr)) ) 1940 Execute "MakeNG7AttenTable()" 1941 Endif 1942 //just in case creating the tables fails.... 1943 if(!(WaveExists($attStr)) || !(WaveExists($lamStr)) ) 1944 Abort "Attenuator lookup waves could not be found. You must manually enter the absolute parameters" 1945 Endif 1946 1947 //lookup the value by interpolating the wavelength 1948 //the attenuator must always be an integer 1949 Wave att = $attStr 1950 Wave lam = $lamstr 1951 trans = interp(lambda,lam,att) 1952 1953 //Print "trans = ",trans 1954 1955 return trans 1956 1957 End 1958 1959 //returns the proper attenuation factor based on the instrument (NG3, NG5, or NG7) 1960 //NG5 values are taken from the NG7 tables (there is very little difference in the 1961 //values, and NG5 attenuators have not been calibrated (as of 8/01) 1962 //filestr as passed is textread[3], the default directory 1963 Function AttenuationFactor(fileStr,lam,attenNo) 1964 String fileStr 1965 Variable lam,attenNo 1966 1967 Variable attenFactor=1,loc 1968 String instr=fileStr[1,3] //filestr is "[NGnSANSn] " or "[NGnSANSnn]" (11 characters total) 1969 1970 strswitch(instr) 1971 case "NG3": 1972 attenFactor = LookupAttenNG3(lam,attenNo) 1973 break 1974 case "NG5": 1975 //using NG7 lookup Table 1976 attenFactor = LookupAttenNG7(lam,attenNo) 1977 break 1978 case "NG7": 1979 attenFactor = LookupAttenNG7(lam,attenNo) 1980 break 1981 default: 1982 //return error? 1983 attenFactor=1 1984 endswitch 1985 // print "instr, lambda, attenNo,attenFactor = ",instr,lam,attenNo,attenFactor 1986 return(attenFactor) 1987 End 1809 1988 1810 1989 1811 //******************* -
sans/SANSReduction/branches/kline_29MAR07/Put in User Procedures/SANS_Reduction_v5.00/VAXFileUtils.ipf
r47 r69 3 3 #pragma IgorVersion=4.0 4 4 5 //**************************6 // Vers. 1.2 0921017 //8 //this file is a collection of uilities for processing vax filenames9 //and processing lists (especially for display in popup menus)10 //11 //required to correctly account for VAX supplied version numbers, which12 //may or may not be removed by the ftp utility13 //14 // - parses lists of run numbers into real filenames15 // - selects proper detector constants16 //17 //**************************18 19 20 //given a filename of a SANS data filename of the form21 //TTTTTnnn.SAn_TTT_Txxx22 //returns the run number "nnn" as a number23 //returns -1 as an invalid file number24 Function GetRunNumFromFile(item)25 String item26 Variable invalid = -1 //negative numbers are invalid27 Variable num=-128 29 //find the "dot"30 String runStr=""31 Variable pos = strsearch(item,".",0)32 if(pos == -1)33 //"dot" not found34 return (invalid)35 else36 //found, get the three characters preceeding it37 if (pos <=2)38 //not enough characters39 return (invalid)40 else41 runStr = item[pos-3,pos-1]42 //convert to a number43 num = str2num(runStr)44 //if valid, return it45 if (num == NaN)46 //3 characters were not a number47 return (invalid)48 else49 //run was OK50 return (num)51 Endif52 Endif53 Endif54 End55 56 //given a filename of a SANS data filename of the form57 //TTTTTnnn.SAn_TTT_Txxx58 //returns the run number "nnn" as a STRING of THREE characters59 //returns "ABC" as an invalid file number60 Function/S GetRunNumStrFromFile(item)61 String item62 String invalid = "ABC" //"ABC" is not a valid run number, since it's text63 Variable num=-164 65 //find the "dot"66 String runStr=""67 Variable pos = strsearch(item,".",0)68 if(pos == -1)69 //"dot" not found70 return (invalid)71 else72 //found, get the three characters preceeding it73 if (pos <=2)74 //not enough characters75 return (invalid)76 else77 runStr = item[pos-3,pos-1]78 return (runStr)79 Endif80 Endif81 End82 83 //returns a string containing the full path and file to the file containing the84 //run number "num". The null string is returned if no valid file can be found85 //the path "catPathName" used and is hard-wired, will abort if this path does not exist86 //the file returned will be a RAW SANS data file, other types of files are87 //filtered out.88 Function/S FindFileFromRunNumber(num)89 Variable num90 91 String fullName="",partialName="",item=""92 //get list of raw data files in folder that match "num" (add leading zeros)93 if( (num>999) || (num<=0) )94 //Print "error in FindFileFromRunNumber(num), file number too large or too small"95 Return ("")96 Endif97 //make a three character string of the run number98 String numStr=""99 if(num<10)100 numStr = "00"+num2str(num)101 else102 if(num<100)103 numStr = "0"+num2str(num)104 else105 numStr = num2str(num)106 Endif107 Endif108 //Print "numstr = ",numstr109 110 //make sure that path exists111 PathInfo catPathName112 String path = S_path113 if (V_flag == 0)114 Abort "folder path does not exist - use Pick Path button"115 Endif116 String list="",newList="",testStr=""117 118 list = IndexedFile(catPathName,-1,"????") //get all files in folder119 //find (the) one with the number in the run # location in the name120 Variable numItems,ii,runFound,isRAW121 numItems = ItemsInList(list,";") //get the new number of items in the list122 ii=0123 do124 //parse through the list in this order:125 // 1 - does item contain run number (as a string) "TTTTTnnn.SAn_XXX_Tyyy"126 // 2 - exclude by isRaw? (to minimize disk access)127 item = StringFromList(ii, list ,";" )128 if(strlen(item) != 0)129 //find the run number, if it exists as a three character string130 testStr = GetRunNumStrFromFile(item)131 runFound= cmpstr(numStr,testStr) //compare the three character strings, 0 if equal132 if(runFound == 0)133 //the run Number was found134 //build valid filename135 partialName = FindValidFileName(item)136 if(strlen(partialName) != 0) //non-null return from FindValidFileName()137 fullName = path + partialName138 //check if RAW, if so,this must be the file!139 isRAW = CheckIfRawData(fullName)140 if(isRaw)141 //stop here142 return(fullname)143 Endif144 Endif145 Endif146 Endif147 ii+=1148 while(ii<numItems) //process all items in list149 Return ("") //null return if file not found in list150 End151 152 //function to test a binary file to see if it is a RAW binary SANS file153 //first checks the total bytes in the file (which for raw data is 33316 bytes)154 //**note that the "DIV" file will also show up as a raw file by the run field155 //should be listed in CAT/SHORT and in patch windows156 //157 //Function then checks the file fname (full path:file) for "RAW" run.type field158 //if not found, the data is not raw data and zero is returned159 Function CheckIfRawData(fname)160 String fname161 162 Variable refnum,totalBytes163 String testStr=""164 165 Open/R/T="????TEXT" refNum as fname166 //get the total number of bytes in the file, to avoid moving past EOF167 FStatus refNum168 totalBytes = V_logEOF169 //Print totalBytes170 if(totalBytes!=33316)171 //can't possibly be a raw data file172 Close refnum173 return(0) //not a raw SANS file174 Endif175 FSetPos refNum,75176 FReadLine/N=3 refNum,testStr177 Close refNum178 179 if(cmpstr(testStr,"RAW")==0)180 //true, is raw data file181 Return(1)182 else183 //some other file184 Return(0)185 Endif186 End187 188 //function to remove all spaces from names when searching for filenames189 //the filename (as saved) will never have interior spaces (TTTTTnnn_AB _Bnnn)190 //but the text field in the header WILL, if less than 3 characters were used for the191 //user's initials, and can have leading spaces if prefix was less than 5 characters192 //193 //returns a string identical to the original string, except with the interior spaces removed194 //195 Function/S RemoveAllSpaces(str)196 String str197 198 String tempstr = str199 Variable ii,spc,len //should never be more than 2 or 3 trailing spaces in a filename200 ii=0201 do202 len = strlen(tempStr)203 spc = strsearch(tempStr," ",0) //is the last character a space?204 if (spc == -1)205 break //no more spaces found, get out206 endif207 str = tempstr208 tempStr = str[0,(spc-1)] + str[(spc+1),(len-1)] //remove the space from the string209 While(1) //should never be more than 2 or 3210 211 If(strlen(tempStr) < 1)212 tempStr = "" //be sure to return a null string if problem found213 Endif214 215 //Print strlen(tempstr)216 217 Return(tempStr)218 219 End220 221 222 //Function attempts to find valid filename from partial name that has been stripped of223 //the VAX version number. The partial name is tried first224 //*** the PATH is hard-wired to catPathName (which is assumed to exist)225 //version numers up to ;10 are tried226 //only the "name;vers" is returned. the path is not prepended, hence the return string227 //is not a complete specification of the file228 //229 // added 11/99 - uppercase and lowercase versions of the file are tried, if necessary230 // since from marquee, the filename field (textread[0]) must be used, and can be a mix of231 // upper/lowercase letters, while the filename on the server (should) be all caps232 // now makes repeated calls to ValidFileString()233 //234 Function/S FindValidFilename(partialName)235 String PartialName236 237 String retStr=""238 239 //try name with no changes - to allow for ABS files that have spaces in the names 12APR04240 retStr = ValidFileString(partialName)241 if(cmpstr(retStr,"") !=0)242 //non-null return243 return(retStr)244 Endif245 246 //if the partial name is derived from the file header, there can be spaces at the beginning247 //or in the middle of the filename - depending on the prefix and initials used248 //249 //remove any leading spaces from the name before starting250 partialName = RemoveAllSpaces(partialName)251 252 //try name with no spaces253 retStr = ValidFileString(partialName)254 if(cmpstr(retStr,"") !=0)255 //non-null return256 return(retStr)257 Endif258 259 //try all UPPERCASE260 partialName = UpperStr(partialName)261 retStr = ValidFileString(partialName)262 if(cmpstr(retStr,"") !=0)263 //non-null return264 return(retStr)265 Endif266 267 //try all lowercase (ret null if failure)268 partialName = LowerStr(partialName)269 retStr = ValidFileString(partialName)270 if(cmpstr(retStr,"") !=0)271 //non-null return272 return(retStr)273 else274 return(retStr)275 Endif276 End277 278 //Function attempts to find valid filename from partial name that has been stripped of279 //the VAX version number. The partial name is tried first280 //*** the PATH is hard-wired to catPathName (which is assumed to exist)281 //version numers up to ;10 are tried282 //only the "name;vers" is returned. the path is not prepended, hence the return string283 //is not a complete specification of the file284 //285 Function/S ValidFileString(partialName)286 String partialName287 288 String tempName = "",msg=""289 Variable ii,refnum290 291 ii=0292 do293 if(ii==0)294 //first pass, try the partialName295 tempName = partialName296 Open/Z/R/T="????TEXT"/P=catPathName refnum tempName //Does open file (/Z flag)297 if(V_flag == 0)298 //file exists299 Close refnum //YES needed,300 break301 endif302 else303 tempName = partialName + ";" + num2str(ii)304 Open/Z/R/T="????TEXT"/P=catPathName refnum tempName305 if(V_flag == 0)306 //file exists307 Close refnum308 break309 endif310 Endif311 ii+=1312 //print "ii=",ii313 while(ii<11)314 //go get the selected bits of information, using tempName, which exists315 if(ii>=11)316 //msg = partialName + " not found. is version number > 11?"317 //DoAlert 0, msg318 //PathInfo catPathName319 //Print S_Path320 Return ("") //use null string as error condition321 Endif322 323 Return (tempName)324 End325 5 326 6 327 7 328 //the following is a WaveMetrics procedure from <StrMatchList>329 // MatchList(matchStr,list,sep)330 // Returns the items of the list whose items match matchStr331 // The lists are separated by the sep character, usually ";"332 //333 // matchStr may be something like "abc", in which case it is identical to CmpStr334 // matchStr may also be "*" to match anything, "abc*" to match anything starting with "abc",335 // "*abc" to match anything ending with "abc".336 // matchStr may also begin with "!" to indicate a match to anything not matching the rest of337 // the pattern.338 // At most one "*" and one "!" are allowed in matchStr, otherwise the results are not guaranteed.339 //340 Function/S MyMatchList(matchStr,list,sep)341 String matchStr,list,sep342 String item,outList=""343 Variable n=strlen(list)344 Variable en,st=0345 do346 en= strsearch(list,sep,st)347 if( en < 0 )348 if( st < n-1 )349 en= n // no trailing separator350 sep="" // don't put sep in output, either351 else352 break // no more items in list353 endif354 endif355 item=list[st,en-1]356 if( MyStrMatch(matchStr,item) == 0 )357 outlist += item+sep358 Endif359 st=en+1360 while (st < n ) // exit is by break, above361 return outlist362 End363 364 //the following is a WaveMetrics procedure from <StrMatchList>365 // StrMatch(matchStr,str)366 // Returns 0 if the pattern in matchStr matches str, else it returns 1367 //368 // matchStr may be something like "abc", in which case it is identical to CmpStr369 // matchStr may also be "*" to match anything, "abc*" to match anything starting with "abc",370 // "*abc" to match anything ending with "abc".371 // matchStr may also begin with "!" to indicate a match to anything not matching the rest of372 // the pattern.373 // At most one "*" and one "!" are allowed in matchStr, otherwise the results are not guaranteed.374 //375 Function MyStrMatch(matchStr,str)376 String matchStr,str377 Variable match = 1 // 0 means match378 Variable invert= strsearch(matchStr,"!",0) == 0379 if( invert )380 matchStr[0,0]="" // remove the "!"381 endif382 Variable st=0,en=strlen(str)-1383 Variable starPos= strsearch(matchStr,"*",0)384 if( starPos >= 0 ) // have a star385 if( starPos == 0 ) // at start386 matchStr[0,0]="" // remove star at start387 else // at end388 matchStr[starPos,999999]="" // remove star and rest of (ignored, illegal) pattern389 endif390 Variable len=strlen(matchStr)391 if( len > 0 )392 if(starPos == 0) // star at start, match must be at end393 st=en-len+1394 else395 en=len-1 // star at end, match at start396 endif397 else398 str="" // so that "*" matches anything399 endif400 endif401 match= !CmpStr(matchStr,str[st,en])==0 // 1 or 0402 if( invert )403 match= 1-match404 endif405 return match406 End407 408 409 //returns a string containing filename (WITHOUT the ;vers)410 //the input string is a full path to the file (Mac-style, still works on Win in IGOR)411 //with the folders separated by colons412 Function/S GetFileNameFromPathNoSemi(fullPath)413 String fullPath414 415 Variable offset1,offset2416 String filename=""417 //String PartialPath418 offset1 = 0419 do420 offset2 = StrSearch(fullPath, ":", offset1)421 if (offset2 == -1) // no more colons ?422 fileName = FullPath[offset1,strlen(FullPath) ]423 //PartialPath = FullPath[0, offset1-1]424 break425 endif426 offset1 = offset2+1427 while (1)428 429 //remove version number from name, if it's there - format should be: filename;N430 filename = StringFromList(0,filename,";") //returns null if error431 432 Return filename433 End434 435 //returns a string containing filename (INCLUDING the ;vers)436 //the input string is a full path to the file (Mac-style, still works on Win in IGOR)437 //with the folders separated by colons438 Function/S GetFileNameFromPathKeepSemi(fullPath)439 String fullPath440 441 Variable offset1,offset2442 String filename443 //String PartialPath444 offset1 = 0445 do446 offset2 = StrSearch(fullPath, ":", offset1)447 if (offset2 == -1) // no more colons ?448 fileName = FullPath[offset1,strlen(FullPath) ]449 //PartialPath = FullPath[0, offset1-1]450 break451 endif452 offset1 = offset2+1453 while (1)454 455 //keep version number from name, if it's there - format should be: filename;N456 457 Return filename458 End459 460 //given the full path and filename (fullPath), strips the data path461 //(Mac-style, separated by colons) and returns this path462 //this partial path is the same string that would be returned from PathInfo, for example463 Function/S GetPathStrFromfullName(fullPath)464 String fullPath465 466 Variable offset1,offset2467 //String filename468 String PartialPath469 offset1 = 0470 do471 offset2 = StrSearch(fullPath, ":", offset1)472 if (offset2 == -1) // no more colons ?473 //fileName = FullPath[offset1,strlen(FullPath) ]474 PartialPath = FullPath[0, offset1-1]475 break476 endif477 offset1 = offset2+1478 while (1)479 480 Return PartialPath481 End482 483 //given the VAX filename, pull off the first 8 characters to make a valid484 //file string that can be used for naming averaged 1-d files485 Function/S GetNameFromHeader(fullName)486 String fullName487 String temp, newName = ""488 Variable spc,ii=0489 490 //filename is 20 characters NNNNNxxx.SAn_NNN_NNN491 //want the first 8 characters, NNNNNxxx, then strip off any spaces at the beginning492 //NNNNN was entered as less than 5 characters493 //returns a null string if no name can be found494 do495 temp = fullname[ii,7] //characters ii,7 of the name496 spc = strsearch(temp," ",0)497 if (spc == -1)498 break //no more spaces found499 endif500 ii+=1501 While(ii<8)502 503 If(strlen(temp) < 1)504 newName = "" //be sure to return a null string if problem found505 else506 newName = temp507 Endif508 509 Return(newName)510 End511 512 //list (input) is a list, typically returned from IndexedFile()513 //which is semicolon-delimited, and may contain filesnames from the VAX514 //that contain version numbers, where the version number appears as a separate list item515 //(and also as a non-existent file)516 //these numbers must be purged from the list, especially for display in a popup517 //or list processing of filenames518 //the function returns the list, cleaned of version numbers (up to 11)519 //raw data files will typically never have a version number other than 1.520 Function/S RemoveVersNumsFromList(list)521 String list522 523 //get rid of version numbers first (up to 11)524 Variable ii,num525 String item526 num = ItemsInList(list,";")527 ii=1528 do529 item = num2str(ii)530 list = RemoveFromList(item, list ,";" )531 ii+=1532 while(ii<12)533 534 return (list)535 End536 537 //input is a list of run numbers, and output is a list of filenames (not the full path)538 //*** input list must be COMMA delimited***539 //output is equivalent to selecting from the CAT table540 //if some or all of the list items are valid filenames, keep them...541 //if an error is encountered, notify of the offending element and return the null list542 //543 //output is COMMA delimited544 //545 // this routine is expecting that the "ask", "none" special cases are handled elsewhere546 //and not passed here547 Function/S ParseRunNumberList(list)548 String list549 550 String newList="",item="",tempStr=""551 Variable num,ii,runNum552 553 //expand number ranges, if any554 list = ExpandNumRanges(list)555 556 num=itemsinlist(list,",")557 558 for(ii=0;ii<num;ii+=1)559 //get the item560 item = StringFromList(ii,list,",")561 //is it already a valid filename?562 tempStr=FindValidFilename(item) //returns filename if good, null if error563 if(strlen(tempstr)!=0)564 //valid name, add to list565 //Print "it's a file"566 newList += tempStr + ","567 else568 //not a valid name569 //is it a number?570 runNum=str2num(item)571 //print runnum572 if(numtype(runNum) != 0)573 //not a number - maybe an error574 DoAlert 0,"List item "+item+" is not a valid run number or filename. Please enter a valid number or filename."575 return("")576 else577 //a run number or an error578 tempStr = GetFileNameFromPathNoSemi( FindFileFromRunNumber(runNum) )579 if(strlen(tempstr)==0)580 //file not found, error581 DoAlert 0,"List item "+item+" is not a valid run number. Please enter a valid number."582 return("")583 else584 newList += tempStr + ","585 endif586 endif587 endif588 endfor //loop over all items in list589 590 return(newList)591 End592 593 //takes a comma delimited list that MAY contain number range, and594 //expands any range of run numbers into a comma-delimited list...595 //and returns the new list - if not a range, return unchanged596 Function/S ExpandNumRanges(list)597 String list598 599 String newList="",dash="-",item,str600 Variable num,ii,hasDash601 602 num=itemsinlist(list,",")603 // print num604 for(ii=0;ii<num;ii+=1)605 //get the item606 item = StringFromList(ii,list,",")607 //does it contain a dash?608 hasDash = strsearch(item,dash,0) //-1 if no dash found609 if(hasDash == -1)610 //not a range, keep it in the list611 newList += item + ","612 else613 //has a dash (so it's a range), expand (or add null)614 newList += ListFromDash(item)615 endif616 endfor617 618 return newList619 End620 621 //be sure to add a trailing comma to the return string...622 Function/S ListFromDash(item)623 String item624 625 String numList="",loStr="",hiStr=""626 Variable lo,hi,ii627 628 loStr=StringFromList(0,item,"-") //treat the range as a list629 hiStr=StringFromList(1,item,"-")630 lo=str2num(loStr)631 hi=str2num(hiStr)632 if( (numtype(lo) != 0) || (numtype(hi) !=0 ) || (lo > hi) )633 numList=""634 return numList635 endif636 for(ii=lo;ii<=hi;ii+=1)637 numList += num2str(ii) + ","638 endfor639 640 Return numList641 End642 643 644 //****************645 //utilities for handling binary data - prompting for files or paths,646 //moving data from one folder to another (within IGOR)647 //and converting data to log or linear scale648 649 650 //prompts user to choose the local folder that contains the SANS Data651 //only one folder can be used, and its path is catPathName (and is a NAME, not a string)652 //this will overwrite the path selection653 //returns 1 if no path selected as error condition, or if user cancelled654 Function PickPath()655 656 //set the global string to the selected pathname657 NewPath/O/M="pick the SANS data folder" catPathName658 if(V_Flag != 0)659 return(1) //user cancelled660 endif661 662 PathInfo/S catPathName663 String dum = S_path664 String alertStr = ""665 alertStr = "You must set the path to Charlotte through a Mapped Network Drive, not through the Network Neighborhood"666 //alertStr += " Please see the manual for details."667 if (V_flag == 0)668 //path does not exist - no folder selected669 String/G root:myGlobals:gCatPathStr = "no folder selected"670 return(1)671 else672 //set the global to the path (as a string)673 // need 4 \ since it is the escape character674 if(cmpstr("\\\\",dum[0,1])==0) //Windoze user going through network neighborhood675 DoAlert 0,alertStr676 KillPath catPathName677 return(1)678 endif679 String/G root:myGlobals:gCatPathStr = dum680 // these are now set in theire respective procedures, since the folders don't exist yet!681 // String/G root:myGlobals:Patch:gCatPathStr = dum //and the global used by Patch and Trans682 // String/G root:myGlobals:TransHeaderInfo:gCatPathStr = dum //and the global used by Patch and Trans683 return(0) //no error684 endif685 End686 687 //a utility function that prompts the user for a file (of any type)688 //and returns the full path:name;vers string required to open the file689 //the file is NOT opened by this routine (/D flag)690 //a null string is returned if no file is selected691 //"msgStr" is the message displayed in the dialog, informing the user what692 //file is desired693 //694 Function/S PromptForPath(msgStr)695 String msgStr696 String fullPath697 Variable refnum698 699 //this just asks for the filename, doesn't open the file700 Open/D/R/T="????"/M=(msgStr) refNum701 fullPath = S_FileName //fname is the full path702 // Print refnum,fullPath703 704 //null string is returned in S_FileName if user cancelled, and is passed back to calling function705 Return(fullPath)706 End707 708 709 //returns a string containg the transmision stored in the file that is710 //currently in the "type" folder (not from the binary header)711 //returns "none" if the value (in RealsRead) cannot be found712 //713 Function/S GetTrans(type)714 String type715 716 String name="root:"+type+":realsread"717 WAVE reals = $name718 if(waveExists(reals))719 return(num2str(reals[4]))720 else721 return("none")722 endif723 End724 725 //returns a string containg the sample thickness stored in the file that is726 //currently in the "type" folder (not from the binary header)727 //returns "none" if the value (in RealsRead) cannot be found728 //729 Function/S GetThick(type)730 String type731 732 String name="root:"+type+":realsread"733 WAVE reals = $name734 if(waveExists(reals))735 return(num2str(reals[5]))736 else737 return("none")738 endif739 End740 741 //procedure is not called from anywhere, for debugging purposes only742 //not for gerneral users, since it Kills data folders, requiring743 //re-initialization of the experiment744 //745 Proc ClearWorkFolders()746 747 //not foolproof - will generage an error if any wavs, etc.. are in use.748 KillDataFolder root:RAW749 KillDataFolder root:SAM750 KillDataFolder root:EMP751 KillDataFolder root:BGD752 KillDataFolder root:COR753 KillDataFolder root:DIV754 KillDataFolder root:MSK755 KillDataFolder root:ABS756 KillDataFolder root:CAL757 SetDataFolder root:758 759 End760 761 //not used - but potentially very useful for ensuring that old762 // data in work folders is not accidentally being used763 //764 Function ClearWorkFolder(type)765 String type766 767 SetDataFolder $("root:"+type)768 KillWaves/A/Z769 KillStrings/A/Z770 KillVariables/A/Z771 772 SetDataFolder root:773 End774 775 776 //procedure is not called from anywhere, for debugging purposes only777 //not for gerneral users, but could be useful in reducon clutter778 //779 Proc ClearRootFolder()780 781 DoAlert 1,"Are you sure you want to delete everything from the root level?"782 SetDataFolder root:783 KillWaves/A/Z784 KillStrings/A/Z785 KillVariables/A/Z786 787 End788 789 ///*****************790 //unused testing procedure for writing a 4 byte floating point value in VAX format791 Proc TestReWriteReal()792 String Path793 Variable value,start794 795 GetFileAndPath()796 Path = S_Path + S_filename797 798 value = 0.2222799 start = 158 //trans starts at byte 159800 ReWriteReal(path,value,start)801 802 SetDataFolder root:803 End804 805 //function will re-write a real value (4bytes) to the header of a RAW data file806 //to ensure re-readability, the real value must be written mimicking VAX binary format807 //which is done in this function808 //path is the full path:file;vers to the file809 //value is the real value to write810 //start is the position to move the file marker to, to begin writing811 //--so start is actually the "end byte" of the previous value812 //813 //this procedure takes care of all file open/close pairs needed814 //815 Function ReWriteReal(path,value,start)816 String path817 Variable value,start818 819 //Print " in F(), path = " + path820 Variable refnum,int1,int2, value4821 822 //////823 value4 = 4*value824 825 Open/A/T="????TEXT" refnum as path826 //write IEEE FP, 4*desired value827 FSetPos refnum,start828 FBinWrite/B=3/F=4 refnum,value4 //write out as little endian829 830 //move to the end of the file831 FStatus refnum832 FSetPos refnum,V_logEOF833 //Print "Wrote end of header to " + num2str(V_filePOS)834 835 Close refnum836 837 ///////838 Open/R refnum as path839 //read back as two 16-bit integers840 FSetPos refnum,start841 FBinRead/B=2/F=2 refnum,int1 //read as big-endian842 FBinRead/B=2/F=2 refnum,int2843 844 //file was opened read-only845 //no need to move to the end of the file, just close it846 847 Close refnum848 ///////849 Open/A/T="????TEXT" refnum as path850 //write the two 16-bit integers, reversed851 FSetPos refnum,start852 FBinWrite/B=2/F=2 refnum,int2 //re-write as big endian853 FBinWrite/B=2/F=2 refnum,int1854 855 //move to the end of the file856 FStatus refnum857 FSetPos refnum,V_logEOF858 //Print "Wrote end of header to " + num2str(V_filePOS)859 860 Close refnum //at this point, it is as the VAX would have written it.861 862 Return(0)863 End864 865 //Utility function that returns the detector resolution (in cm) given information866 //from the file header867 //Global values are set in the Initialize procedure868 Function DetectorPixelResolution(fileStr,detStr)869 String fileStr,detStr870 871 Variable DDet872 String instr=fileStr[1,3] //filestr is "[NGnSANSn] " or "[NGnSANSnn]" (11 characters total)873 874 NVAR PixelResNG3_ILL = root:myGlobals:PixelResNG3_ILL //pixel resolution in cm875 NVAR PixelResNG5_ILL = root:myGlobals:PixelResNG5_ILL876 NVAR PixelResNG7_ILL = root:myGlobals:PixelResNG7_ILL877 NVAR PixelResNG3_ORNL = root:myGlobals:PixelResNG3_ORNL878 NVAR PixelResNG5_ORNL = root:myGlobals:PixelResNG5_ORNL879 NVAR PixelResNG7_ORNL = root:myGlobals:PixelResNG7_ORNL880 NVAR PixelResDefault = root:myGlobals:PixelResDefault881 882 strswitch(instr)883 case "NG3":884 if(cmpstr(detStr, "ILL ") == 0 )885 DDet= PixelResNG3_ILL886 else887 DDet = PixelResNG3_ORNL //detector is ordella-type888 endif889 break890 case "NG5":891 if(cmpstr(detStr, "ILL ") == 0 )892 DDet= PixelResNG5_ILL893 else894 DDet = PixelResNG5_ORNL //detector is ordella-type895 endif896 break897 case "NG7":898 if(cmpstr(detStr, "ILL ") == 0 )899 DDet= PixelResNG7_ILL900 else901 DDet = PixelResNG7_ORNL //detector is ordella-type902 endif903 break904 default:905 //return error?906 DDet = PixelResDefault //5mm, typical for new ORNL detectors907 endswitch908 909 return(DDet)910 End911 912 //Utility function that returns the detector deadtime (in seconds) given information913 //from the file header914 //Global values are set in the Initialize procedure915 Function DetectorDeadtime(fileStr,detStr)916 String fileStr,detStr917 918 Variable deadtime919 String instr=fileStr[1,3] //filestr is "[NGnSANSn] " or "[NGnSANSnn]" (11 characters total)920 921 NVAR DeadtimeNG3_ILL = root:myGlobals:DeadtimeNG3_ILL //pixel resolution in cm922 NVAR DeadtimeNG5_ILL = root:myGlobals:DeadtimeNG5_ILL923 NVAR DeadtimeNG7_ILL = root:myGlobals:DeadtimeNG7_ILL924 NVAR DeadtimeNG3_ORNL = root:myGlobals:DeadtimeNG3_ORNL925 NVAR DeadtimeNG5_ORNL = root:myGlobals:DeadtimeNG5_ORNL926 NVAR DeadtimeNG7_ORNL = root:myGlobals:DeadtimeNG7_ORNL927 NVAR DeadtimeDefault = root:myGlobals:DeadtimeDefault928 929 strswitch(instr)930 case "NG3":931 if(cmpstr(detStr, "ILL ") == 0 )932 deadtime= DeadtimeNG3_ILL933 else934 deadtime = DeadtimeNG3_ORNL //detector is ordella-type935 endif936 break937 case "NG5":938 if(cmpstr(detStr, "ILL ") == 0 )939 deadtime= DeadtimeNG5_ILL940 else941 deadtime = DeadtimeNG5_ORNL //detector is ordella-type942 endif943 break944 case "NG7":945 if(cmpstr(detStr, "ILL ") == 0 )946 deadtime= DeadtimeNG7_ILL947 else948 deadtime = DeadtimeNG7_ORNL //detector is ordella-type949 endif950 break951 default:952 //return error?953 deadtime = DeadtimeDefault //1e-6 seconds, typical for new ORNL detectors954 endswitch955 956 return(deadtime)957 End958 959 //////////////////////960 // "intelligent" differentiation of the data files based on information gathered while961 // getting the FIle Catalog. Uses some waves that are generated there, but not displayed in the table962 //963 // See CatVSTable.ipf for where these files are created (and sorted to keep them together)964 ////////////965 966 //testing - unused967 //968 Function/S TextWave2SemiList(textW)969 Wave/T textW970 971 String list=""972 Variable num=numpnts(textW),ii=0973 do974 list += textw[ii] + ";"975 ii+=1976 while(ii<num)977 return(list)978 End979 980 Function/S NumWave2CommaList(numW)981 Wave numW982 983 String list=""984 Variable num=numpnts(numW),ii=0985 do986 list += num2Str(numW[ii]) + ","987 ii+=1988 while(ii<num)989 return(list)990 End991 992 // utility function to convert a list (string) of semicolon-delimited993 //items to a text wave994 Function List2TextWave(str,tw)995 String str996 wave/T tw997 998 Variable num=ItemsinList(str,";"),ii=0999 Redimension/N=(num) tw1000 do1001 tw[ii] = StringFromList(ii, str ,";")1002 ii+=11003 while(ii<num)1004 return(0)1005 1006 End1007 1008 // generates a list of the procedure files in the experiment1009 // putting the results in a wave named "tw", editing and sorting the wave1010 //1011 Proc ListIncludedFiles()1012 Make/O/T/N=2 tw1013 String str=""1014 //str = WinList("*", ";","INCLUDE:6")1015 str = WinList("*", ";","WIN:128")1016 List2TextWave(str,tw)1017 Edit tw1018 Sort tw tw1019 End1020 1021 // returns a comma delimited list of run numbers based on the run numbers collected1022 // during the building of the File Catalog (why do it twice)1023 Function/S RunNumberList()1024 1025 Wave w= $"root:myGlobals:CatVSHeaderInfo:RunNumber"1026 String list=""1027 if(WaveExists(w) == 0)1028 list = ""1029 else1030 list=NumWave2CommaList(w)1031 endif1032 return(list)1033 End1034 1035 // list is a comma delimited list of run numbers, from the File Catalog1036 // - scan through the list and remove numbers that are not transmission files1037 //1038 Function/S isTransList(list)1039 String list1040 1041 //scan through the list, find the corresponding point number, and see what isTrans says1042 Variable ii,num,temp1043 String newList=""1044 num=ItemsInList(list ,",")1045 for(ii=0;ii<num;ii+=1)1046 temp = str2num( StringFromList(ii, list ,",") )1047 if(RunNumIsTransFile(temp))1048 newList += num2str(temp) + ","1049 endif1050 endfor1051 1052 return(newList)1053 End1054 1055 //truth if run number is a transmission file1056 // based on whatever is currently in the File Catalog1057 //1058 // Can't use findlevel - it assumes a monotonic RunNumber wave1059 Function RunNumIsTransFile(num)1060 Variable num1061 1062 Wave isTrans = $"root:myGlobals:CatVSHeaderInfo:IsTrans"1063 Wave RunNumber = $"root:myGlobals:CatVSHeaderInfo:RunNumber"1064 1065 if( (WaveExists(isTrans) == 0 ) || (WaveExists(RunNumber) == 0 ) )1066 return(0)1067 endif1068 1069 Variable pts=numpnts(RunNumber),ii1070 for(ii=0;ii<pts;ii+=1)1071 if(RunNumber[ii] == num)1072 return(isTrans[ii])1073 endif1074 endfor1075 // FindLevel/P/Q RunNumber,num1076 //1077 // if(isTrans[V_LevelX]==1)1078 // return(1)1079 // else1080 // return(0)1081 // endif1082 End1083 1084 //truth if run number is at the given sample to detector distance1085 // based on whatever is currently in the File Catalog1086 //1087 // need fuzzy comparison, since SDD = 1.33 may actually be represented in FP as 1.33000004 !!!1088 Function RunNumIsAtSDD(num,sdd)1089 Variable num,sdd1090 1091 Wave w = $"root:myGlobals:CatVSHeaderInfo:SDD"1092 Wave RunNumber = $"root:myGlobals:CatVSHeaderInfo:RunNumber"1093 1094 if( (WaveExists(w) == 0 ) || (WaveExists(RunNumber) == 0 ) )1095 return(0)1096 endif1097 Variable pts=numpnts(RunNumber),ii1098 for(ii=0;ii<pts;ii+=1)1099 if(RunNumber[ii] == num)1100 if(abs(w[ii] - sdd) < 0.001 ) //if numerically within 0.001 meter, they're the same1101 return(1)1102 else1103 return(0)1104 endif1105 endif1106 endfor1107 End1108 1109 1110 // list is a comma delimited list of run numbers, from the File Catalog1111 // - scan through the list and remove numbers that are not at the specified SDD1112 //1113 Function/S atSDDList(list,sdd)1114 String list1115 Variable sdd1116 1117 //scan through the list, find the corresponding point number, and see what SDD the run is at1118 Variable ii,num,temp1119 String newList=""1120 num=ItemsInList(list ,",")1121 for(ii=0;ii<num;ii+=1)1122 temp = str2num( StringFromList(ii, list ,",") )1123 if(RunNumIsAtSDD(temp,sdd))1124 newList += num2str(temp) + ","1125 endif1126 endfor1127 1128 return(newList)1129 End1130 1131 //given a comma-delimited list, remove those that are trans files1132 //1133 Function/S removeTrans(list)1134 String list1135 1136 //scan through the list, and remove those that are trans files1137 Variable ii,num,temp1138 // String newList=""1139 num=ItemsInList(list ,",")1140 for(ii=0;ii<num;ii+=1)1141 temp = str2num( StringFromList(ii, list ,",") )1142 if(RunNumIsTransFile(temp))1143 list = RemoveFromList(num2str(temp),list,",")1144 ii -= 1 //item ii was just deleted (everything moves to fill in)1145 num -= 1 // and the list is shorter now1146 endif1147 endfor1148 1149 return(list)1150 End1151 1152 Function setMREDFileList(str)1153 String str1154 1155 SVAR/Z list = root:myGlobals:MRED:gFileNumList1156 if(SVAR_Exists(list)==0) //check for myself1157 DoAlert 0,"The Multiple Reduce Panel must be open for you to use this function"1158 Return(1)1159 endif1160 1161 list = str1162 1163 //force an update If the SVAR exists, then the panel does too - MRED cleans up after itself when done1164 DoWindow/F Multiple_Reduce_Panel //bring to front1165 MRedPopMenuProc("MRFilesPopup",0,"") //parse the list, pop the menu1166 1167 return(0)1168 End1169 1170 Proc FillEMPUsingSelection()1171 FillEMPFilenameWSelection()1172 End1173 1174 Proc GuessEveryTransFiles(num)1175 Variable num=61176 GuessAllTransFiles(num)1177 End1178 1179 Proc GuessSelectedTransFiles(num)1180 Variable num=61181 fGuessSelectedTransFiles(num)1182 End1183 1184 Proc ClearSelectedTransAssignments()1185 ClearSelectedAssignments()1186 End1187 1188 Proc CreateRunNumList()1189 String/G rStr=""1190 rStr=RunNumberList()1191 Print "The list is stored in root:rStr"1192 print rStr1193 End1194 1195 Proc TransList()1196 String/G rStr=""1197 rStr=RunNumberList()1198 rStr=isTransList(rStr)1199 print rStr1200 End1201 1202 Proc ScatteringAtSDDList(sdd)1203 Variable sdd=131204 1205 String/G rStr=""1206 rStr=RunNumberList()1207 rStr=removeTrans(rStr)1208 rStr=atSDDList(rStr,sdd)1209 1210 //for Igor 4, the search is case-sensitive, so use all permutations1211 // in Igor 5, use the proper flag in strsearch() inside FindStringInLabel()1212 rStr = RemoveEmptyBlocked(rStr,"EMPTY")1213 rStr = RemoveEmptyBlocked(rStr,"Empty")1214 rStr = RemoveEmptyBlocked(rStr,"empty")1215 rStr = RemoveEmptyBlocked(rStr,"MT Cell")1216 rStr = RemoveEmptyBlocked(rStr,"MT CELL")1217 rStr = RemoveEmptyBlocked(rStr,"mt cell")1218 rStr = RemoveEmptyBlocked(rStr,"BLOCKED")1219 rStr = RemoveEmptyBlocked(rStr,"Blocked")1220 rStr = RemoveEmptyBlocked(rStr,"blocked")1221 1222 print rStr1223 End1224 1225 Proc FillMREDList()1226 setMREDFileList(rStr)1227 DoUpdate1228 End1229 1230 //num passed in is the run number, as in the list1231 // ii is the index of all of the files from the catalog1232 //return will be -1 if string not found, >=0 if found1233 //1234 Function FindStringInLabel(num,findThisStr)1235 Variable num1236 String findThisStr1237 1238 Wave/T w = $"root:myGlobals:CatVSHeaderInfo:Labels"1239 Wave RunNumber = $"root:myGlobals:CatVSHeaderInfo:RunNumber"1240 1241 if( (WaveExists(w) == 0 ) || (WaveExists(RunNumber) == 0 ) )1242 return(0)1243 endif1244 1245 Variable pts=numpnts(RunNumber),ii,loc1246 for(ii=0;ii<pts;ii+=1)1247 if(RunNumber[ii] == num)1248 loc = strsearch(w[ii], findThisStr, 0) //Igor 4 version is case-sensitive1249 // loc = strsearch(w[ii], findThisStr, 0 ,2) //2==case insensitive, but Igor 5 specific1250 if(loc != -1)1251 Print "Remove w[ii] = ",num," ",w[ii]1252 endif1253 endif1254 endfor1255 1256 return(loc) //return will be -1 if string not found, >=0 if found1257 end1258 1259 //rStr is the global string, already atSDD (so there should be only one instance of1260 // empty and one instance of blocked1261 //1262 //scan through the list, and remove those that are have "empty" or "blocked" in the label1263 // or anything that is listed in StrToFind1264 //1265 Function/S RemoveEmptyBlocked(list,StrToFind)1266 String list,StrToFind1267 1268 Variable ii,num,temp1269 num=ItemsInList(list ,",")1270 for(ii=0;ii<num;ii+=1)1271 temp = str2num( StringFromList(ii, list ,",") )1272 if(FindStringInLabel(temp,StrToFind) != -1)1273 list = RemoveFromList(num2str(temp),list,",")1274 ii -= 1 //item ii was just deleted (everything moves to fill in)1275 num -= 1 // and the list is shorter now1276 endif1277 endfor1278 //print list1279 return(list)1280 end1281 1282 // input is a single run number to remove from the list1283 // - typically EC and BN - before sending to MRED1284 Proc RemoveRunFromList(remList)1285 String remList=""1286 1287 rStr = RemoveFromList(remList, rStr ,",")1288 end -
sans/SANSReduction/branches/kline_29MAR07/Put in User Procedures/SANS_Reduction_v5.00/WriteQIS.ipf
r60 r69 7 7 // 8 8 //************************ 9 10 11 //***this function is not used - WriteWaves_W_Protocol() is used instead12 //13 //for writing out data (q-i-s) from the "type" folder14 //if fullpath is a complete HD path:filename, no dialog will be presented15 //if fullpath is just a filename, the save dialog will be presented (forced if dialog =1)16 //writes ONLY the standard header information (no protocol information)17 //18 Function WriteWaves(type,fullpath,dialog)19 String type,fullpath20 Variable dialog //=1 will present dialog for name21 22 String destStr=""23 destStr = "root:"+type24 25 Variable refNum26 String formatStr = "%15.4g %15.4g %15.4g %15.4g %15.4g %15.4g\r\n"27 String fname,ave="C",headerFormat = "%10.4g %8.2g %8.2g %8.2g %8.3g %8.3g %8s %5.0g\r\n"28 Variable step=129 30 //*****these waves MUST EXIST, or IGOR Pro will crash, with a type 2 error****31 WAVE intw=$(destStr + ":integersRead")32 WAVE rw=$(destStr + ":realsRead")33 WAVE/T textw=$(destStr + ":textRead")34 WAVE qvals =$(destStr + ":qval")35 WAVE inten=$(destStr + ":aveint")36 WAVE sig=$(destStr + ":sigave")37 WAVE qbar = $(destStr + ":QBar")38 WAVE sigmaq = $(destStr + ":SigmaQ")39 WAVE fsubs = $(destStr + ":fSubS")40 41 //check each wave42 If(!(WaveExists(intw)))43 Abort "intw DNExist BinaryWrite()"44 Endif45 If(!(WaveExists(rw)))46 Abort "rw DNExist BinaryWrite()"47 Endif48 If(!(WaveExists(textw)))49 Abort "textw DNExist BinaryWrite()"50 Endif51 If(!(WaveExists(qvals)))52 Abort "qvals DNExist BinaryWrite()"53 Endif54 If(!(WaveExists(inten)))55 Abort "inten DNExist BinaryWrite()"56 Endif57 If(!(WaveExists(sig)))58 Abort "sig DNExist BinaryWrite()"59 Endif60 If(!(WaveExists(qbar)))61 Abort "qbar DNExist BinaryWrite()"62 Endif63 If(!(WaveExists(sigmaq)))64 Abort "sigmaq DNExist BinaryWrite()"65 Endif66 If(!(WaveExists(fsubs)))67 Abort "fsubs DNExist BinaryWrite()"68 Endif69 70 if(dialog)71 PathInfo/S catPathName72 fullPath = DoSaveFileDialog("Save data as")73 If(cmpstr(fullPath,"")==0)74 //user cancel, don't write out a file75 Close/A76 Abort "no data file was written"77 Endif78 //Print "dialog fullpath = ",fullpath79 Endif80 81 //actually open the file82 Open refNum as fullpath83 84 fprintf refnum,"FILE: %s\t\t CREATED: %s\r\n",textw[0],textw[1]85 fprintf refnum,"LABEL: %s\r\n",textw[6]86 fprintf refnum,"MON CNT LAMBDA DET ANG DET DIST TRANS THICK AVE STEP\r\n"87 fprintf refnum,headerFormat,rw[0],rw[26],rw[19],rw[18],rw[4],rw[5],ave,step88 wfprintf refnum, formatStr, qvals,inten,sig,sigmaq,qbar,fsubs89 90 Close refnum91 92 SetDataFolder root: //(redundant)93 94 Return(0)95 End96 97 9 98 10 //for writing out data (q-i-s) from the "type" folder, and including reduction information … … 539 451 End 540 452 541 //**********************542 // Resolution calculation - used by the averaging routines543 // to calculate the resolution function at each q-value544 // - the return value is not used545 //546 // equivalent to John's routine on the VAX Q_SIGMA_AVE.FOR547 // Incorporates eqn. 3-15 from J. Appl. Cryst. (1995) v. 28 p105-114548 //549 // - 21 MAR 07 uses projected BS diameter on the detector550 //551 Function/S getResolution(inQ,lambda,lambdaWidth,DDet,apOff,S1,S2,L1,L2,BS,del_r,SigmaQ,QBar,fSubS)552 Variable inQ, lambda, lambdaWidth, DDet, apOff, S1, S2, L1, L2, BS, del_r553 Variable &fSubS, &QBar, &SigmaQ //these are the output quantities at the input Q value554 555 //lots of calculation variables556 Variable a2, q_small, lp, v_lambda, v_b, v_d, vz, yg, v_g557 Variable r0, delta, inc_gamma, fr, fv, rmd, v_r1, rm, v_r558 559 //Constants560 //Variable del_r = .1561 Variable vz_1 = 3.956e5 //velocity [cm/s] of 1 A neutron562 Variable g = 981.0 //gravity acceleration [cm/s^2]563 564 String results565 results ="Failure"566 567 //rename for working variables, these must be gotten from global568 //variables569 570 // Variable wLam, wLW, wL1, wL2, wS1, wS2571 // Variable wBS, wDDet, wApOff572 // wLam = lambda573 // wLW = lambdaWidth574 // wDDet = DDet575 // wApOff = apOff576 S1 *= 0.5*0.1 //convert to radius and [cm]577 S2 *= 0.5*0.1578 579 L1 *= 100.0 // [cm]580 L1 -= apOff //correct the distance581 582 L2 *= 100.0583 L2 += apOff584 del_r *= 0.1 //width of annulus, convert mm to [cm]585 586 BS *= 0.5*0.1 //nominal BS diameter passed in, convert to radius and [cm]587 // 21 MAR 07 SRK - use the projected BS diameter, based on a point sample aperture588 Variable LB589 LB = 20.1 + 1.61*BS //distance in cm from beamstop to anode plane (empirical)590 BS = bs + bs*lb/(l2-lb) //adjusted diameter of shadow from parallax591 592 //Start resolution calculation593 a2 = S1*L2/L1 + S2*(L1+L2)/L1594 q_small = 2.0*Pi*(BS-a2)*(1.0-lambdaWidth)/(lambda*L2)595 lp = 1.0/( 1.0/L1 + 1.0/L2)596 597 v_lambda = lambdaWidth^2/6.0598 v_b = 0.25*(S1*L2/L1)^2 +0.25*(S2*L2/lp)^2599 v_d = (DDet/2.3548)^2 + del_r^2/12.0600 vz = vz_1 / lambda601 yg = 0.5*g*L2*(L1+L2)/vz^2602 v_g = 2.0*yg^2*v_lambda603 604 r0 = L2*tan(2.0*asin(lambda*inQ/(4.0*Pi) ))605 delta = 0.5*(BS - r0)^2/v_d606 607 if (r0 < BS)608 inc_gamma=exp(gammln(1.5))*(1-gammp(1.5,delta))609 else610 inc_gamma=exp(gammln(1.5))*(1+gammp(1.5,delta))611 endif612 613 fSubS = 0.5*(1.0+erf( (r0-BS)/sqrt(2.0*v_d) ) )614 if (fSubS <= 0.0)615 fSubS = 1.e-10616 endif617 fr = 1.0 + sqrt(v_d)*exp(-1.0*delta) /(r0*fSubS*sqrt(2.0*Pi))618 fv = inc_gamma/(fSubS*sqrt(Pi)) - r0^2*(fr-1.0)^2/v_d619 620 rmd = fr*r0621 v_r1 = v_b + fv*v_d +v_g622 623 rm = rmd + 0.5*v_r1/rmd624 v_r = v_r1 - 0.5*(v_r1/rmd)^2625 if (v_r < 0.0)626 v_r = 0.0627 endif628 QBar = (4.0*Pi/lambda)*sin(0.5*atan(rm/L2))629 SigmaQ = QBar*sqrt(v_r/rmd^2 +v_lambda)630 631 results = "success"632 Return results633 End634 453 635 454 //ASCII export of data as 3-columns qx-qy-Intensity … … 805 624 return(0) 806 625 End 626 627 628 //returns the path to the file, or null if cancel 629 Function/S DoOpenFileDialog(msg) 630 String msg 631 632 Variable refNum 633 // String message = "Select a file" 634 String outputPath 635 636 Open/D/R/T="????"/M=msg refNum 637 outputPath = S_fileName 638 639 return outputPath 640 End 641 642 // returns the path to the file, or null if the user cancelled 643 Function/S DoSaveFileDialog(msg) 644 String msg 645 Variable refNum 646 // String message = "Save the file as" 647 String outputPath 648 649 Open/D/M=msg refNum 650 outputPath = S_fileName 651 652 return outputPath 653 End 654 655 656 ////***this function is not used - WriteWaves_W_Protocol() is used instead 657 //// 658 ////for writing out data (q-i-s) from the "type" folder 659 ////if fullpath is a complete HD path:filename, no dialog will be presented 660 ////if fullpath is just a filename, the save dialog will be presented (forced if dialog =1) 661 ////writes ONLY the standard header information (no protocol information) 662 //// 663 //Function WriteWaves(type,fullpath,dialog) 664 // String type,fullpath 665 // Variable dialog //=1 will present dialog for name 666 // 667 // String destStr="" 668 // destStr = "root:"+type 669 // 670 // Variable refNum 671 // String formatStr = "%15.4g %15.4g %15.4g %15.4g %15.4g %15.4g\r\n" 672 // String fname,ave="C",headerFormat = "%10.4g %8.2g %8.2g %8.2g %8.3g %8.3g %8s %5.0g\r\n" 673 // Variable step=1 674 // 675 // //*****these waves MUST EXIST, or IGOR Pro will crash, with a type 2 error**** 676 // WAVE intw=$(destStr + ":integersRead") 677 // WAVE rw=$(destStr + ":realsRead") 678 // WAVE/T textw=$(destStr + ":textRead") 679 // WAVE qvals =$(destStr + ":qval") 680 // WAVE inten=$(destStr + ":aveint") 681 // WAVE sig=$(destStr + ":sigave") 682 // WAVE qbar = $(destStr + ":QBar") 683 // WAVE sigmaq = $(destStr + ":SigmaQ") 684 // WAVE fsubs = $(destStr + ":fSubS") 685 // 686 // //check each wave 687 // If(!(WaveExists(intw))) 688 // Abort "intw DNExist BinaryWrite()" 689 // Endif 690 // If(!(WaveExists(rw))) 691 // Abort "rw DNExist BinaryWrite()" 692 // Endif 693 // If(!(WaveExists(textw))) 694 // Abort "textw DNExist BinaryWrite()" 695 // Endif 696 // If(!(WaveExists(qvals))) 697 // Abort "qvals DNExist BinaryWrite()" 698 // Endif 699 // If(!(WaveExists(inten))) 700 // Abort "inten DNExist BinaryWrite()" 701 // Endif 702 // If(!(WaveExists(sig))) 703 // Abort "sig DNExist BinaryWrite()" 704 // Endif 705 // If(!(WaveExists(qbar))) 706 // Abort "qbar DNExist BinaryWrite()" 707 // Endif 708 // If(!(WaveExists(sigmaq))) 709 // Abort "sigmaq DNExist BinaryWrite()" 710 // Endif 711 // If(!(WaveExists(fsubs))) 712 // Abort "fsubs DNExist BinaryWrite()" 713 // Endif 714 // 715 // if(dialog) 716 // PathInfo/S catPathName 717 // fullPath = DoSaveFileDialog("Save data as") 718 // If(cmpstr(fullPath,"")==0) 719 // //user cancel, don't write out a file 720 // Close/A 721 // Abort "no data file was written" 722 // Endif 723 // //Print "dialog fullpath = ",fullpath 724 // Endif 725 // 726 // //actually open the file 727 // Open refNum as fullpath 728 // 729 // fprintf refnum,"FILE: %s\t\t CREATED: %s\r\n",textw[0],textw[1] 730 // fprintf refnum,"LABEL: %s\r\n",textw[6] 731 // fprintf refnum,"MON CNT LAMBDA DET ANG DET DIST TRANS THICK AVE STEP\r\n" 732 // fprintf refnum,headerFormat,rw[0],rw[26],rw[19],rw[18],rw[4],rw[5],ave,step 733 // wfprintf refnum, formatStr, qvals,inten,sig,sigmaq,qbar,fsubs 734 // 735 // Close refnum 736 // 737 // SetDataFolder root: //(redundant) 738 // 739 // Return(0) 740 //End
Note: See TracChangeset
for help on using the changeset viewer.