- Timestamp:
- Dec 2, 2015 1:24:05 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sans/Dev/trunk/NCNR_User_Procedures/Common/NIST_XML_v40.ipf
r932 r971 343 343 344 344 345 function/S getXMLDataSetTitle(xmlDF,dsNum,[useFilename])345 function/S GetXMLDataSetTitle(xmlDF,dsNum,[useFilename]) 346 346 String xmlDF 347 347 Variable dsNum … … 393 393 394 394 395 //Function to write NIST canSAS XML files 396 //Minimalist XML file - AJJ Dec 2008 397 Function WriteNISTXML(fileName, NISTfile) 398 String fileName 399 Struct NISTXMLfile &NISTfile 400 401 variable fileID 402 403 //create the sasXML file with SASroot 404 //no namespace, no prefix 405 fileID = xmlcreatefile(fileName,"SASroot","cansas1d/1.0","") 406 407 //create a version attribute for the root element 408 xmlsetAttr(fileID,"/SASroot","","version","1.0") 409 xmlsetAttr(fileID,"/SASroot","","xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance") 410 xmlsetAttr(fileID,"/SASroot","","xsi:schemaLocation","cansas1d/1.0 http://svn.smallangles.net/svn/canSAS/1dwg/trunk/cansas1d.xsd") 411 412 413 //create the SASentry node 414 xmladdnode(fileID,"/SASroot","","SASentry","",1) 415 416 //create the Title node 417 xmladdnode(fileID,"/SASroot/SASentry","","Title",NISTfile.Title,1) 418 419 //create the Run node 420 xmladdnode(fileID,"/SASroot/SASentry","","Run",NISTfile.Run,1) 421 422 //create the SASdata node 423 xmladdnode(fileID,"/SASroot/SASentry","","SASdata","",1) 424 425 variable ii 426 427 if (WaveExists(NISTfile.dQl) == 1) 428 for(ii=0 ; ii<numpnts(NISTfile.Q) ; ii+=1) 429 xmladdnode(fileID,"/SASroot/SASentry/SASdata","","Idata","",1) 430 xmladdnode(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]","","Q",num2str(NISTfile.Q[ii]),1) 431 xmlsetAttr(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]/Q","","unit",NISTfile.unitsQ) 432 433 xmladdnode(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]","","I",num2str(NISTfile.I[ii]),1) 434 xmlsetAttr(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]/I","","unit",NISTfile.unitsI) 435 436 xmladdnode(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]","","Idev",num2str(NISTfile.Idev[ii]),1) 437 xmlsetAttr(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]/Idev","","unit",NISTfile.unitsIdev) 438 439 xmladdnode(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]","","dQl",num2str(NISTfile.dQl[ii]),1) 440 xmlsetAttr(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]/dQl","","unit",NISTfile.unitsdQl) 441 endfor 442 else 443 for(ii=0 ; ii<numpnts(NISTfile.Q) ; ii+=1) 444 xmladdnode(fileID,"/SASroot/SASentry/SASdata","","Idata","",1) 445 xmladdnode(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]","","Q",num2str(NISTfile.Q[ii]),1) 446 xmlsetAttr(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]/Q","","unit",NISTfile.unitsQ) 447 448 xmladdnode(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]","","I",num2str(NISTfile.I[ii]),1) 449 xmlsetAttr(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]/I","","unit",NISTfile.unitsI) 450 451 xmladdnode(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]","","Idev",num2str(NISTfile.Idev[ii]),1) 452 xmlsetAttr(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]/Idev","","unit",NISTfile.unitsIdev) 453 454 xmladdnode(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]","","Qdev",num2str(NISTfile.Qdev[ii]),1) 455 xmlsetAttr(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]/Qdev","","unit",NISTfile.unitsQdev) 456 457 xmladdnode(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]","","Qmean",num2str(NISTfile.Qmean[ii]),1) 458 xmlsetAttr(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]/Qmean","","unit",NISTfile.unitsQmean) 459 460 xmladdnode(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]","","Shadowfactor",num2str(NISTfile.shadowfactor[ii]),1) 461 endfor 462 endif 463 464 //SASsample node 465 xmladdnode(fileID,"/SASroot/SASentry","","SASsample","",1) 466 xmladdnode(fileID,"/SASroot/SASentry/SASsample","","ID",NISTfile.sample_ID,1) 467 468 //SASInstrument node 469 xmladdnode(fileID,"/SASroot/SASentry","","SASinstrument","",1) 470 xmladdnode(fileID,"/SASroot/SASentry/SASinstrument","","name",NISTfile.nameSASinstrument,1) 471 472 //SASsource 473 xmladdnode(fileID,"/SASroot/SASentry/SASinstrument","","SASsource","",1) 474 xmladdnode(fileID,"/SASroot/SASentry/SASinstrument/SASsource","","radiation",NISTfile.radiation,1) 475 476 //SAScollimation 477 xmladdnode(fileID,"/SASroot/SASentry/SASinstrument","","SAScollimation","",1) 478 479 //SASdetector 480 xmladdnode(fileID,"/SASroot/SASentry/SASinstrument","","SASdetector","",1) 481 xmladdnode(fileID,"/SASroot/SASentry/SASinstrument/SASdetector","","name",NISTfile.detector_name,1) 482 483 484 //SASprocess 485 xmladdnode(fileID,"/SASroot/SASentry","","SASprocess","",1) 486 xmlsetAttr(fileID,"/SASroot/SASentry/SASprocess","","name",NISTfile.nameSASprocess) 487 xmladdnode(fileID,"/SASroot/SASentry/SASprocess","","SASprocessnote",NISTfile.SASprocessnote,1) 488 489 //SASnote 490 xmladdnode(fileID,"/SASroot/SASentry","","SASnote",NISTfile.SASnote,1) 491 492 xmlsavefile(fileID) 493 xmlclosefile(fileID,0) 494 495 end 496 497 // 498 // !!! nf.Sample_ID is not set correctly here, since it's not read in from the NIST 6-col data file 499 // and SASprocessnote does not get set either! 500 // 501 Function ConvertNISTtoNISTXML(fileStr) 502 String fileStr 503 504 Struct NISTXMLfile nf 505 506 Variable rr,gg,bb,refnum,dQv 507 SetDataFolder root: 508 509 if (cmpStr(fileStr,"") == 0) 510 //No filename given, open dialog 511 Open/D/R refnum 512 if (cmpstr(S_filename,"") == 0) 513 return 0 514 else 515 fileStr = S_filename 516 endif 517 endif 518 519 //Load the waves, using default waveX names 520 //if no path or file is specified for LoadWave, the default Mac open dialog will appear 521 LoadWave/G/D/A/Q fileStr 522 String fileNamePath = S_Path+S_fileName 523 String basestr = CleanupName(ParseFilePath(3,ParseFilePath(5,fileNamePath,":",0,0),":",0,0),0) 524 // String baseStr = CleanupName(S_fileName,0) 525 // print "basestr :"+basestr 526 String fileName = ParseFilePath(0,ParseFilePath(5,filestr,":",0,0),":",1,0) 527 // print "filename :"+filename 528 Variable numCols = V_flag 529 String outfileName = S_Path+basestr+".xml" 530 531 532 if(numCols==3) //simple 3-column data with no resolution information 533 534 Wave nf.Q = $(StringFromList(0, S_waveNames ,";" )) 535 Wave nf.I = $(StringFromList(1, S_waveNames ,";" )) 536 Wave nf.Idev = $(StringFromList(2, S_waveNames ,";" )) 537 538 //Set units 539 nf.unitsQ = "1/A" 540 nf.unitsI = "1/cm" 541 nf.unitsIdev = "1/cm" 542 543 endif //3-col data 544 545 if(numCols == 6) //6-column SANS or USANS data that has resolution information 546 547 // put the names of the (default named) loaded waves into local names 548 Wave nf.Q = $(StringFromList(0, S_waveNames ,";" )) 549 Wave nf.I = $(StringFromList(1, S_waveNames ,";" )) 550 Wave nf.Idev = $(StringFromList(2, S_waveNames ,";" )) 551 552 //Set units 553 nf.unitsQ = "1/A" 554 nf.unitsI = "1/cm" 555 nf.unitsIdev = "1/cm" 556 557 WAVE resTest = $(StringFromList(3, S_waveNames ,";" )) 558 559 // need to switch based on SANS/USANS 560 if (isSANSResolution(resTest[0])) //checks to see if the first point of the wave is <0] 561 Wave nf.Qdev = $(StringFromList(3, S_waveNames ,";" )) 562 Wave nf.Qmean = $(StringFromList(4, S_waveNames ,";" )) 563 Wave nf.Shadowfactor = $(StringFromList(5, S_waveNames ,";" )) 564 565 //Set units 566 nf.unitsQdev = "1/A" 567 nf.unitsQmean = "1/A" 568 else 569 Wave nf.dQl = $(StringFromList(3, S_waveNames ,";" )) 570 nf.dQl = abs(nf.dQl) 571 572 //Set units 573 nf.unitsdQl = "1/A" 574 575 endif 576 577 endif //6-col data 578 579 //Get file header 580 setmetadataFromASCHeader(fileStr,nf) 581 582 //Set required metadata that we can't get from these files 583 nf.detector_name = "Ordela 128x128" 584 nf.nameSASinstrument = "NIST NG3/NG7 SANS" 585 nf.radiation = "neutron" 586 nf.sample_ID = nf.title 587 nf.nameSASProcess = "NIST Data Converter" 588 nf.sasnote = "Data converted from previous NIST format. SASProcessnote contains header from original text file." 589 590 writeNISTXML(outfileName, nf) 591 592 //Tidy up AFTER we're all done, since STRUCT points to wave0,wave1, etc. 593 Variable i = 0 594 do 595 WAVE/Z wv= $(StringFromList(i,S_waveNames,";")) 596 if( WaveExists(wv) == 0 ) 597 break 598 endif 599 KillWaves wv 600 i += 1 601 while (1) // exit is via break statement 602 603 end 604 605 function SetMetadataFromASCHeader(fileStr,NISTfile) 606 String fileStr 607 Struct NISTXMLfile &NISTfile 608 609 String hdr="",buffer="" 610 Variable lineNum = 0, fileref 611 Variable num 612 613 Open/R fileref as fileStr 614 do 615 FReadLine fileref, buffer 616 if (stringmatch(buffer,"*The 6 columns are*") == 1) 617 break 618 endif 619 buffer = RemoveEnding(buffer) 620 // print buffer 621 //Get run value 622 if (stringmatch(buffer,"*file:*") == 1) 623 NISTfile.run = TrimWS(StringFromList(0,StringFromList(1, buffer, ":"),"C")) 624 elseif (stringmatch(buffer,"combined file*") == 1) 625 NISTfile.run = "Combined Data" 626 endif 627 628 //Get title value 629 if (stringmatch(buffer,"*FIRST File LABEL:*") == 1) 630 NISTfile.title = TrimWS(StringFromList(1,buffer, ":")) 631 endif 632 if(stringmatch(buffer,"*LABEL:*") == 1) 633 NISTfile.title = TrimWS(StringFromList(1,buffer, ":")) 634 endif 635 if(stringmatch(buffer,"NSORT*") == 1) 636 NISTfile.title = buffer 637 endif 638 639 hdr += buffer+"\n" 640 while(strlen(buffer) > 0) 641 642 if (strlen(NISTfile.title) == 0) 643 NISTfile.title = CleanupName(ParseFilePath(3,ParseFilePath(5,fileStr,":",0,0),":",0,0),0) 644 endif 645 if (strlen(NISTfile.run) == 0) 646 NISTfile.run = "Unknown" 647 endif 648 649 NISTfile.sasprocessnote = RemoveEnding(hdr) 650 651 end 652 653 //for writing out data (q-i-s) from the "type" folder, and including reduction information 654 //if fullpath is a complete HD path:filename, no dialog will be presented 655 //if fullpath is just a filename, the save dialog will be presented 656 //if dialog = 1, a dialog will always be presented 657 // 658 // root:myGlobals:Protocols:gProtoStr is the name of the currently active protocol 659 // 660 //AJJ Nov 2009 : This version of the function currently only works for Circular, Sector and Rectangular averages 661 //i.e. anything that produces I vs Q. Need to add ability to handle Annular (I vs theta) but that requires namespace addition to XML format 662 //and handling on load. 663 Function WriteXMLWaves_W_Protocol(type,fullpath,dialog) 664 String type,fullpath 665 Variable dialog //=1 will present dialog for name 666 667 Struct NISTXMLfile nf 668 669 String destStr="" 670 destStr = "root:Packages:NIST:"+type 671 672 Variable refNum 673 // String fname,ave="C",hdrStr1="",hdrStr2="" 674 // Variable step=1 675 676 //*****these waves MUST EXIST, or IGOR Pro will crash, with a type 2 error**** 677 WAVE intw=$(destStr + ":integersRead") 678 WAVE rw=$(destStr + ":realsRead") 679 WAVE/T textw=$(destStr + ":textRead") 680 WAVE qvals =$(destStr + ":qval") 681 WAVE inten=$(destStr + ":aveint") 682 WAVE sig=$(destStr + ":sigave") 683 WAVE qbar = $(destStr + ":QBar") 684 WAVE sigmaq = $(destStr + ":SigmaQ") 685 WAVE fsubs = $(destStr + ":fSubS") 686 687 688 SVAR gProtoStr = root:myGlobals:Protocols:gProtoStr 689 Wave/T proto=$("root:myGlobals:Protocols:"+gProtoStr) 690 691 692 //check each wave 693 If(!(WaveExists(intw))) 694 Abort "intw DNExist BinaryWrite_W_Protocol()" 695 Endif 696 If(!(WaveExists(rw))) 697 Abort "rw DNExist BinaryWrite_W_Protocol()" 698 Endif 699 If(!(WaveExists(textw))) 700 Abort "textw DNExist BinaryWrite_W_Protocol()" 701 Endif 702 If(!(WaveExists(qvals))) 703 Abort "qvals DNExist BinaryWrite_W_Protocol()" 704 Endif 705 If(!(WaveExists(inten))) 706 Abort "inten DNExist BinaryWrite_W_Protocol()" 707 Endif 708 If(!(WaveExists(sig))) 709 Abort "sig DNExist BinaryWrite_W_Protocol()" 710 Endif 711 If(!(WaveExists(qbar))) 712 Abort "qbar DNExist BinaryWrite_W_Protocol()" 713 Endif 714 If(!(WaveExists(sigmaq))) 715 Abort "sigmaq DNExist BinaryWrite_W_Protocol()" 716 Endif 717 If(!(WaveExists(fsubs))) 718 Abort "fsubs DNExist BinaryWrite_W_Protocol()" 719 Endif 720 If(!(WaveExists(proto))) 721 Abort "current protocol wave DNExist BinaryWrite_W_Protocol()" 722 Endif 723 724 if(dialog) 725 PathInfo/S catPathName 726 fullPath = DoSaveFileDialog("Save data as") 727 If(cmpstr(fullPath,"")==0) 728 //user cancel, don't write out a file 729 Close/A 730 Abort "no data file was written" 731 Endif 732 //Print "dialog fullpath = ",fullpath 733 Endif 734 735 SVAR samFiles = $("root:Packages:NIST:"+type+":fileList") 736 //actually open the file here 737 //Open refNum as fullpath 738 739 //Data 740 Wave nf.Q = qvals 741 nf.unitsQ = "1/A" 742 Wave nf.I = inten 743 nf.unitsI = "1/cm" 744 Wave nf.Idev = sig 745 nf.unitsIdev = "1/cm" 746 Wave nf.Qdev = sigmaq 747 nf.unitsQdev = "1/A" 748 Wave nf.Qmean = qbar 749 nf.unitsQmean = "1/A" 750 Wave nf.Shadowfactor = fSubS 751 nf.unitsShadowfactor = "none" 752 753 754 //write out the standard header information 755 //fprintf refnum,"FILE: %s\t\t CREATED: %s\r\n",textw[0],textw[1] 756 757 //AJJ to fix with sensible values 758 nf.run = "Test" 759 String acct = textw[3] 760 nf.nameSASinstrument = acct[1,3] 761 nf.SASnote = "" 762 // 763 nf.sample_ID = textw[6] 764 nf.title = textw[6] 765 nf.radiation = "neutron" 766 nf.wavelength = rw[26] 767 nf.unitswavelength = "A" 768 nf.offset_angle = rw[19] 769 nf.unitsoffset_angle = "cm" 770 nf.SDD = rw[18] 771 nf.unitsSDD = "m" 772 nf.sample_transmission = rw[4] 773 nf.sample_thickness = rw[5] 774 nf.unitssample_thickness = "mm" 775 776 nf.beamcenter_X = rw[16] 777 nf.beamcenter_Y = rw[17] 778 nf.unitsbeamcenter_X = "pixels" 779 nf.unitsbeamcenter_Y = "pixels" 780 nf.source_aperture = rw[23] 781 nf.typesource_aperture = "pinhole" 782 nf.unitssource_aperture = "mm" 783 nf.sample_aperture = rw[24] 784 nf.typesample_aperture = "pinhole" 785 nf.unitssample_aperture = "mm" 786 //nf.collimation_length = total length - rw[25] 787 nf.wavelength_spread = rw[27] 788 nf.unitswavelength_spread = "percent" 789 //Do something with beamstop (rw[21]) 790 nf.detector_name = textW[9] 791 // fprintf refnum,"MON CNT LAMBDA DET ANG DET DIST TRANS THICK AVE STEP\r\n" 792 // fprintf refnum,hdrStr1 793 794 // fprintf refnum,"BCENT(X,Y) A1(mm) A2(mm) A1A2DIST(m) DL/L BSTOP(mm) DET_TYP \r\n" 795 // fprintf refnum,hdrStr2 796 797 //insert protocol information here 798 //-1 list of sample files 799 //0 - bkg 800 //1 - emp 801 //2 - div 802 //3 - mask 803 //4 - abs params c2-c5 804 //5 - average params 805 nf.SASprocessnote = "SAM: "+samFiles+"\n" 806 nf.SASprocessnote += "BGD: "+proto[0]+"\n" 807 nf.SASprocessnote += "EMP: "+Proto[1]+"\n" 808 nf.SASprocessnote += "DIV: "+Proto[2]+"\n" 809 nf.SASprocessnote += "MASK: "+Proto[3]+"\n" 810 nf.SASprocessnote += "ABS Parameters (3-6): "+Proto[4]+"\n" 811 nf.SASprocessnote += "Average Choices: "+Proto[5]+"\n" 812 813 nf.nameSASProcess = "NIST IGOR" 814 815 //Close refnum 816 817 writeNISTXML(fullpath, nf) 818 819 SetDataFolder root: //(redundant) 820 821 //write confirmation of write operation to history area 822 Print "Averaged XML File written: ", GetFileNameFromPathNoSemi(fullPath) 823 KillWaves/Z tempShortProto 824 Return(0) 825 End 826 827 Function WriteNSORTedXMLFile(qw,iw,sw,firstFileName,secondFileName,thirdFileName,normTo,norm12,norm23,[res]) 828 Wave qw,iw,sw,res 829 String firstFileName,secondFileName,thirdFileName,normTo 830 Variable norm12,norm23 831 832 Variable err=0,refNum,numCols,dialog=1 833 String fullPath="",formatStr="",str2 834 //check each wave - else REALLY FATAL error when writing file 835 If(!(WaveExists(qw))) 836 err = 1 837 return err 838 Endif 839 If(!(WaveExists(iw))) 840 err = 1 841 return err 842 Endif 843 If(!(WaveExists(sw))) 844 err = 1 845 return err 846 Endif 847 848 if(WaveExists(res)) 849 numCols = 6 850 else 851 numCols = 3 852 endif 853 854 // 05SEP05 SRK -- added to automatically combine files from a table - see the end of NSORT.ipf for details 855 // - use the flag set in DoCombineFiles() to decide if the table entries should be used 856 //Ê Êroot:myGlobals:CombineTable:useTable= (1) (0) 857 //if(exists("root:myGlobals:CombineTable:SaveName")) 858 NVAR/Z useTable = root:myGlobals:CombineTable:useTable 859 if(NVAR_Exists(useTable) && useTable==1) 860 SVAR str=root:myGlobals:CombineTable:SaveNameStr //messy, but pass in as a global 861 fullPath = str 862 // str2 = "Is the file name "+str+" correct?" 863 // DoAlert 1,str2 864 // if(V_flag==1) 865 dialog=0 //bypass the dialog if the name is good (assumed, since DoAlert is bypassed) 866 // endif 867 endif 868 869 if(dialog) 870 PathInfo/S catPathName 871 fullPath = DoSaveFileDialog("Save XML data as",fname="",suffix=".ABSx") //won't actually open the file 872 If(cmpstr(fullPath,"")==0) 873 //user cancel, don't write out a file 874 Close/A 875 Abort "no data file was written" 876 Endif 877 //Print "dialog fullpath = ",fullpath 878 Endif 879 880 Struct NISTxmlfile nf 881 882 //Data 883 Wave nf.Q = qw 884 nf.unitsQ = "1/A" 885 Wave nf.I = iw 886 nf.unitsI = "1/cm" 887 Wave nf.Idev = sw 888 nf.unitsIdev = "1/cm" 889 890 //write out the standard header information 891 //fprintf refnum,"FILE: %s\t\t CREATED: %s\r\n",textw[0],textw[1] 892 893 //AJJ to fix with sensible values 894 nf.run = "" 895 nf.nameSASinstrument = "NIST IGOR" 896 nf.SASnote = "" 897 // 898 nf.sample_ID = ParseFilePath(3, fullPath, ":", 0, 0) 899 nf.title = ParseFilePath(3, fullPath, ":", 0, 0) 900 nf.radiation = "neutron" 901 //Do something with beamstop (rw[21]) 902 nf.detector_name = "NSORTed Data" 903 nf.nameSASProcess = "NIST IGOR" 904 905 nf.sasProcessNote = "COMBINED FILE CREATED: "+date()+"\n" 906 nf.sasProcessNote += "NSORT-ed : " +firstFileName+";"+secondFileName+";"+thirdFileName+"\n" 907 nf.sasProcessNote += "normalized to "+normTo+"\n" 908 fprintf refNum, "multiplicative factor 1-2 = "+num2str(norm12)+" multiplicative factor 2-3 = "+num2str(norm23)+"\n" 909 910 if (numCols == 3) 911 writeNISTXML(fullpath,nf) 912 elseif (numCols == 6) 913 Make/O/N=(dimsize(res,0)) sigq = res[p][0] 914 Make/O/N=(dimsize(res,0)) qbar = res[p][1] 915 Make/O/N=(dimsize(res,0)) fs = res[p][2] 916 917 Wave nf.Qdev = sigQ 918 nf.unitsQdev = "1/A" 919 Wave nf.Qmean = qbar 920 nf.unitsQmean = "1/A" 921 Wave nf.Shadowfactor = fs 922 nf.unitsShadowfactor = "none" 923 924 writeNISTXML(fullpath,nf) 925 926 Killwaves/Z sigq,qbar,fs 927 endif 928 929 Return err 930 End 931 932 933 934 /// See WriteModelData_v40.ipf for 6 column equivalent 935 // 936 // will abort if resolution wave is missing 937 // switches for USANS data if the proper global is found, otheriwse treats as SANS data 938 // 939 Function ReWrite1DXMLData(folderStr) 940 String folderStr 941 942 String fullpath="" 943 Variable dialog=1 944 String dataSetFolderParent,basestr,fullBase 945 946 Struct NISTXMLfile nf 947 948 //Abuse ParseFilePath to get path without folder name 949 dataSetFolderParent = ParseFilePath(1,folderStr,":",1,0) 950 //Abuse ParseFilePath to get basestr 951 basestr = ParseFilePath(0,folderStr,":",1,0) 952 953 SetDataFolder $(dataSetFolderParent+basestr) 954 WAVE/Z qw = $(baseStr+"_q") 955 WAVE/Z iw = $(baseStr+"_i") 956 WAVE/Z sw = $(baseStr+"_s") 957 WAVE/Z resw = $(baseStr+"_res") 958 959 if(WaveExists(qw) == 0) 960 Abort "q is missing" 961 endif 962 if(WaveExists(iw) == 0) 963 Abort "i is missing" 964 endif 965 if(WaveExists(sw) == 0) 966 Abort "s is missing" 967 endif 968 if(WaveExists(resw) == 0) 969 Abort "Resolution information is missing." 970 endif 971 972 973 // if (USANS) 974 // else (SANS is assumed) 975 // endif 976 NVAR/Z dQv = USANS_dQv // in current DF 977 if (NVAR_Exists(dQv)) 978 //USANS data, proceed 979 //Use the evil extra column for the resolution "information". Should probably switch to using slit_length in collimation. 980 Duplicate/O qw,dumWave 981 dumWave = dQv //written out as a positive value, since the column is identified by its label, dQl 982 983 //Data 984 Wave nf.Q = qw 985 nf.unitsQ = "1/A" 986 Wave nf.I = iw 987 nf.unitsI = "1/cm" 988 Wave nf.Idev = sw 989 nf.unitsIdev = "1/cm" 990 // for slit-smeared USANS, set only a 4th column to -dQv 991 Wave nf.dQl = dumWave 992 nf.unitsdQl= "1/A" 993 994 //AJJ to fix with sensible values 995 nf.run = "" 996 nf.nameSASinstrument = "NIST IGOR Procedures" 997 nf.SASnote = "" 998 // 999 nf.sample_ID = baseStr 1000 nf.title = baseStr 1001 nf.radiation = "neutron" 1002 //Do something with beamstop (rw[21]) 1003 nf.detector_name = "Re-written USANS data" 1004 1005 nf.SASprocessnote = "Modified data written from folder "+baseStr+" on "+(date()+" "+time()) 1006 1007 nf.nameSASProcess = "NIST IGOR" 1008 1009 else 1010 //assume SANS data 1011 Duplicate/O qw qbar,sigQ,fs 1012 sigq = resw[p][0] 1013 qbar = resw[p][1] 1014 fs = resw[p][2] 1015 1016 1017 //Data 1018 Wave nf.Q = qw 1019 nf.unitsQ = "1/A" 1020 Wave nf.I = iw 1021 nf.unitsI = "1/cm" 1022 Wave nf.Idev = sw 1023 nf.unitsIdev = "1/cm" 1024 Wave nf.Qdev = sigQ 1025 nf.unitsQdev = "1/A" 1026 Wave nf.Qmean = qbar 1027 nf.unitsQmean = "1/A" 1028 Wave nf.Shadowfactor = fs 1029 nf.unitsShadowfactor = "none" 1030 1031 1032 //write out the standard header information 1033 //fprintf refnum,"FILE: %s\t\t CREATED: %s\r\n",textw[0],textw[1] 1034 1035 //AJJ to fix with sensible values 1036 nf.run = "" 1037 nf.nameSASinstrument = "NIST IGOR Procedures" 1038 nf.SASnote = "" 1039 // 1040 nf.sample_ID = baseStr 1041 nf.title = baseStr 1042 nf.radiation = "neutron" 1043 //Do something with beamstop (rw[21]) 1044 nf.detector_name = "Re-written data" 1045 1046 nf.SASprocessnote = "Modified data written from folder "+baseStr+" on "+(date()+" "+time()) 1047 1048 nf.nameSASProcess = "NIST IGOR" 1049 1050 endif 1051 1052 1053 if(dialog) 1054 PathInfo/S catPathName 1055 fullPath = DoSaveFileDialog("Save data as",fname=baseStr+".xml") 1056 If(cmpstr(fullPath,"")==0) 1057 //user cancel, don't write out a file 1058 Close/A 1059 Abort "no data file was written" 1060 Endif 1061 //Print "dialog fullpath = ",fullpath 1062 Endif 1063 1064 1065 writeNISTXML(fullpath,nf) 1066 //write confirmation of write operation to history area 1067 Print "XML File written: ", GetFileNameFromPathNoSemi(fullPath) 1068 KillWaves/Z tempShortProto 1069 1070 SetDataFolder root: 1071 1072 Return(0) 1073 End 1074 1075 1076 1077 1078 #else // if( Exists("XmlOpenFile") ) 1079 // No XMLutils XOP: provide dummy function so that IgorPro can compile dependent support code 1080 // FUNCTION LoadNISTXMLData(fileName,doPlot) 1081 // String fileName 1082 // Variable doPlot 1083 // Abort "XML function provided by XMLutils XOP is not available, get the XOP from : http://www.igorexchange.com/project/XMLutils (see http://www.smallangles.net/wgwiki/index.php/cansas1d_binding_IgorPro for details)" 1084 // RETURN(-6) 1085 // END 1086 1087 1088 Function LoadNISTXMLData(filestr,outStr,doPlot,forceOverwrite) 1089 String filestr,outStr 1090 Variable doPlot,forceOverwrite 1091 1092 Abort "XML function provided by XMLutils XOP is not available, get the XOP from : http://www.igorexchange.com/project/XMLutils (see http://www.smallangles.net/wgwiki/index.php/cansas1d_binding_IgorPro for details)" 1093 return(-6) 1094 end 1095 1096 Function/S GetXMLDataSetTitle(xmlDF,dsNum,[useFilename]) 1097 String xmlDF 1098 Variable dsNum 1099 Variable useFilename 1100 1101 Abort "XML function provided by XMLutils XOP is not available, get the XOP from : http://www.igorexchange.com/project/XMLutils (see http://www.smallangles.net/wgwiki/index.php/cansas1d_binding_IgorPro for details)" 1102 return("") 1103 end 1104 1105 Function WriteNISTXML(fileName, NISTfile) 1106 String fileName, NISTfile 1107 Abort "XML function provided by XMLutils XOP is not available, get the XOP from : http://www.igorexchange.com/project/XMLutils (see http://www.smallangles.net/wgwiki/index.php/cansas1d_binding_IgorPro for details)" 1108 RETURN(-6) 1109 End 1110 1111 Function WriteXMLWaves_W_Protocol(type,fullpath,dialog) 1112 String type,fullpath 1113 Variable dialog //=1 will present dialog for name 1114 1115 Abort "XML function provided by XMLutils XOP is not available, get the XOP from : http://www.igorexchange.com/project/XMLutils (see http://www.smallangles.net/wgwiki/index.php/cansas1d_binding_IgorPro for details)" 1116 return(-6) 1117 end 1118 1119 Function WriteNSORTedXMLFile(q3,i3,sig3,firstFileName,secondFileName,thirdFileName,normTo,norm12,norm23,[res]) 1120 Wave q3,i3,sig3,res 1121 String firstFileName,secondFileName,thirdFileName,normTo 1122 Variable norm12,norm23 1123 1124 Abort "XML function provided by XMLutils XOP is not available, get the XOP from : http://www.igorexchange.com/project/XMLutils (see http://www.smallangles.net/wgwiki/index.php/cansas1d_binding_IgorPro for details)" 1125 return(-6) 1126 End 1127 1128 Function ReWrite1DXMLData(folderStr) 1129 String folderStr 1130 1131 Abort "XML function provided by XMLutils XOP is not available, get the XOP from : http://www.igorexchange.com/project/XMLutils (see http://www.smallangles.net/wgwiki/index.php/cansas1d_binding_IgorPro for details)" 1132 return(-6) 1133 end 1134 1135 Function SetMetadataFromASCHeader(fileStr,NISTfile) 1136 String fileStr 1137 Struct NISTXMLfile &NISTfile 1138 1139 Abort "XML function provided by XMLutils XOP is not available, get the XOP from : http://www.igorexchange.com/project/XMLutils (see http://www.smallangles.net/wgwiki/index.php/cansas1d_binding_IgorPro for details)" 1140 return(-6) 1141 end 1142 1143 Function ConvertNISTtoNISTXML(fileStr) 1144 String fileStr 1145 1146 Abort "XML function provided by XMLutils XOP is not available, get the XOP from : http://www.igorexchange.com/project/XMLutils (see http://www.smallangles.net/wgwiki/index.php/cansas1d_binding_IgorPro for details)" 1147 return(-6) 1148 end 1149 1150 1151 #endif 1152 395 1153 //AJJ 12/5/08 396 1154 … … 470 1228 Endstructure 471 1229 472 473 //Function to write NIST canSAS XML files474 //Minimalist XML file - AJJ Dec 2008475 function writeNISTXML(fileName, NISTfile)476 String fileName477 Struct NISTXMLfile &NISTfile478 479 variable fileID480 481 //create the sasXML file with SASroot482 //no namespace, no prefix483 fileID = xmlcreatefile(fileName,"SASroot","cansas1d/1.0","")484 485 //create a version attribute for the root element486 xmlsetAttr(fileID,"/SASroot","","version","1.0")487 xmlsetAttr(fileID,"/SASroot","","xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance")488 xmlsetAttr(fileID,"/SASroot","","xsi:schemaLocation","cansas1d/1.0 http://svn.smallangles.net/svn/canSAS/1dwg/trunk/cansas1d.xsd")489 490 491 //create the SASentry node492 xmladdnode(fileID,"/SASroot","","SASentry","",1)493 494 //create the Title node495 xmladdnode(fileID,"/SASroot/SASentry","","Title",NISTfile.Title,1)496 497 //create the Run node498 xmladdnode(fileID,"/SASroot/SASentry","","Run",NISTfile.Run,1)499 500 //create the SASdata node501 xmladdnode(fileID,"/SASroot/SASentry","","SASdata","",1)502 503 variable ii504 505 if (WaveExists(NISTfile.dQl) == 1)506 for(ii=0 ; ii<numpnts(NISTfile.Q) ; ii+=1)507 xmladdnode(fileID,"/SASroot/SASentry/SASdata","","Idata","",1)508 xmladdnode(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]","","Q",num2str(NISTfile.Q[ii]),1)509 xmlsetAttr(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]/Q","","unit",NISTfile.unitsQ)510 511 xmladdnode(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]","","I",num2str(NISTfile.I[ii]),1)512 xmlsetAttr(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]/I","","unit",NISTfile.unitsI)513 514 xmladdnode(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]","","Idev",num2str(NISTfile.Idev[ii]),1)515 xmlsetAttr(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]/Idev","","unit",NISTfile.unitsIdev)516 517 xmladdnode(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]","","dQl",num2str(NISTfile.dQl[ii]),1)518 xmlsetAttr(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]/dQl","","unit",NISTfile.unitsdQl)519 endfor520 else521 for(ii=0 ; ii<numpnts(NISTfile.Q) ; ii+=1)522 xmladdnode(fileID,"/SASroot/SASentry/SASdata","","Idata","",1)523 xmladdnode(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]","","Q",num2str(NISTfile.Q[ii]),1)524 xmlsetAttr(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]/Q","","unit",NISTfile.unitsQ)525 526 xmladdnode(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]","","I",num2str(NISTfile.I[ii]),1)527 xmlsetAttr(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]/I","","unit",NISTfile.unitsI)528 529 xmladdnode(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]","","Idev",num2str(NISTfile.Idev[ii]),1)530 xmlsetAttr(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]/Idev","","unit",NISTfile.unitsIdev)531 532 xmladdnode(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]","","Qdev",num2str(NISTfile.Qdev[ii]),1)533 xmlsetAttr(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]/Qdev","","unit",NISTfile.unitsQdev)534 535 xmladdnode(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]","","Qmean",num2str(NISTfile.Qmean[ii]),1)536 xmlsetAttr(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]/Qmean","","unit",NISTfile.unitsQmean)537 538 xmladdnode(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]","","Shadowfactor",num2str(NISTfile.shadowfactor[ii]),1)539 endfor540 endif541 542 //SASsample node543 xmladdnode(fileID,"/SASroot/SASentry","","SASsample","",1)544 xmladdnode(fileID,"/SASroot/SASentry/SASsample","","ID",NISTfile.sample_ID,1)545 546 //SASInstrument node547 xmladdnode(fileID,"/SASroot/SASentry","","SASinstrument","",1)548 xmladdnode(fileID,"/SASroot/SASentry/SASinstrument","","name",NISTfile.nameSASinstrument,1)549 550 //SASsource551 xmladdnode(fileID,"/SASroot/SASentry/SASinstrument","","SASsource","",1)552 xmladdnode(fileID,"/SASroot/SASentry/SASinstrument/SASsource","","radiation",NISTfile.radiation,1)553 554 //SAScollimation555 xmladdnode(fileID,"/SASroot/SASentry/SASinstrument","","SAScollimation","",1)556 557 //SASdetector558 xmladdnode(fileID,"/SASroot/SASentry/SASinstrument","","SASdetector","",1)559 xmladdnode(fileID,"/SASroot/SASentry/SASinstrument/SASdetector","","name",NISTfile.detector_name,1)560 561 562 //SASprocess563 xmladdnode(fileID,"/SASroot/SASentry","","SASprocess","",1)564 xmlsetAttr(fileID,"/SASroot/SASentry/SASprocess","","name",NISTfile.nameSASprocess)565 xmladdnode(fileID,"/SASroot/SASentry/SASprocess","","SASprocessnote",NISTfile.SASprocessnote,1)566 567 //SASnote568 xmladdnode(fileID,"/SASroot/SASentry","","SASnote",NISTfile.SASnote,1)569 570 xmlsavefile(fileID)571 xmlclosefile(fileID,0)572 573 end574 575 //576 // !!! nf.Sample_ID is not set correctly here, since it's not read in from the NIST 6-col data file577 // and SASprocessnote does not get set either!578 //579 Function convertNISTtoNISTXML(fileStr)580 String fileStr581 582 Struct NISTXMLfile nf583 584 Variable rr,gg,bb,refnum,dQv585 SetDataFolder root:586 587 if (cmpStr(fileStr,"") == 0)588 //No filename given, open dialog589 Open/D/R refnum590 if (cmpstr(S_filename,"") == 0)591 return 0592 else593 fileStr = S_filename594 endif595 endif596 597 //Load the waves, using default waveX names598 //if no path or file is specified for LoadWave, the default Mac open dialog will appear599 LoadWave/G/D/A/Q fileStr600 String fileNamePath = S_Path+S_fileName601 String basestr = CleanupName(ParseFilePath(3,ParseFilePath(5,fileNamePath,":",0,0),":",0,0),0)602 // String baseStr = CleanupName(S_fileName,0)603 // print "basestr :"+basestr604 String fileName = ParseFilePath(0,ParseFilePath(5,filestr,":",0,0),":",1,0)605 // print "filename :"+filename606 Variable numCols = V_flag607 String outfileName = S_Path+basestr+".xml"608 609 610 if(numCols==3) //simple 3-column data with no resolution information611 612 Wave nf.Q = $(StringFromList(0, S_waveNames ,";" ))613 Wave nf.I = $(StringFromList(1, S_waveNames ,";" ))614 Wave nf.Idev = $(StringFromList(2, S_waveNames ,";" ))615 616 //Set units617 nf.unitsQ = "1/A"618 nf.unitsI = "1/cm"619 nf.unitsIdev = "1/cm"620 621 endif //3-col data622 623 if(numCols == 6) //6-column SANS or USANS data that has resolution information624 625 // put the names of the (default named) loaded waves into local names626 Wave nf.Q = $(StringFromList(0, S_waveNames ,";" ))627 Wave nf.I = $(StringFromList(1, S_waveNames ,";" ))628 Wave nf.Idev = $(StringFromList(2, S_waveNames ,";" ))629 630 //Set units631 nf.unitsQ = "1/A"632 nf.unitsI = "1/cm"633 nf.unitsIdev = "1/cm"634 635 WAVE resTest = $(StringFromList(3, S_waveNames ,";" ))636 637 // need to switch based on SANS/USANS638 if (isSANSResolution(resTest[0])) //checks to see if the first point of the wave is <0]639 Wave nf.Qdev = $(StringFromList(3, S_waveNames ,";" ))640 Wave nf.Qmean = $(StringFromList(4, S_waveNames ,";" ))641 Wave nf.Shadowfactor = $(StringFromList(5, S_waveNames ,";" ))642 643 //Set units644 nf.unitsQdev = "1/A"645 nf.unitsQmean = "1/A"646 else647 Wave nf.dQl = $(StringFromList(3, S_waveNames ,";" ))648 nf.dQl = abs(nf.dQl)649 650 //Set units651 nf.unitsdQl = "1/A"652 653 endif654 655 endif //6-col data656 657 //Get file header658 setmetadataFromASCHeader(fileStr,nf)659 660 //Set required metadata that we can't get from these files661 nf.detector_name = "Ordela 128x128"662 nf.nameSASinstrument = "NIST NG3/NG7 SANS"663 nf.radiation = "neutron"664 nf.sample_ID = nf.title665 nf.nameSASProcess = "NIST Data Converter"666 nf.sasnote = "Data converted from previous NIST format. SASProcessnote contains header from original text file."667 668 writeNISTXML(outfileName, nf)669 670 //Tidy up AFTER we're all done, since STRUCT points to wave0,wave1, etc.671 Variable i = 0672 do673 WAVE/Z wv= $(StringFromList(i,S_waveNames,";"))674 if( WaveExists(wv) == 0 )675 break676 endif677 KillWaves wv678 i += 1679 while (1) // exit is via break statement680 681 end682 683 function setmetadataFromASCHeader(fileStr,NISTfile)684 String fileStr685 Struct NISTXMLfile &NISTfile686 687 String hdr="",buffer=""688 Variable lineNum = 0, fileref689 Variable num690 691 Open/R fileref as fileStr692 do693 FReadLine fileref, buffer694 if (stringmatch(buffer,"*The 6 columns are*") == 1)695 break696 endif697 buffer = RemoveEnding(buffer)698 // print buffer699 //Get run value700 if (stringmatch(buffer,"*file:*") == 1)701 NISTfile.run = TrimWS(StringFromList(0,StringFromList(1, buffer, ":"),"C"))702 elseif (stringmatch(buffer,"combined file*") == 1)703 NISTfile.run = "Combined Data"704 endif705 706 //Get title value707 if (stringmatch(buffer,"*FIRST File LABEL:*") == 1)708 NISTfile.title = TrimWS(StringFromList(1,buffer, ":"))709 endif710 if(stringmatch(buffer,"*LABEL:*") == 1)711 NISTfile.title = TrimWS(StringFromList(1,buffer, ":"))712 endif713 if(stringmatch(buffer,"NSORT*") == 1)714 NISTfile.title = buffer715 endif716 717 hdr += buffer+"\n"718 while(strlen(buffer) > 0)719 720 if (strlen(NISTfile.title) == 0)721 NISTfile.title = CleanupName(ParseFilePath(3,ParseFilePath(5,fileStr,":",0,0),":",0,0),0)722 endif723 if (strlen(NISTfile.run) == 0)724 NISTfile.run = "Unknown"725 endif726 727 NISTfile.sasprocessnote = RemoveEnding(hdr)728 729 end730 731 //for writing out data (q-i-s) from the "type" folder, and including reduction information732 //if fullpath is a complete HD path:filename, no dialog will be presented733 //if fullpath is just a filename, the save dialog will be presented734 //if dialog = 1, a dialog will always be presented735 //736 // root:myGlobals:Protocols:gProtoStr is the name of the currently active protocol737 //738 //AJJ Nov 2009 : This version of the function currently only works for Circular, Sector and Rectangular averages739 //i.e. anything that produces I vs Q. Need to add ability to handle Annular (I vs theta) but that requires namespace addition to XML format740 //and handling on load.741 Function WriteXMLWaves_W_Protocol(type,fullpath,dialog)742 String type,fullpath743 Variable dialog //=1 will present dialog for name744 745 Struct NISTXMLfile nf746 747 String destStr=""748 destStr = "root:Packages:NIST:"+type749 750 Variable refNum751 // String fname,ave="C",hdrStr1="",hdrStr2=""752 // Variable step=1753 754 //*****these waves MUST EXIST, or IGOR Pro will crash, with a type 2 error****755 WAVE intw=$(destStr + ":integersRead")756 WAVE rw=$(destStr + ":realsRead")757 WAVE/T textw=$(destStr + ":textRead")758 WAVE qvals =$(destStr + ":qval")759 WAVE inten=$(destStr + ":aveint")760 WAVE sig=$(destStr + ":sigave")761 WAVE qbar = $(destStr + ":QBar")762 WAVE sigmaq = $(destStr + ":SigmaQ")763 WAVE fsubs = $(destStr + ":fSubS")764 765 766 SVAR gProtoStr = root:myGlobals:Protocols:gProtoStr767 Wave/T proto=$("root:myGlobals:Protocols:"+gProtoStr)768 769 770 //check each wave771 If(!(WaveExists(intw)))772 Abort "intw DNExist BinaryWrite_W_Protocol()"773 Endif774 If(!(WaveExists(rw)))775 Abort "rw DNExist BinaryWrite_W_Protocol()"776 Endif777 If(!(WaveExists(textw)))778 Abort "textw DNExist BinaryWrite_W_Protocol()"779 Endif780 If(!(WaveExists(qvals)))781 Abort "qvals DNExist BinaryWrite_W_Protocol()"782 Endif783 If(!(WaveExists(inten)))784 Abort "inten DNExist BinaryWrite_W_Protocol()"785 Endif786 If(!(WaveExists(sig)))787 Abort "sig DNExist BinaryWrite_W_Protocol()"788 Endif789 If(!(WaveExists(qbar)))790 Abort "qbar DNExist BinaryWrite_W_Protocol()"791 Endif792 If(!(WaveExists(sigmaq)))793 Abort "sigmaq DNExist BinaryWrite_W_Protocol()"794 Endif795 If(!(WaveExists(fsubs)))796 Abort "fsubs DNExist BinaryWrite_W_Protocol()"797 Endif798 If(!(WaveExists(proto)))799 Abort "current protocol wave DNExist BinaryWrite_W_Protocol()"800 Endif801 802 if(dialog)803 PathInfo/S catPathName804 fullPath = DoSaveFileDialog("Save data as")805 If(cmpstr(fullPath,"")==0)806 //user cancel, don't write out a file807 Close/A808 Abort "no data file was written"809 Endif810 //Print "dialog fullpath = ",fullpath811 Endif812 813 SVAR samFiles = $("root:Packages:NIST:"+type+":fileList")814 //actually open the file here815 //Open refNum as fullpath816 817 //Data818 Wave nf.Q = qvals819 nf.unitsQ = "1/A"820 Wave nf.I = inten821 nf.unitsI = "1/cm"822 Wave nf.Idev = sig823 nf.unitsIdev = "1/cm"824 Wave nf.Qdev = sigmaq825 nf.unitsQdev = "1/A"826 Wave nf.Qmean = qbar827 nf.unitsQmean = "1/A"828 Wave nf.Shadowfactor = fSubS829 nf.unitsShadowfactor = "none"830 831 832 //write out the standard header information833 //fprintf refnum,"FILE: %s\t\t CREATED: %s\r\n",textw[0],textw[1]834 835 //AJJ to fix with sensible values836 nf.run = "Test"837 String acct = textw[3]838 nf.nameSASinstrument = acct[1,3]839 nf.SASnote = ""840 //841 nf.sample_ID = textw[6]842 nf.title = textw[6]843 nf.radiation = "neutron"844 nf.wavelength = rw[26]845 nf.unitswavelength = "A"846 nf.offset_angle = rw[19]847 nf.unitsoffset_angle = "cm"848 nf.SDD = rw[18]849 nf.unitsSDD = "m"850 nf.sample_transmission = rw[4]851 nf.sample_thickness = rw[5]852 nf.unitssample_thickness = "mm"853 854 nf.beamcenter_X = rw[16]855 nf.beamcenter_Y = rw[17]856 nf.unitsbeamcenter_X = "pixels"857 nf.unitsbeamcenter_Y = "pixels"858 nf.source_aperture = rw[23]859 nf.typesource_aperture = "pinhole"860 nf.unitssource_aperture = "mm"861 nf.sample_aperture = rw[24]862 nf.typesample_aperture = "pinhole"863 nf.unitssample_aperture = "mm"864 //nf.collimation_length = total length - rw[25]865 nf.wavelength_spread = rw[27]866 nf.unitswavelength_spread = "percent"867 //Do something with beamstop (rw[21])868 nf.detector_name = textW[9]869 // fprintf refnum,"MON CNT LAMBDA DET ANG DET DIST TRANS THICK AVE STEP\r\n"870 // fprintf refnum,hdrStr1871 872 // fprintf refnum,"BCENT(X,Y) A1(mm) A2(mm) A1A2DIST(m) DL/L BSTOP(mm) DET_TYP \r\n"873 // fprintf refnum,hdrStr2874 875 //insert protocol information here876 //-1 list of sample files877 //0 - bkg878 //1 - emp879 //2 - div880 //3 - mask881 //4 - abs params c2-c5882 //5 - average params883 nf.SASprocessnote = "SAM: "+samFiles+"\n"884 nf.SASprocessnote += "BGD: "+proto[0]+"\n"885 nf.SASprocessnote += "EMP: "+Proto[1]+"\n"886 nf.SASprocessnote += "DIV: "+Proto[2]+"\n"887 nf.SASprocessnote += "MASK: "+Proto[3]+"\n"888 nf.SASprocessnote += "ABS Parameters (3-6): "+Proto[4]+"\n"889 nf.SASprocessnote += "Average Choices: "+Proto[5]+"\n"890 891 nf.nameSASProcess = "NIST IGOR"892 893 //Close refnum894 895 writeNISTXML(fullpath, nf)896 897 SetDataFolder root: //(redundant)898 899 //write confirmation of write operation to history area900 Print "Averaged XML File written: ", GetFileNameFromPathNoSemi(fullPath)901 KillWaves/Z tempShortProto902 Return(0)903 End904 905 Function WriteNSORTedXMLFile(qw,iw,sw,firstFileName,secondFileName,thirdFileName,normTo,norm12,norm23,[res])906 Wave qw,iw,sw,res907 String firstFileName,secondFileName,thirdFileName,normTo908 Variable norm12,norm23909 910 Variable err=0,refNum,numCols,dialog=1911 String fullPath="",formatStr="",str2912 //check each wave - else REALLY FATAL error when writing file913 If(!(WaveExists(qw)))914 err = 1915 return err916 Endif917 If(!(WaveExists(iw)))918 err = 1919 return err920 Endif921 If(!(WaveExists(sw)))922 err = 1923 return err924 Endif925 926 if(WaveExists(res))927 numCols = 6928 else929 numCols = 3930 endif931 932 // 05SEP05 SRK -- added to automatically combine files from a table - see the end of NSORT.ipf for details933 // - use the flag set in DoCombineFiles() to decide if the table entries should be used934 //Ê Êroot:myGlobals:CombineTable:useTable= (1) (0)935 //if(exists("root:myGlobals:CombineTable:SaveName"))936 NVAR/Z useTable = root:myGlobals:CombineTable:useTable937 if(NVAR_Exists(useTable) && useTable==1)938 SVAR str=root:myGlobals:CombineTable:SaveNameStr //messy, but pass in as a global939 fullPath = str940 // str2 = "Is the file name "+str+" correct?"941 // DoAlert 1,str2942 // if(V_flag==1)943 dialog=0 //bypass the dialog if the name is good (assumed, since DoAlert is bypassed)944 // endif945 endif946 947 if(dialog)948 PathInfo/S catPathName949 fullPath = DoSaveFileDialog("Save XML data as",fname="",suffix=".ABSx") //won't actually open the file950 If(cmpstr(fullPath,"")==0)951 //user cancel, don't write out a file952 Close/A953 Abort "no data file was written"954 Endif955 //Print "dialog fullpath = ",fullpath956 Endif957 958 Struct NISTxmlfile nf959 960 //Data961 Wave nf.Q = qw962 nf.unitsQ = "1/A"963 Wave nf.I = iw964 nf.unitsI = "1/cm"965 Wave nf.Idev = sw966 nf.unitsIdev = "1/cm"967 968 //write out the standard header information969 //fprintf refnum,"FILE: %s\t\t CREATED: %s\r\n",textw[0],textw[1]970 971 //AJJ to fix with sensible values972 nf.run = ""973 nf.nameSASinstrument = "NIST IGOR"974 nf.SASnote = ""975 //976 nf.sample_ID = ParseFilePath(3, fullPath, ":", 0, 0)977 nf.title = ParseFilePath(3, fullPath, ":", 0, 0)978 nf.radiation = "neutron"979 //Do something with beamstop (rw[21])980 nf.detector_name = "NSORTed Data"981 nf.nameSASProcess = "NIST IGOR"982 983 nf.sasProcessNote = "COMBINED FILE CREATED: "+date()+"\n"984 nf.sasProcessNote += "NSORT-ed : " +firstFileName+";"+secondFileName+";"+thirdFileName+"\n"985 nf.sasProcessNote += "normalized to "+normTo+"\n"986 fprintf refNum, "multiplicative factor 1-2 = "+num2str(norm12)+" multiplicative factor 2-3 = "+num2str(norm23)+"\n"987 988 if (numCols == 3)989 writeNISTXML(fullpath,nf)990 elseif (numCols == 6)991 Make/O/N=(dimsize(res,0)) sigq = res[p][0]992 Make/O/N=(dimsize(res,0)) qbar = res[p][1]993 Make/O/N=(dimsize(res,0)) fs = res[p][2]994 995 Wave nf.Qdev = sigQ996 nf.unitsQdev = "1/A"997 Wave nf.Qmean = qbar998 nf.unitsQmean = "1/A"999 Wave nf.Shadowfactor = fs1000 nf.unitsShadowfactor = "none"1001 1002 writeNISTXML(fullpath,nf)1003 1004 Killwaves/Z sigq,qbar,fs1005 endif1006 1007 Return err1008 End1009 1010 1011 1012 /// See WriteModelData_v40.ipf for 6 column equivalent1013 //1014 // will abort if resolution wave is missing1015 // switches for USANS data if the proper global is found, otheriwse treats as SANS data1016 //1017 Function ReWrite1DXMLData(folderStr)1018 String folderStr1019 1020 String fullpath=""1021 Variable dialog=11022 String dataSetFolderParent,basestr,fullBase1023 1024 Struct NISTXMLfile nf1025 1026 //Abuse ParseFilePath to get path without folder name1027 dataSetFolderParent = ParseFilePath(1,folderStr,":",1,0)1028 //Abuse ParseFilePath to get basestr1029 basestr = ParseFilePath(0,folderStr,":",1,0)1030 1031 SetDataFolder $(dataSetFolderParent+basestr)1032 WAVE/Z qw = $(baseStr+"_q")1033 WAVE/Z iw = $(baseStr+"_i")1034 WAVE/Z sw = $(baseStr+"_s")1035 WAVE/Z resw = $(baseStr+"_res")1036 1037 if(WaveExists(qw) == 0)1038 Abort "q is missing"1039 endif1040 if(WaveExists(iw) == 0)1041 Abort "i is missing"1042 endif1043 if(WaveExists(sw) == 0)1044 Abort "s is missing"1045 endif1046 if(WaveExists(resw) == 0)1047 Abort "Resolution information is missing."1048 endif1049 1050 1051 // if (USANS)1052 // else (SANS is assumed)1053 // endif1054 NVAR/Z dQv = USANS_dQv // in current DF1055 if (NVAR_Exists(dQv))1056 //USANS data, proceed1057 //Use the evil extra column for the resolution "information". Should probably switch to using slit_length in collimation.1058 Duplicate/O qw,dumWave1059 dumWave = dQv //written out as a positive value, since the column is identified by its label, dQl1060 1061 //Data1062 Wave nf.Q = qw1063 nf.unitsQ = "1/A"1064 Wave nf.I = iw1065 nf.unitsI = "1/cm"1066 Wave nf.Idev = sw1067 nf.unitsIdev = "1/cm"1068 // for slit-smeared USANS, set only a 4th column to -dQv1069 Wave nf.dQl = dumWave1070 nf.unitsdQl= "1/A"1071 1072 //AJJ to fix with sensible values1073 nf.run = ""1074 nf.nameSASinstrument = "NIST IGOR Procedures"1075 nf.SASnote = ""1076 //1077 nf.sample_ID = baseStr1078 nf.title = baseStr1079 nf.radiation = "neutron"1080 //Do something with beamstop (rw[21])1081 nf.detector_name = "Re-written USANS data"1082 1083 nf.SASprocessnote = "Modified data written from folder "+baseStr+" on "+(date()+" "+time())1084 1085 nf.nameSASProcess = "NIST IGOR"1086 1087 else1088 //assume SANS data1089 Duplicate/O qw qbar,sigQ,fs1090 sigq = resw[p][0]1091 qbar = resw[p][1]1092 fs = resw[p][2]1093 1094 1095 //Data1096 Wave nf.Q = qw1097 nf.unitsQ = "1/A"1098 Wave nf.I = iw1099 nf.unitsI = "1/cm"1100 Wave nf.Idev = sw1101 nf.unitsIdev = "1/cm"1102 Wave nf.Qdev = sigQ1103 nf.unitsQdev = "1/A"1104 Wave nf.Qmean = qbar1105 nf.unitsQmean = "1/A"1106 Wave nf.Shadowfactor = fs1107 nf.unitsShadowfactor = "none"1108 1109 1110 //write out the standard header information1111 //fprintf refnum,"FILE: %s\t\t CREATED: %s\r\n",textw[0],textw[1]1112 1113 //AJJ to fix with sensible values1114 nf.run = ""1115 nf.nameSASinstrument = "NIST IGOR Procedures"1116 nf.SASnote = ""1117 //1118 nf.sample_ID = baseStr1119 nf.title = baseStr1120 nf.radiation = "neutron"1121 //Do something with beamstop (rw[21])1122 nf.detector_name = "Re-written data"1123 1124 nf.SASprocessnote = "Modified data written from folder "+baseStr+" on "+(date()+" "+time())1125 1126 nf.nameSASProcess = "NIST IGOR"1127 1128 endif1129 1130 1131 if(dialog)1132 PathInfo/S catPathName1133 fullPath = DoSaveFileDialog("Save data as",fname=baseStr+".xml")1134 If(cmpstr(fullPath,"")==0)1135 //user cancel, don't write out a file1136 Close/A1137 Abort "no data file was written"1138 Endif1139 //Print "dialog fullpath = ",fullpath1140 Endif1141 1142 1143 writeNISTXML(fullpath,nf)1144 //write confirmation of write operation to history area1145 Print "XML File written: ", GetFileNameFromPathNoSemi(fullPath)1146 KillWaves/Z tempShortProto1147 1148 SetDataFolder root:1149 1150 Return(0)1151 End1152 1153 1154 1155 1156 #else // if( Exists("XmlOpenFile") )1157 // No XMLutils XOP: provide dummy function so that IgorPro can compile dependent support code1158 FUNCTION LoadNISTXMLData(fileName,doPlot)1159 String fileName1160 Variable doPlot1161 Abort "XML function provided by XMLutils XOP is not available, get the XOP from : http://www.igorexchange.com/project/XMLutils (see http://www.smallangles.net/wgwiki/index.php/cansas1d_binding_IgorPro for details)"1162 RETURN(-6)1163 END1164 1165 1166 Function writeNISTXML(fileName, NISTfile)1167 String fileName, NISTfile1168 Abort "XML function provided by XMLutils XOP is not available, get the XOP from : http://www.igorexchange.com/project/XMLutils (see http://www.smallangles.net/wgwiki/index.php/cansas1d_binding_IgorPro for details)"1169 RETURN(-6)1170 End1171 1172 Function WriteXMLWaves_W_Protocol(type,fullpath,dialog)1173 String type,fullpath1174 Variable dialog //=1 will present dialog for name1175 1176 Abort "XML function provided by XMLutils XOP is not available, get the XOP from : http://www.igorexchange.com/project/XMLutils (see http://www.smallangles.net/wgwiki/index.php/cansas1d_binding_IgorPro for details)"1177 return(-6)1178 end1179 1180 Function WriteNSORTedXMLFile(q3,i3,sig3,firstFileName,secondFileName,thirdFileName,normTo,norm12,norm23,[res])1181 Wave q3,i3,sig3,res1182 String firstFileName,secondFileName,thirdFileName,normTo1183 Variable norm12,norm231184 1185 Abort "XML function provided by XMLutils XOP is not available, get the XOP from : http://www.igorexchange.com/project/XMLutils (see http://www.smallangles.net/wgwiki/index.php/cansas1d_binding_IgorPro for details)"1186 return(-6)1187 End1188 1189 Function ReWrite1DXMLData(folderStr)1190 String folderStr1191 1192 Abort "XML function provided by XMLutils XOP is not available, get the XOP from : http://www.igorexchange.com/project/XMLutils (see http://www.smallangles.net/wgwiki/index.php/cansas1d_binding_IgorPro for details)"1193 return(-6)1194 end1195 #endif1196 1197 1230 // if( Exists("XmlOpenFile") 1198 1231 //Needed to test whether file is XML. The load routine will then either give an error if XMLutils is not present or load the file if it is. 1199 function isXML(filestr)1232 Function isXML(filestr) 1200 1233 String filestr 1201 1234
Note: See TracChangeset
for help on using the changeset viewer.