Changeset 1065 for sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS
- Timestamp:
- Sep 27, 2017 4:19:12 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/WriteHDF5.ipf
r1054 r1065 21 21 // If dialog and fullpath are left blank (0 and "", resp.), a test will be run 22 22 23 Function WriteNxCan sas(type,fullpath,dialog)23 Function WriteNxCanSAS1D(type,fullpath,dialog) 24 24 // Define input variables 25 25 String type // data location, in memory, relative to root:Packages:NIST: 26 26 String fullpath // file path and name where data will be saved 27 Variable dialog // if 0, prompt user for file path, otherwise, use fullpath27 Variable dialog // if 1, prompt user for file path, otherwise, use fullpath 28 28 29 29 // Define local function variables … … 251 251 /////////////////////////////////////////////////////////////////////////// 252 252 253 Function WriteNxCanSAS2D(type,fullpath,dialog) 254 // Define input variables 255 String type // data location, in memory, relative to root:Packages:NIST: 256 String fullpath // file path and name where data will be saved 257 Variable dialog // if 1, prompt user for file path, otherwise, use fullpath 258 259 // Define local function variables 260 Variable fileID 261 Variable step=1,refnum 262 String destStr="",typeStr="" 263 String parentBase = "/sasentry/" // HDF5 base path for all 264 String/G base = "root:NXcanSAS_file" 265 266 KillDataFolder/Z $base 267 268 // Define local waves 269 Wave/T vals,attr,attrVals,textw 270 Wave intw,rw,qvals,inten,sig,qbar,sigmaq,fsubs 271 272 // Define folder for data heirarchy 273 NewDataFolder/O/S root:NXcanSAS_file 274 275 // Check fullpath and dialog 276 if(dialog || stringmatch(fullpath, "")) 277 fileID = NxCansas_DoSaveFileDialog() 278 else 279 NxCansas_CreateFile(fullpath) 280 Endif 281 if(!fileID) 282 Print "Unable to create file at " + fullpath + "." 283 else 284 WAVE intw,rw,qvals,inten,sig,qbar,sigmaq,fsubs 285 WAVE/T textw 286 if(stringmatch(type,"")) 287 // Test values for each data set 288 Make/N=9 intw = {0,180.0,23,6254,16547,6178,22,2,0} 289 Make/N=5 rw = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} 290 Make/T/N=2 textw= {"","","","","","","","","","",""} 291 Make/N=10 qvals = {1,1,1,1,1,1,1,1,1,1} // qvals, inten, siq, qbar, sigmaq must be same length 292 Make/N=10 inten = {0,0,0,0,0,0,0,0,0,0} // qvals, inten, siq, qbar, sigmaq must be same length 293 Make/N=10 sig = {0,0,0,0,0,0,0,0,0,0} // qvals, inten, siq, qbar, sigmaq must be same length 294 Make/N=10 qbar = {0,0,0,0,0,0,0,0,0,0} // qvals, inten, siq, qbar, sigmaq must be same length 295 Make/N=10 sigmaq = {0,0,0,0,0,0,0,0,0,0} // qvals, inten, siq, qbar, sigmaq must be same length 296 Make/N=10 fsubs = {0,0,0,0,0,0,0,0,0,0} // qvals, inten, siq, qbar, sigmaq must be same length 297 else 298 destStr = "root:Packages:NIST:"+type 299 300 //must select the linear_data to export 301 NVAR isLog = $(destStr+":gIsLogScale") 302 if(isLog==1) 303 typeStr = ":linear_data" 304 else 305 typeStr = ":data" 306 endif 307 308 NVAR pixelsX = root:myGlobals:gNPixelsX 309 NVAR pixelsY = root:myGlobals:gNPixelsY 310 311 Wave data=$(destStr+typeStr) 312 Wave data_err=$(destStr+":linear_data_error") 313 WAVE intw=$(destStr + ":integersRead") 314 WAVE rw=$(destStr + ":realsRead") 315 WAVE/T textw=$(destStr + ":textRead") 316 317 endif 318 endif 319 320 /////////////////////////////////////////////////////////////////////////// 321 // Compute Qx, Qy data from pixel space 322 323 Duplicate/O data,qx_val,qy_val,z_val,qval,qz_val,phi,r_dist 324 325 Variable xctr,yctr,sdd,lambda,pixSize 326 xctr = rw[16] 327 yctr = rw[17] 328 sdd = rw[18] 329 lambda = rw[26] 330 pixSize = rw[13]/10 //convert mm to cm (x and y are the same size pixels) 331 332 qx_val = CalcQx(p+1,q+1,rw[16],rw[17],rw[18],rw[26],rw[13]/10) //+1 converts to detector coordinate system 333 qy_val = CalcQy(p+1,q+1,rw[16],rw[17],rw[18],rw[26],rw[13]/10) 334 335 Redimension/N=(pixelsX*pixelsY) qx_val,qy_val,z_val 336 337 Variable L2 = rw[18] 338 Variable BS = rw[21] 339 Variable S1 = rw[23] 340 Variable S2 = rw[24] 341 Variable L1 = rw[25] 342 Variable lambdaWidth = rw[27] 343 Variable usingLenses = rw[28] //new 2007 344 345 Variable vz_1 = 3.956e5 //velocity [cm/s] of 1 A neutron 346 Variable g = 981.0 //gravity acceleration [cm/s^2] 347 Variable m_h = 252.8 // m/h [=] s/cm^2 348 349 Variable acc,ssd,lambda0,yg_d,qstar 350 351 G = 981. //! ACCELERATION OF GRAVITY, CM/SEC^2 352 acc = vz_1 // 3.956E5 //! CONVERT WAVELENGTH TO VELOCITY CM/SEC 353 SDD = L2 *100 //1317 354 SSD = L1 *100 //1627 //cm 355 lambda0 = lambda // 15 356 YG_d = -0.5*G*SDD*(SSD+SDD)*(LAMBDA0/acc)^2 357 Print "DISTANCE BEAM FALLS DUE TO GRAVITY (CM) = ",YG_d 358 // Print "Gravity q* = ",-2*pi/lambda0*2*yg_d/sdd 359 qstar = -2*pi/lambda0*2*yg_d/sdd 360 361 362 // the gravity center is not the resolution center 363 // gravity center = beam center 364 // resolution center = offset y = dy + (2)*yg_d 365 ///************ 366 // do everything to write out the resolution too 367 // un-comment these if you want to write out qz_val and qval too, then use the proper save command 368 qval = CalcQval(p+1,q+1,rw[16],rw[17],rw[18],rw[26],rw[13]/10) 369 qz_val = CalcQz(p+1,q+1,rw[16],rw[17],rw[18],rw[26],rw[13]/10) 370 // phi = FindPhi( pixSize*((p+1)-xctr) , pixSize*((q+1)-yctr)) //(dx,dy) 371 // r_dist = sqrt( (pixSize*((p+1)-xctr))^2 + (pixSize*((q+1)-yctr))^2 ) //radial distance from ctr to pt 372 phi = FindPhi( pixSize*((p+1)-xctr) , pixSize*((q+1)-yctr)+(2)*yg_d) //(dx,dy+yg_d) 373 r_dist = sqrt( (pixSize*((p+1)-xctr))^2 + (pixSize*((q+1)-yctr)+(2)*yg_d)^2 ) //radial distance from ctr to pt 374 Redimension/N=(pixelsX*pixelsY) qz_val,qval,phi,r_dist 375 //everything in 1D now 376 Duplicate/O qval SigmaQX,SigmaQY,fsubS 377 378 379 //Two parameters DDET and APOFF are instrument dependent. Determine 380 //these from the instrument name in the header. 381 //From conversation with JB on 01.06.99 these are the current good values 382 Variable DDet 383 NVAR apOff = root:myGlobals:apOff //in cm 384 DDet = rw[10]/10 // header value (X) is in mm, want cm here 385 386 Variable ret1,ret2,ret3,nq 387 nq = pixelsX*pixelsY 388 Variable ii = 0 389 390 do 391 get2DResolution(qval[ii],phi[ii],lambda,lambdaWidth,DDet,apOff,S1,S2,L1,L2,BS,pixSize,usingLenses,r_dist[ii],ret1,ret2,ret3) 392 SigmaQX[ii] = ret1 393 SigmaQY[ii] = ret2 394 fsubs[ii] = ret3 395 ii+=1 396 while(ii<nq) 397 // 398 /////////////////////////////////////////////////////////////////////////// 399 400 401 /////////////////////////////////////////////////////////////////////////// 402 // Write all data 403 404 // Define common attribute waves 405 Make/T/N=1 empty = {""} 406 Make/T/N=1 units = {"units"} 407 Make/T/N=1 m = {"m"} 408 Make/T/N=1 mm = {"mm"} 409 Make/T/N=1 cm = {"cm"} 410 Make/T/N=1 pixel = {"pixel"} 411 Make/T/N=1 angstrom = {"angstrom"} 412 Make/T/N=1 inv_cm = {"1/cm"} 413 Make/T/N=1 inv_angstrom = {"1/angstrom"} 414 415 // Run Name and title 416 NewDataFolder/O/S $(base + ":entry1") 417 Make/T/N=1 $(base + ":entry1:title") = {textw[6]} 418 CreateStrNxCansas(fileID,parentBase,"","title",$(base + ":entry1:title"),empty,empty) 419 Make/T/N=1 $(base + ":entry1:run") = {textw[0]} 420 CreateStrNxCansas(fileID,parentBase,"","run",$(base + ":entry1:run"),empty,empty) 421 422 // TODO: Change the steps to save 2D data instead of 1D 423 424 // SASData 425 String dataParent = parentBase + "sasdata/" 426 // Create SASdata entry 427 String dataBase = base + ":entry1:sasdata" 428 NewDataFolder/O/S $(dataBase) 429 Make/O/T/N=5 $(dataBase + ":attr") = {"canSAS_class","signal","I_axes","NX_class","Q_indices"} 430 Make/O/T/N=5 $(dataBase + ":attrVals") = {"SASdata","I","Qx,Qy","NXdata","0,1"} 431 CreateStrNxCansas(fileID,dataParent,"","",empty,$(dataBase + ":attr"),$(dataBase + ":attrVals")) 432 // Create i entry 433 NewDataFolder/O/S $(dataBase + ":i") 434 Make/T/N=2 $(dataBase + ":i:attr") = {"units","uncertainties"} 435 Make/T/N=2 $(dataBase + ":i:attrVals") = {"1/cm","Idev"} 436 CreateVarNxCansas(fileID,dataParent,"sasdata","I",data,$(dataBase + ":i:attr"),$(dataBase + ":i:attrVals")) 437 // Create qx and qy entry 438 // data,qx_val,qy_val,z_val,qval,qz_val,phi,r_dist 439 NewDataFolder/O/S $(dataBase + ":qx") 440 Make/T/N=2 $(dataBase + ":qx:attr") = {"units","resolutions"} 441 Make/T/N=2 $(dataBase + ":qx:attrVals") = {"1/angstrom","Qxdev"} 442 CreateVarNxCansas(fileID,dataParent,"sasdata","Qx",qx_val,$(dataBase + ":qx:attr"),$(dataBase + ":qx:attrVals")) 443 NewDataFolder/O/S $(dataBase + ":qy") 444 Make/T/N=2 $(dataBase + ":qy:attr") = {"units","resolutions"} 445 Make/T/N=2 $(dataBase + ":qy:attrVals") = {"1/angstrom","Qydev"} 446 CreateVarNxCansas(fileID,dataParent,"sasdata","Qy",qy_val,$(dataBase + ":qy:attr"),$(dataBase + ":qy:attrVals")) 447 // Create idev entry 448 NewDataFolder/O/S $(dataBase + ":idev") 449 CreateVarNxCansas(fileID,dataParent,"sasdata","Idev",data_err,units,$(dataBase + ":idev:attrVals")) 450 // Create qdev entry 451 NewDataFolder/O/S $(dataBase + ":qxdev") 452 CreateVarNxCansas(fileID,dataParent,"sasdata","Qxdev",SigmaQX,units,inv_angstrom) 453 CreateVarNxCansas(fileID,dataParent,"sasdata","Qydev",SigmaQY,units,inv_angstrom) 454 455 // SASinstrument 456 String instrParent = parentBase + "sasinstrument/" 457 // Create SASinstrument entry 458 String instrumentBase = base + ":entry1:sasinstrument" 459 NewDataFolder/O/S $(instrumentBase) 460 Make/O/T/N=5 $(instrumentBase + ":attr") = {"canSAS_class","NX_class"} 461 Make/O/T/N=5 $(instrumentBase + ":attrVals") = {"SASinstrument","NXinstrument"} 462 CreateStrNxCansas(fileID,instrParent,"","",empty,$(instrumentBase + ":attr"),$(instrumentBase + ":attrVals")) 463 464 // SASaperture 465 String apertureParent = instrParent + "sasaperture/" 466 // Create SASaperture entry 467 String apertureBase = instrumentBase + ":sasaperture" 468 NewDataFolder/O/S $(apertureBase) 469 Make/O/T/N=5 $(apertureBase + ":attr") = {"canSAS_class","NX_class"} 470 Make/O/T/N=5 $(apertureBase + ":attrVals") = {"SASaperture","NXaperture"} 471 CreateStrNxCansas(fileID,apertureParent,"","",empty,$(apertureBase + ":attr"),$(apertureBase + ":attrVals")) 472 // Create SASaperture shape entry 473 Make/O/T/N=1 $(apertureBase + ":shape") = {"pinhole"} // TODO: Where do I get rectangular dimensions from? 474 CreateStrNxCansas(fileID,apertureParent,"sasaperture","shape",$(apertureBase + ":shape"),empty,empty) 475 // Create SASaperture x_gap entry 476 Make/O/N=1 $(apertureBase + ":x_gap") = {rw[24]} // TODO: Where do I get rectangular dimensions from? 477 CreateVarNxCansas(fileID,apertureParent,"sasaperture","x_gap",$(apertureBase + ":x_gap"),units,cm) 478 // Create SASaperture y_gap entry 479 Make/O/N=1 $(apertureBase + ":y_gap") = {rw[24]} // TODO: Where do I get rectangular dimensions from? 480 CreateVarNxCansas(fileID,apertureParent,"sasaperture","y_gap",$(apertureBase + ":y_gap"),units,cm) 481 482 // SAScollimation 483 String collimationParent = instrParent + "sascollimation/" 484 // Create SAScollimation entry 485 String collimationBase = instrumentBase + ":sascollimation" 486 NewDataFolder/O/S $(collimationBase) 487 Make/O/T/N=5 $(collimationBase + ":attr") = {"canSAS_class","NX_class"} 488 Make/O/T/N=5 $(collimationBase + ":attrVals") = {"SAScollimation","NXcollimation"} 489 CreateStrNxCansas(fileID,collimationParent,"","",empty,$(collimationBase + ":attr"),$(collimationBase + ":attrVals")) 490 // Create SAScollimation length entry 491 Make/O/N=1 $(collimationBase + ":length") = {15.3} // TODO: Get real value 492 CreateVarNxCansas(fileID,collimationParent,"sasaperture","length",$(collimationBase + ":length"),units,m) 493 // Create SAScollimation distance entry 494 Make/O/N=1 $(collimationBase + ":distance") = {rw[25]} 495 CreateVarNxCansas(fileID,collimationParent,"sasaperture","distance",$(collimationBase + ":distance"),units,m) 496 497 // SASdetector 498 String detectorParent = instrParent + "sasdetector/" 499 // Create SASdetector entry 500 String detectorBase = instrumentBase + ":sasdetector" 501 NewDataFolder/O/S $(detectorBase) 502 Make/O/T/N=5 $(detectorBase + ":attr") = {"canSAS_class","NX_class"} 503 Make/O/T/N=5 $(detectorBase + ":attrVals") = {"SASdetector","NXdetector"} 504 CreateStrNxCansas(fileID,detectorParent,"","",empty,$(detectorBase + ":attr"),$(detectorBase + ":attrVals")) 505 // Create SASdetector name entry 506 Make/O/T/N=1 $(detectorBase + ":name") = {"ORNL"} // TODO: Get real value 507 CreateStrNxCansas(fileID,detectorParent,"","name",$(detectorBase + ":name"),empty,empty) 508 // Create SASdetector distance entry 509 Make/O/N=1 $(detectorBase + ":SDD") = {rw[18]} 510 CreateVarNxCansas(fileID,detectorParent,"","SDD",$(detectorBase + ":SDD"),units,m) 511 // Create SASdetector beam_center_x entry 512 Make/O/N=1 $(detectorBase + ":beam_center_x") = {rw[16]} 513 CreateVarNxCansas(fileID,detectorParent,"","beam_center_x",$(detectorBase + ":beam_center_x"),units,pixel) 514 // Create SASdetector beam_center_y entry 515 Make/O/N=1 $(detectorBase + ":beam_center_y") = {rw[17]} 516 CreateVarNxCansas(fileID,detectorParent,"","beam_center_y",$(detectorBase + ":beam_center_y"),units,pixel) 517 // Create SASdetector x_pixel_size entry 518 Make/O/N=1 $(detectorBase + ":x_pixel_size") = {rw[10]} 519 CreateVarNxCansas(fileID,detectorParent,"","x_pixel_size",$(detectorBase + ":x_pixel_size"),units,mm) 520 // Create SASdetector y_pixel_size entry 521 Make/O/N=1 $(detectorBase + ":y_pixel_size") = {rw[13]} 522 CreateVarNxCansas(fileID,detectorParent,"","y_pixel_size",$(detectorBase + ":y_pixel_size"),units,mm) 523 524 // SASsource 525 String sourceParent = instrParent + "sassource/" 526 // Create SASdetector entry 527 String sourceBase = instrumentBase + ":sassource" 528 NewDataFolder/O/S $(sourceBase) 529 Make/O/T/N=5 $(sourceBase + ":attr") = {"canSAS_class","NX_class"} 530 Make/O/T/N=5 $(sourceBase + ":attrVals") = {"SASsource","NXsource"} 531 CreateStrNxCansas(fileID,sourceParent,"","",empty,$(sourceBase + ":attr"),$(sourceBase + ":attrVals")) 532 // Create SASsource radiation entry 533 Make/O/T/N=1 $(sourceBase + ":radiation") = {"Reactor Neutron Source"} 534 CreateStrNxCansas(fileID,sourceParent,"","radiation",$(sourceBase + ":radiation"),empty,empty) 535 // Create SASsource incident_wavelength entry 536 Make/O/N=1 $(sourceBase + ":incident_wavelength") = {rw[26]} 537 CreateVarNxCansas(fileID,sourceParent,"","incident_wavelength",$(sourceBase + ":incident_wavelength"),units,angstrom) 538 // Create SASsource incident_wavelength_spread entry 539 Make/O/N=1 $(sourceBase + ":incident_wavelength_spread") = {rw[27]} 540 CreateVarNxCansas(fileID,sourceParent,"","incident_wavelength_spread",$(sourceBase + ":incident_wavelength_spread"),units,angstrom) 541 542 // SASsample 543 String sampleParent = parentBase + "sassample/" 544 // Create SASsample entry 545 String sampleBase = base + ":entry1:sassample" 546 NewDataFolder/O/S $(sampleBase) 547 Make/O/T/N=5 $(sampleBase + ":attr") = {"canSAS_class","NX_class"} 548 Make/O/T/N=5 $(sampleBase + ":attrVals") = {"SASsample","NXsample"} 549 CreateStrNxCansas(fileID,sampleParent,"","",empty,$(sampleBase + ":attr"),$(sampleBase + ":attrVals")) 550 // Create SASsample name entry 551 Make/O/T/N=1 $(sampleBase + ":name") = {textw[6]} 552 CreateStrNxCansas(fileID,sampleParent,"","name",$(sampleBase + ":name"),empty,empty) 553 // Create SASsample thickness entry 554 Make/O/N=1 $(sampleBase + ":thickness") = {rw[5]} 555 CreateVarNxCansas(fileID,sampleParent,"","thickness",$(sampleBase + ":thickness"),units,cm) 556 // Create SASsample transmission entry 557 Make/O/N=1 $(sampleBase + ":transmission") = {rw[4]} 558 CreateVarNxCansas(fileID,sampleParent,"","transmission",$(sampleBase + ":transmission"),empty,empty) 559 560 // 561 /////////////////////////////////////////////////////////////////////////// 562 563 // Close the file 564 if(fileID) 565 HDF5CloseFile /Z fileID 566 endif 567 568 // KillDataFolder/Z $base 569 570 End 571 572 // 573 /////////////////////////////////////////////////////////////////////////// 574 253 575 /////////////////////////////////////////////////////////////////////////// 254 576 // Basic file open and initialization routines
Note: See TracChangeset
for help on using the changeset viewer.