Changeset 1170 for sans/Dev/branches/nxcansas_writer/NCNR_User_Procedures
- Timestamp:
- Jun 13, 2019 4:25:22 PM (4 years ago)
- Location:
- sans/Dev/branches/nxcansas_writer/NCNR_User_Procedures/Common
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sans/Dev/branches/nxcansas_writer/NCNR_User_Procedures/Common/NIST_NXcanSAS_v709.ipf
r1167 r1170 24 24 // Define local function variables 25 25 Variable fileID 26 String destStr="" 27 String parentBase = "/sasentry/" // HDF5 base path for all 26 String destStr="", parentBase, nxcansasBase 28 27 String/G base = "root:NXcanSAS_file" 29 30 KillDataFolder/Z $base31 28 32 29 // Define local waves … … 43 40 Endif 44 41 if(!fileID) 45 Print "Unable to create file at " + fullpath + "."42 abort "Unable to create file at " + fullpath + "." 46 43 else 44 Variable sasentry = NumVarOrDefault("root:Packages:NIST:gSASEntryNumber", 1) 45 sPrintf parentBase,"%s:sasentry%d",base,sasentry // Igor memory base path for all 46 sPrintf nxcansasBase,"/sasentry%d/",sasentry // HDF5 base path for all 47 47 48 destStr = "root:Packages:NIST:"+type 48 49 //*****these waves MUST EXIST, or IGOR Pro will crash, with a type 2 error**** … … 62 63 63 64 // Define common attribute waves 64 Make/T/ N=1 empty = {""}65 Make/T/ N=1 units = {"units"}66 Make/T/ N=1 inv_cm = {"1/cm"}67 Make/T/ N=1 inv_angstrom = {"1/A"}65 Make/T/O/N=1 empty = {""} 66 Make/T/O/N=1 units = {"units"} 67 Make/T/O/N=1 inv_cm = {"1/cm"} 68 Make/T/O/N=1 inv_angstrom = {"1/A"} 68 69 69 70 // Run Name and title 70 NewDataFolder/O/S $( base + ":entry1")71 Make/ T/N=1 $(base + ":entry1:title") = {textw[6]}72 CreateStrNxCansas(fileID, parentBase,"","title",$(base + ":entry1:title"),empty,empty)73 Make/ T/N=1 $(base + ":entry1:run") = {textw[0]}74 CreateStrNxCansas(fileID, parentBase,"","run",$(base + ":entry1:run"),empty,empty)71 NewDataFolder/O/S $(parentBase) 72 Make/O/T/N=1 $(parentBase + ":title") = {textw[6]} 73 CreateStrNxCansas(fileID,nxcansasBase,"","title",$(parentBase + ":title"),empty,empty) 74 Make/O/T/N=1 $(parentBase + ":run") = {textw[0]} 75 CreateStrNxCansas(fileID,nxcansasBase,"","run",$(parentBase + ":run"),empty,empty) 75 76 76 77 // SASData 77 String dataParent = parentBase + "sasdata/"78 String dataParent = nxcansasBase + "sasdata/" 78 79 // Create SASdata entry 79 String dataBase = base + ":entry1:sasdata"80 String dataBase = parentBase + ":sasdata" 80 81 NewDataFolder/O/S $(dataBase) 81 82 Make/O/T/N=5 $(dataBase + ":attr") = {"canSAS_class","signal","I_axes","NX_class","Q_indices", "timestamp"} … … 89 90 // Create i entry 90 91 NewDataFolder/O/S $(dataBase + ":i") 91 Make/ T/N=2 $(dataBase + ":i:attr") = {"units","uncertainties"}92 Make/ T/N=2 $(dataBase + ":i:attrVals") = {"1/cm","Idev"}92 Make/O/T/N=2 $(dataBase + ":i:attr") = {"units","uncertainties"} 93 Make/O/T/N=2 $(dataBase + ":i:attrVals") = {"1/cm","Idev"} 93 94 CreateVarNxCansas(fileID,dataParent,"sasdata","I",inten,$(dataBase + ":i:attr"),$(dataBase + ":i:attrVals")) 94 95 // Create idev entry … … 99 100 100 101 // Write all meta data 101 WriteMetaData(fileID, base,parentBase,rw,textw)102 WriteMetaData(fileID,parentBase,nxcansasBase,rw,textw) 102 103 103 104 // … … 130 131 // Define local function variables 131 132 Variable fileID 132 String destStr="",typeStr="" 133 String parentBase = "/sasentry/" // HDF5 base path for all 133 String destStr="",typeStr="", parentBase, nxcansasBase 134 134 String/G base = "root:NXcanSAS_file" 135 136 KillDataFolder/Z $base137 135 138 136 // Define local waves … … 149 147 Endif 150 148 if(!fileID) 151 Print "Unable to create file at " + fullpath + "."149 abort "Unable to create file at " + fullpath + "." 152 150 else 151 Variable sasentry = NumVarOrDefault("root:Packages:NIST:gSASEntryNumber", 1) 152 sPrintf parentBase,"%s:sasentry%d",base,sasentry // Igor memory base path for all 153 sPrintf nxcansasBase,"/sasentry%d/",sasentry // HDF5 base path for all 154 153 155 destStr = "root:Packages:NIST:"+type 154 156 … … 160 162 typeStr = ":data" 161 163 endif 162 164 NVAR pixelsX = root:myGlobals:gNPixelsX 163 165 NVAR pixelsY = root:myGlobals:gNPixelsY 164 166 Wave data=$(destStr+typeStr) … … 260 262 261 263 // Define common attribute waves 262 Make/ T/N=1 empty = {""}263 Make/ T/N=1 units = {"units"}264 Make/ T/N=1 inv_cm = {"1/cm"}265 Make/ T/N=1 inv_angstrom = {"1/A"}264 Make/O/T/N=1 empty = {""} 265 Make/O/T/N=1 units = {"units"} 266 Make/O/T/N=1 inv_cm = {"1/cm"} 267 Make/O/T/N=1 inv_angstrom = {"1/A"} 266 268 267 269 // Run Name and title 268 NewDataFolder/O/S $(base + ":entry1")269 Make/ T/N=1 $(base + ":entry1:title") = {textw[6]}270 CreateStrNxCansas(fileID,parentBase,"","title",$(base + ":entry1:title"),empty,empty)271 Make/ T/N=1 $(base + ":entry1:run") = {textw[0]}272 CreateStrNxCansas(fileID, parentBase,"","run",$(base + ":entry1:run"),empty,empty)270 NewDataFolder/O/S $(base + parentBase) 271 Make/O/T/N=1 $(base + parentBase + ":title") = {textw[6]} 272 CreateStrNxCansas(fileID,parentBase,"","title",$(base + parentBase + ":title"),empty,empty) 273 Make/O/T/N=1 $(base + parentBase + ":run") = {textw[0]} 274 CreateStrNxCansas(fileID,nxcansasBase,"","run",$(base + parentBase + ":run"),empty,empty) 273 275 274 276 // SASData 275 String dataParent = parentBase + "sasdata/"277 String dataParent = nxcansasBase + "sasdata/" 276 278 // Create SASdata entry 277 String dataBase = base + ":entry1:sasdata"279 String dataBase = base + parentBase + ":sasdata" 278 280 NewDataFolder/O/S $(dataBase) 279 281 Make/O/T/N=5 $(dataBase + ":attr") = {"canSAS_class","signal","I_axes","NX_class","Q_indices", "timestamp"} … … 282 284 // Create i entry 283 285 NewDataFolder/O/S $(dataBase + ":i") 284 Make/ T/N=2 $(dataBase + ":i:attr") = {"units","uncertainties"}285 Make/ T/N=2 $(dataBase + ":i:attrVals") = {"1/cm","Idev"}286 Make/O/T/N=2 $(dataBase + ":i:attr") = {"units","uncertainties"} 287 Make/O/T/N=2 $(dataBase + ":i:attrVals") = {"1/cm","Idev"} 286 288 CreateVarNxCansas(fileID,dataParent,"sasdata","I",data,$(dataBase + ":i:attr"),$(dataBase + ":i:attrVals")) 287 289 … … 293 295 // Create qx and qy entry 294 296 NewDataFolder/O/S $(dataBase + ":q") 295 Make/ T/N=2 $(dataBase + ":q:attr") = {"units"}//,"resolutions"}296 Make/ T/N=2 $(dataBase + ":q:attrVals") = {"1/angstrom"}//,"Qdev"}297 Make/O/T/N=2 $(dataBase + ":q:attr") = {"units"}//,"resolutions"} 298 Make/O/T/N=2 $(dataBase + ":q:attrVals") = {"1/angstrom"}//,"Qdev"} 297 299 CreateVarNxCansas(fileID,dataParent,"sasdata","Q",qxy_vals,$(dataBase + ":q:attr"),$(dataBase + ":q:attrVals")) 298 300 … … 305 307 306 308 // Write all meta data 307 WriteMetaData(fileID, base,parentBase,rw,textw)309 WriteMetaData(fileID,parentBase,nxcansasBase,rw,textw) 308 310 309 311 // Close the file … … 330 332 331 333 // Define common attribute waves 332 Make/T/ N=1 empty = {""}333 Make/T/ N=1 units = {"units"}334 Make/T/ N=1 m = {"m"}335 Make/T/ N=1 mm = {"mm"}336 Make/T/ N=1 cm = {"cm"}337 Make/T/ N=1 pixel = {"pixel"}338 Make/T/ N=1 angstrom = {"A"}334 Make/T/O/N=1 empty = {""} 335 Make/T/O/N=1 units = {"units"} 336 Make/T/O/N=1 m = {"m"} 337 Make/T/O/N=1 mm = {"mm"} 338 Make/T/O/N=1 cm = {"cm"} 339 Make/T/O/N=1 pixel = {"pixel"} 340 Make/T/O/N=1 angstrom = {"A"} 339 341 340 342 // SASinstrument 341 343 String instrParent = parentBase + "sasinstrument/" 342 344 // Create SASinstrument entry 343 String instrumentBase = base + ": entry1:sasinstrument"345 String instrumentBase = base + ":sasinstrument" 344 346 NewDataFolder/O/S $(instrumentBase) 345 347 Make/O/T/N=5 $(instrumentBase + ":attr") = {"canSAS_class","NX_class"} … … 430 432 String sampleParent = parentBase + "sassample/" 431 433 // Create SASsample entry 432 String sampleBase = base + ": entry1:sassample"434 String sampleBase = base + ":sassample" 433 435 NewDataFolder/O/S $(sampleBase) 434 436 Make/O/T/N=5 $(sampleBase + ":attr") = {"canSAS_class","NX_class"} … … 479 481 End 480 482 481 482 483 // Open\ file with a known path 483 484 Function NxCansas_OpenFile(fullpath) … … 486 487 Variable fileID 487 488 fileName = ParseFilePath(3,fullpath,":",0,0) 488 Print fileName489 489 Make/T/O/N=1 $("root:file_name") = fileName 490 490 fullpath = ReplaceString(":\\", fullpath, ":") … … 511 511 Function NxCansas_InitializeFile(fileID) 512 512 Variable fileID 513 String parent 513 String parent,nxParent 514 514 String/G base = "root:NXcanSAS_file" 515 Make/T/N=1 $(base + ":vals") = {""} 516 Make/T/N=3 $(base + ":attr") = {"NX_class", "canSAS_class", "version"} 517 Make/T/N=3 $(base + ":attrVals") = {"NXentry", "SASentry", "1.0"} 518 parent = "/sasentry/" 519 CreateStrNxCansas(fileID,parent,"","",$(base + ":vals"),$(base + ":attr"),$(base + ":attrVals")) 520 Make/T/N=1 $(base + ":entryAttr") = {""} 521 Make/T/N=1 $(base + ":entryAttrVals") = {""} 522 CreateStrNxCansas(fileID,parent,"","definition",{"NXcanSAS"},$(base + ":entryAttr"),$(base + ":entryAttrVals")) 515 Variable sasentry = NumVarOrDefault("root:Packages:NIST:gSASEntryNumber", 1) 516 sPrintf parent,":sasentry%d",sasentry 517 String location = base + parent 518 sPrintf nxParent,"/sasentry%d/",sasentry 519 NewDataFolder/O/S $(location) 520 Make/T/N=1 $(location + ":vals") = {""} 521 Make/T/N=3 $(location + ":attr") = {"NX_class", "canSAS_class", "version"} 522 Make/T/N=3 $(location + ":attrVals") = {"NXentry", "SASentry", "1.0"} 523 CreateStrNxCansas(fileID,nxParent,"","",$(location + ":vals"),$(location + ":attr"),$(location + ":attrVals")) 524 Make/T/N=1 $(location + ":entryAttr") = {""} 525 Make/T/N=1 $(location + ":entryAttrVals") = {""} 526 CreateStrNxCansas(fileID,nxParent,"","definition",{"NXcanSAS"},$(location + ":entryAttr"),$(location + ":entryAttrVals")) 523 527 End 524 528 … … 685 689 686 690 filename = ParseFilePath(3,fileStr,":",0,0) 687 Print "file string: ",filename 688 String/G loadDir = "root:" + filename 689 690 String I_dataStore = filename + "_i" 691 String Q_dataStore = filename + "q" 692 String dI_dataStore = filename + "s" 691 String basestr 692 if (!cmpstr(outstr, "")) //Outstr = "", cmpstr returns 0 693 baseStr = ShortFileNameString(CleanupName(filename,0)) 694 baseStr = CleanupName(baseStr,0) //in case the user added odd characters 695 else 696 baseStr = outstr //for output, hopefully correct length as passed in 697 endif 698 String/G loadDir = "root:" + baseStr 699 700 String I_dataStore = baseStr + "_i" 701 String Q_dataStore = baseStr + "_q" 702 String dQ_dataStore = baseStr + "_dq" 703 String dQl_dataStore = baseStr + "_dql" 704 String dQw_dataStore = baseStr + "_dqw" 705 String dI_dataStore = baseStr + "_s" 693 706 694 707 //go back to the root folder and clean up before leaving 695 708 NewDataFolder/O/S $loadDir 709 Make/O/N=52 $(loadDir + ":realsRead") 710 Make/O/T/N=11 $(loadDir + ":textRead") 696 711 697 712 if(fileID) 698 713 HDF5ListGroup /F/R/Type=1/Z fileID,"/" 699 714 String groupList = S_HDF5ListGroup 700 Print "grouplist: ",groupList 715 716 // 717 // TODO: Differentiate between 1D, 2D, and USANS data (resolutions) (DO I NEED TO?) 718 // 701 719 702 720 Variable groupID 703 HDF5OpenGroup /Z fileID, "/sasentry/sasdata", groupID 704 HDF5LoadData /O/N=$I_dataStore fileID, "/sasentry/sasdata/I" 705 HDF5LoadData /O/N=$Q_dataStore fileID, "/sasentry/sasdata/Q" 706 HDF5LoadData /O/N=$dI_dataStore fileID, "/sasentry/sasdata/Idev" 721 Variable inc = 1 722 String entryUnformatted = "/sasentry%d/" 723 String entryBase 724 sPrintf entryBase,entryUnformatted,inc 725 // Open first group 726 HDF5OpenGroup /Z fileID, entryBase + "sasdata/", groupID 727 do 728 // Load in data 729 HDF5LoadData /O/Z/N=$I_dataStore fileID, entryBase + "sasdata/I" 730 HDF5LoadData /O/Z/N=$Q_dataStore fileID, entryBase + "sasdata/Q" 731 HDF5LoadData /O/Z/N=$dQ_dataStore fileID, entryBase + "sasdata/dQ" 732 HDF5LoadData /O/Z/N=$dQl_dataStore fileID, entryBase + "sasdata/dQl" 733 HDF5LoadData /O/Z/N=$dQw_dataStore fileID, entryBase + "sasdata/dQw" 734 HDF5LoadData /O/Z/N=$dI_dataStore fileID, entryBase + "sasdata/Idev" 735 // Load in Meta Data 736 LoadMetaData(fileID,loadDir,entryBase) 737 // Open next group to see if it exists 738 inc += 1 739 sPrintf entryBase,entryUnformatted,inc 740 HDF5OpenGroup /Z fileID, entryBase + "sasdata/", groupID 741 while(groupID != 0) 707 742 708 743 //plot if desired … … 710 745 Print GetDataFolder(1) 711 746 712 String w0 = loadDir + ":" +Q_dataStore713 String w1 = loadDir + ":" +I_dataStore714 String w2 = loadDir + ":" +dI_dataStore747 String w0 = Q_dataStore 748 String w1 = I_dataStore 749 String w2 = dI_dataStore 715 750 716 751 // assign colors randomly … … 731 766 else 732 767 //new graph 733 SetDataFolder $loadDir //sometimes I end up back in root: here, and I can't figure out why!734 768 Display $w1 vs $w0 735 769 ModifyGraph log=1,mode($w1)=3,marker($w1)=19,msize($w1)=2,rgb($w1)=(rr,gg,bb),tickUnit=1 … … 760 794 HDF5CloseFile /Z fileID 761 795 endif 762 763 // KillDataFolder /Z $loadDir764 796 765 797 end 798 799 Function LoadMetaData(fileID,loadDir,parentBase) 800 String parentBase,loadDir 801 Variable fileID 802 Variable groupID 803 SetDataFolder $(loadDir) 804 Wave rw = $(loadDir + ":realsRead") 805 Wave/T textw = $(loadDir + ":textRead") 806 807 // Title 808 HDF5OpenGroup /Z fileID, parentBase, groupID 809 HDF5LoadData /O/Z/N=title fileID, parentBase + "title" 810 Wave/T title = $(loadDir + ":title") 811 812 // SASinstrument 813 String instrParent = parentBase + "sasinstrument/" 814 815 // SASaperture 816 String apertureParent = instrParent + "sasaperture/" 817 HDF5OpenGroup /Z fileID, apertureParent, groupID 818 HDF5LoadData /O/Z/N=xg fileID, apertureParent + "x_gap" 819 Wave xg = $(loadDir + ":xg") 820 821 // SAScollimation 822 String collimationParent = instrParent + "sascollimation/" 823 HDF5OpenGroup /Z fileID, collimationParent, groupID 824 HDF5LoadData /O/Z/N=cdis fileID, collimationParent + "distance" 825 Wave cdis = $(loadDir + ":cdis") 826 827 // SASdetector 828 String detectorParent = instrParent + "sasdetector/" 829 HDF5OpenGroup /Z fileID, detectorParent, groupID 830 HDF5LoadData /O/Z/N=detname fileID, detectorParent + "name" 831 HDF5LoadData /O/Z/N=sdd fileID, detectorParent + "SDD" 832 HDF5LoadData /O/Z/N=bcx fileID, detectorParent + "beam_center_x" 833 HDF5LoadData /O/Z/N=bcy fileID, detectorParent + "beam_center_y" 834 HDF5LoadData /O/Z/N=xps fileID, detectorParent + "x_pixel_size" 835 HDF5LoadData /O/Z/N=xpy fileID, detectorParent + "y_pixel_size" 836 Wave/T detname = $(loadDir + ":detname") 837 Wave sdd = $(loadDir + ":sdd") 838 Wave bcx = $(loadDir + ":bcx") 839 Wave bcy = $(loadDir + ":bcy") 840 Wave xps = $(loadDir + ":xps") 841 Wave xpy = $(loadDir + ":xpy") 842 843 // SASsource 844 String sourceParent = instrParent + "sassource/" 845 HDF5OpenGroup /Z fileID, sourceParent, groupID 846 HDF5LoadData /O/Z/N=wvel fileID, sourceParent + "incident_wavelength" 847 HDF5LoadData /O/Z/N=wvels fileID, sourceParent + "incident_wavelength_spread" 848 Wave wvel = $(loadDir + ":wvel") 849 Wave wvels = $(loadDir + ":wvels") 850 851 // SASsample 852 String sampleParent = parentBase + "sassample/" 853 HDF5OpenGroup /Z fileID, sampleParent, groupID 854 HDF5LoadData /O/Z/N=smplname fileID, sampleParent + "name" 855 HDF5LoadData /O/Z/N=smplthick fileID, sampleParent + "thickness" 856 HDF5LoadData /O/Z/N=smpltrans fileID, sampleParent + "transmission" 857 Wave/T smplname = $(loadDir + ":smplname") 858 Wave smplthick = $(loadDir + ":smplthick") 859 Wave smpltrans = $(loadDir + ":smpltrans") 860 861 textw[0] = title[0] 862 textw[6] = smplname[0] 863 textw[9] = detname[0] 864 rw[4] = smplthick[0] 865 rw[5] = smpltrans[0] 866 rw[10] = xps[0] 867 rw[13] = xpy[0] 868 rw[16] = bcx[0] 869 rw[17] = bcy[0] 870 rw[18] = sdd[0] 871 rw[24] = xg[0] 872 rw[25] = cdis[0] 873 rw[26] = wvel[0] 874 rw[27] = wvels[0] 875 876 KillWaves title,smplname,detname,smplthick,smpltrans,xps,xpy,bcx,bcy,sdd,xg,cdis,wvel,wvels 877 878 End 766 879 767 880 // … … 777 890 String filestr 778 891 779 Variable fileID =0892 Variable fileID=0,groupID=0 780 893 Int isHDF5File = 0 781 894 782 895 fileID = NxCansas_OpenFile(filestr) 896 HDF5ListGroup /F/R/Type=1/Z fileID,"/" 897 Variable length = strlen(S_HDF5ListGroup) 898 899 if (numtype(length) != 2) 900 isHDF5File = 1 901 endif 783 902 784 903 if (fileID != 0) 785 isHDF5File = 1786 904 // Close the file 787 905 HDF5CloseFile /Z fileID -
sans/Dev/branches/nxcansas_writer/NCNR_User_Procedures/Common/Packages/PlotManager/PlotUtilsMacro_v40.ipf
r1167 r1170 1427 1427 val = NumVarOrDefault("root:Packages:NIST:gDoAdjustRAW_Atten",0) 1428 1428 Variable/G root:Packages:NIST:gDoAdjustRAW_Atten=val 1429 1430 // integer for writing multiple sasentries in XML and NXcanSAS data 1431 val = NumVarOrDefault("root:Packages:NIST:gSASEntryNumber", 1 ) 1432 Variable/G root:Packages:NIST:gSASEntryNumber = val 1429 1433 1430 1434 /// items for SANS Analysis
Note: See TracChangeset
for help on using the changeset viewer.