Changeset 1067


Ignore:
Timestamp:
Sep 28, 2017 12:00:44 PM (5 years ago)
Author:
krzywon
Message:

Create single meta data writer for both 1D and 2D NXcanSAS data writers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/WriteHDF5.ipf

    r1066 r1067  
    122122        CreateVarNxCansas(fileID,dataParent,"sasdata","Qmean",qbar,units,inv_angstrom) 
    123123         
    124         // SASinstrument 
    125         String instrParent = parentBase + "sasinstrument/" 
    126         // Create SASinstrument entry 
    127         String instrumentBase = base + ":entry1:sasinstrument" 
    128         NewDataFolder/O/S $(instrumentBase) 
    129         Make/O/T/N=5 $(instrumentBase + ":attr") = {"canSAS_class","NX_class"} 
    130         Make/O/T/N=5 $(instrumentBase + ":attrVals") = {"SASinstrument","NXinstrument"} 
    131         CreateStrNxCansas(fileID,instrParent,"","",empty,$(instrumentBase + ":attr"),$(instrumentBase + ":attrVals")) 
    132          
    133         // SASaperture 
    134         String apertureParent = instrParent + "sasaperture/" 
    135         // Create SASaperture entry 
    136         String apertureBase = instrumentBase + ":sasaperture" 
    137         NewDataFolder/O/S $(apertureBase) 
    138         Make/O/T/N=5 $(apertureBase + ":attr") = {"canSAS_class","NX_class"} 
    139         Make/O/T/N=5 $(apertureBase + ":attrVals") = {"SASaperture","NXaperture"} 
    140         CreateStrNxCansas(fileID,apertureParent,"","",empty,$(apertureBase + ":attr"),$(apertureBase + ":attrVals")) 
    141         // Create SASaperture shape entry 
    142         Make/O/T/N=1 $(apertureBase + ":shape") = {"pinhole"} // TODO: Where do I get rectangular dimensions from? 
    143         CreateStrNxCansas(fileID,apertureParent,"sasaperture","shape",$(apertureBase + ":shape"),empty,empty) 
    144         // Create SASaperture x_gap entry 
    145         Make/O/N=1 $(apertureBase + ":x_gap") = {rw[24]} // TODO: Where do I get rectangular dimensions from? 
    146         CreateVarNxCansas(fileID,apertureParent,"sasaperture","x_gap",$(apertureBase + ":x_gap"),units,cm) 
    147         // Create SASaperture y_gap entry 
    148         Make/O/N=1 $(apertureBase + ":y_gap") = {rw[24]} // TODO: Where do I get rectangular dimensions from? 
    149         CreateVarNxCansas(fileID,apertureParent,"sasaperture","y_gap",$(apertureBase + ":y_gap"),units,cm) 
    150          
    151         // SAScollimation 
    152         String collimationParent = instrParent + "sascollimation/" 
    153         // Create SAScollimation entry 
    154         String collimationBase = instrumentBase + ":sascollimation" 
    155         NewDataFolder/O/S $(collimationBase) 
    156         Make/O/T/N=5 $(collimationBase + ":attr") = {"canSAS_class","NX_class"} 
    157         Make/O/T/N=5 $(collimationBase + ":attrVals") = {"SAScollimation","NXcollimator"} 
    158         CreateStrNxCansas(fileID,collimationParent,"","",empty,$(collimationBase + ":attr"),$(collimationBase + ":attrVals")) 
    159         // Create SAScollimation length entry 
    160         Make/O/N=1 $(collimationBase + ":length") = {15.3} // TODO: Get real value 
    161         CreateVarNxCansas(fileID,collimationParent,"sasaperture","length",$(collimationBase + ":length"),units,m) 
    162         // Create SAScollimation distance entry 
    163         Make/O/N=1 $(collimationBase + ":distance") = {rw[25]} 
    164         CreateVarNxCansas(fileID,collimationParent,"sasaperture","distance",$(collimationBase + ":distance"),units,m) 
    165          
    166         // SASdetector 
    167         String detectorParent = instrParent + "sasdetector/" 
    168         // Create SASdetector entry 
    169         String detectorBase = instrumentBase + ":sasdetector" 
    170         NewDataFolder/O/S $(detectorBase) 
    171         Make/O/T/N=5 $(detectorBase + ":attr") = {"canSAS_class","NX_class"} 
    172         Make/O/T/N=5 $(detectorBase + ":attrVals") = {"SASdetector","NXdetector"} 
    173         CreateStrNxCansas(fileID,detectorParent,"","",empty,$(detectorBase + ":attr"),$(detectorBase + ":attrVals")) 
    174         // Create SASdetector name entry 
    175         Make/O/T/N=1 $(detectorBase + ":name") = {textw[9]} 
    176         CreateStrNxCansas(fileID,detectorParent,"","name",$(detectorBase + ":name"),empty,empty) 
    177         // Create SASdetector distance entry 
    178         Make/O/N=1 $(detectorBase + ":SDD") = {rw[18]} 
    179         CreateVarNxCansas(fileID,detectorParent,"","SDD",$(detectorBase + ":SDD"),units,m) 
    180         // Create SASdetector beam_center_x entry 
    181         Make/O/N=1 $(detectorBase + ":beam_center_x") = {rw[16]} 
    182         CreateVarNxCansas(fileID,detectorParent,"","beam_center_x",$(detectorBase + ":beam_center_x"),units,pixel) 
    183         // Create SASdetector beam_center_y entry 
    184         Make/O/N=1 $(detectorBase + ":beam_center_y") = {rw[17]} 
    185         CreateVarNxCansas(fileID,detectorParent,"","beam_center_y",$(detectorBase + ":beam_center_y"),units,pixel) 
    186         // Create SASdetector x_pixel_size entry 
    187         Make/O/N=1 $(detectorBase + ":x_pixel_size") = {rw[10]} 
    188         CreateVarNxCansas(fileID,detectorParent,"","x_pixel_size",$(detectorBase + ":x_pixel_size"),units,mm) 
    189         // Create SASdetector y_pixel_size entry 
    190         Make/O/N=1 $(detectorBase + ":y_pixel_size") = {rw[13]} 
    191         CreateVarNxCansas(fileID,detectorParent,"","y_pixel_size",$(detectorBase + ":y_pixel_size"),units,mm) 
    192          
    193         // SASsource 
    194         String sourceParent = instrParent + "sassource/" 
    195         // Create SASdetector entry 
    196         String sourceBase = instrumentBase + ":sassource" 
    197         NewDataFolder/O/S $(sourceBase) 
    198         Make/O/T/N=5 $(sourceBase + ":attr") = {"canSAS_class","NX_class"} 
    199         Make/O/T/N=5 $(sourceBase + ":attrVals") = {"SASsource","NXsource"} 
    200         CreateStrNxCansas(fileID,sourceParent,"","",empty,$(sourceBase + ":attr"),$(sourceBase + ":attrVals")) 
    201         // Create SASsource radiation entry 
    202         Make/O/T/N=1 $(sourceBase + ":radiation") = {"Reactor Neutron Source"} 
    203         CreateStrNxCansas(fileID,sourceParent,"","radiation",$(sourceBase + ":radiation"),empty,empty) 
    204         // Create SASsource incident_wavelength entry 
    205         Make/O/N=1 $(sourceBase + ":incident_wavelength") = {rw[26]} 
    206         CreateVarNxCansas(fileID,sourceParent,"","incident_wavelength",$(sourceBase + ":incident_wavelength"),units,angstrom) 
    207         // Create SASsource incident_wavelength_spread entry 
    208         Make/O/N=1 $(sourceBase + ":incident_wavelength_spread") = {rw[27]} 
    209         CreateVarNxCansas(fileID,sourceParent,"","incident_wavelength_spread",$(sourceBase + ":incident_wavelength_spread"),units,angstrom) 
    210          
    211         // SASsample 
    212         String sampleParent = parentBase + "sassample/" 
    213         // Create SASsample entry 
    214         String sampleBase = base + ":entry1:sassample" 
    215         NewDataFolder/O/S $(sampleBase) 
    216         Make/O/T/N=5 $(sampleBase + ":attr") = {"canSAS_class","NX_class"} 
    217         Make/O/T/N=5 $(sampleBase + ":attrVals") = {"SASsample","NXsample"} 
    218         CreateStrNxCansas(fileID,sampleParent,"","",empty,$(sampleBase + ":attr"),$(sampleBase + ":attrVals")) 
    219         // Create SASsample name entry 
    220         Make/O/T/N=1 $(sampleBase + ":name") = {textw[6]} 
    221         CreateStrNxCansas(fileID,sampleParent,"","name",$(sampleBase + ":name"),empty,empty) 
    222         // Create SASsample thickness entry 
    223         Make/O/N=1 $(sampleBase + ":thickness") = {rw[5]} 
    224         CreateVarNxCansas(fileID,sampleParent,"","thickness",$(sampleBase + ":thickness"),units,cm) 
    225         // Create SASsample transmission entry 
    226         Make/O/N=1 $(sampleBase + ":transmission") = {rw[4]} 
    227         CreateVarNxCansas(fileID,sampleParent,"","transmission",$(sampleBase + ":transmission"),empty,empty) 
     124        // Write all meta data 
     125        WriteMetaData(fileID,base,parentBase,rw,textw) 
    228126         
    229127        // 
     
    446344         
    447345        // TODO: Reinstate ShadowFactor 
    448          
    449346        // CreateVarNxCansas(fileID,dataParent,"sasdata","ShadowFactor",fsubs,empty,empty) 
     347         
     348        // Write all meta data 
     349        WriteMetaData(fileID,base,parentBase,rw,textw) 
     350         
     351        // Close the file 
     352        if(fileID) 
     353                HDF5CloseFile /Z fileID 
     354        endif 
     355         
     356        // KillDataFolder/Z $base 
     357         
     358End 
     359 
     360// 
     361/////////////////////////////////////////////////////////////////////////// 
     362 
     363/////////////////////////////////////////////////////////////////////////// 
     364// - WriteMetaData - Method used to write non data elements into NXcanSAS 
     365// format. This is common between 1D and 2D data sets. 
     366 
     367Function WriteMetaData(fileID,base,parentBase,rw,textw) 
     368        String base,parentBase 
     369        Variable fileID 
     370        Wave rw 
     371        Wave/T textw 
     372         
     373        // Define common attribute waves 
     374        Make/T/N=1 empty = {""} 
     375        Make/T/N=1 units = {"units"} 
     376        Make/T/N=1 m = {"m"} 
     377        Make/T/N=1 mm = {"mm"} 
     378        Make/T/N=1 cm = {"cm"} 
     379        Make/T/N=1 pixel = {"pixel"} 
     380        Make/T/N=1 angstrom = {"A"} 
     381        Make/T/N=1 inv_cm = {"1/cm"} 
     382        Make/T/N=1 inv_angstrom = {"1/A"} 
    450383         
    451384        // SASinstrument 
     
    553486        Make/O/N=1 $(sampleBase + ":transmission") = {rw[4]} 
    554487        CreateVarNxCansas(fileID,sampleParent,"","transmission",$(sampleBase + ":transmission"),empty,empty) 
    555          
    556         // 
    557         /////////////////////////////////////////////////////////////////////////// 
    558          
    559         // Close the file 
    560         if(fileID) 
    561                 HDF5CloseFile /Z fileID 
    562         endif 
    563          
    564         // KillDataFolder/Z $base 
    565          
    566 End 
    567  
     488End 
     489         
    568490// 
    569491/////////////////////////////////////////////////////////////////////////// 
     492 
    570493 
    571494/////////////////////////////////////////////////////////////////////////// 
Note: See TracChangeset for help on using the changeset viewer.