Changeset 1172


Ignore:
Timestamp:
Jun 14, 2019 4:16:08 PM (3 years ago)
Author:
krzywon
Message:

Update the USANS writer to generalize the meta data and allow for multiple sasentry per file (untested).

Location:
sans/Dev/branches/nxcansas_writer/NCNR_User_Procedures/Reduction/USANS
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • sans/Dev/branches/nxcansas_writer/NCNR_User_Procedures/Reduction/USANS/COR_Graph.ipf

    r1161 r1172  
    264264        if (useXMLOutput == 1) 
    265265                WriteXMLUSANSWaves(type,"",ptA,ptB,1) 
    266         else if (useNXcanSASOutput == 1) 
     266        elseif (useNXcanSASOutput == 1) 
    267267                WriteUSANSNXCanSAS(type,"",ptA,ptB,1) 
    268268        else 
  • sans/Dev/branches/nxcansas_writer/NCNR_User_Procedures/Reduction/USANS/NCNR_USANS_Includes_v230.ipf

    r903 r1172  
    2525#include "PlotUtilsMacro_v40",version >= 2.20 
    2626#include "NIST_XML_v40"                                 //cansas file writer 
     27#include "WriteUSANSNXcanSAS"          //NXcanSAS file writer 
    2728#include "USANS_SlitSmearing_v40"        
    2829#include "WriteUSANSData",version >= 2.20        
  • sans/Dev/branches/nxcansas_writer/NCNR_User_Procedures/Reduction/USANS/WriteUSANSNXcanSAS.ipf

    r1157 r1172  
    2828        String dateStr=date()+" "+time() 
    2929 
    30         String parentBase = "/sasentry/" // HDF5 base path for all  
     30        String parentBase,nxcansasBase 
    3131        String/G base = "root:NXcanSAS_USANS_file" 
     32         
     33        Variable sasentry = NumVarOrDefault("root:Packages:NIST:gSASEntryNumber", 1) 
     34        sPrintf parentBase,"%s:sasentry%d",base,sasentry // Igor memory base path for all 
     35        sPrintf nxcansasBase,"/sasentry%d/",sasentry // HDF5 base path for all 
    3236         
    3337        KillDataFolder/Z $base 
     
    7478         
    7579        // Run Name and title 
    76         NewDataFolder/O/S $(base + ":entry1") 
    77         Make/T/N=1 $(base + ":entry1:title") = {StringByKey("LABEL",note(inten),":",";")} 
    78         CreateStrNxCansas(fileID,parentBase,"","title",$(base + ":entry1:title"),empty,empty) 
    79         Make/T/N=1 $(base + ":entry1:run") = {""} 
    80         CreateStrNxCansas(fileID,parentBase,"","run",$(base + ":entry1:run"),empty,empty) 
     80        NewDataFolder/O/S $(parentBase) 
     81        Make/T/N=1 $(parentBase + ":title") = {StringByKey("LABEL",note(inten),":",";")} 
     82        CreateStrNxCansas(fileID,nxcansasBase,"","title",$(parentBase + ":title"),empty,empty) 
     83        Make/T/N=1 $(parentBase + ":run") = {""} 
     84        CreateStrNxCansas(fileID,nxcansasBase,"","run",$(parentBase + ":run"),empty,empty) 
    8185         
    8286        // SASData 
    83         String dataParent = parentBase + "sasdata/" 
     87        String dataParent = nxcansasBase + "sasdata/" 
    8488        // Create SASdata entry 
    85         String dataBase = base + ":entry1:sasdata" 
     89        String dataBase = parentBase + ":sasdata" 
    8690        NewDataFolder/O/S $(dataBase) 
    8791        Make/O/T/N=5 $(dataBase + ":attr") = {"canSAS_class","signal","I_axes","NX_class","Q_indices", "timestamp"} 
     
    105109        CreateVarNxCansas(fileID,dataParent,"sasdata","Qmean",res2,units,inv_angstrom) 
    106110         
    107         // 
    108111        ////////////////////////////////////////////////////////////////////////////////////////////// 
    109          
    110         ////////////////////////////////////////////////////////////////////////////////////////////// 
    111         // 
    112         // Write USANS meta data 
    113          
    114          
    115         //tailor the output given the type of data written out... 
    116         WAVE inten_EMP=$(USANSFolder+":EMP:DetCts") 
    117         String samStr="",empStr="",samLabelStr="",paramStr="",empLevStr="",bkgLevStr="" 
    118         String pkStr="", processNote="" 
    119         NVAR TransWide = $(USANSFolder+":Globals:MainPanel:gTransWide") 
    120         NVAR TransRock = $(USANSFolder+":Globals:MainPanel:gTransRock") 
    121         NVAR empCts = $(USANSFolder+":Globals:MainPanel:gEmpCts") 
    122         NVAR bkgCts = $(USANSFolder+":Globals:MainPanel:gBkgCts") 
    123         NVAR thick = $(USANSFolder+":Globals:MainPanel:gThick") 
    124          
    125         strswitch(type) 
    126                 case "SAM":              
    127                         samStr = type +" FILES: "+StringByKey("FILE",note(inten),":",";") 
    128                         empStr = "Uncorrected SAM data" 
    129                         empLevStr = "Uncorrected SAM data" 
    130                         bkgLevStr = "Uncorrected SAM data" 
    131                         paramStr = "Uncorrected SAM data" 
    132                         pkStr += "SAM PEAK ANGLE: "+num2str(QpkFromNote("SAM")) 
    133                         break                                            
    134                 case "EMP":      
    135                         samStr = type +" FILES: "+StringByKey("FILE",note(inten),":",";") 
    136                         empStr = "Uncorrected EMP data" 
    137                         empLevStr = "Uncorrected EMP data" 
    138                         bkgLevStr = "Uncorrected EMP data" 
    139                         paramStr = "Uncorrected EMP data" 
    140                         pkStr += "EMP PEAK ANGLE: "+num2str(QpkFromNote("EMP")) 
    141                         break 
    142                 default:                //"COR" is the default   
    143                         samStr = type +" FILES: "+StringByKey("FILE",note(inten),":",";") 
    144                         empStr = "EMP FILES: "+StringByKey("FILE",note(inten_EMP),":",";")       
    145                         empLevStr = "EMP LEVEL: " + num2str(empCts) 
    146                         bkgLevStr = "BKG LEVEL: " + num2str(bkgCts) 
    147                         paramStr = "Ds = "+num2str(thick)+" cm ; " 
    148                         paramStr += "Twide = "+num2Str(TransWide)+" ; " 
    149                         paramStr += "Trock = "+num2str(TransRock)        
    150                         pkStr += "SAM PEAK ANGLE: "+num2str(QpkFromNote("SAM")) 
    151                         pkStr += " ; EMP PEAK ANGLE: "+num2str(QpkFromNote("EMP"))                               
    152         endswitch 
    153  
    154         processNote = samStr+"\n"+dateStr+"\n"+samLabelStr+"\n"+empStr+"\n"+paramStr+"\n"+pkStr+"\n" 
    155         processNote += empLevStr + " ; "+bkglevStr+"\n" 
    156          
    157         // SASinstrument 
    158         String instrParent = parentBase + "sasinstrument/" 
    159         // Create SASinstrument entry 
    160         String instrumentBase = base + ":entry1:sasinstrument" 
    161         NewDataFolder/O/S $(instrumentBase) 
    162         Make/O/T/N=5 $(instrumentBase + ":attr") = {"canSAS_class","NX_class"} 
    163         Make/O/T/N=5 $(instrumentBase + ":attrVals") = {"SASinstrument","NXinstrument"} 
    164         CreateStrNxCansas(fileID,instrParent,"","",empty,$(instrumentBase + ":attr"),$(instrumentBase + ":attrVals")) 
    165          
    166         // SASaperture 
    167         String apertureParent = instrParent + "sasaperture/" 
    168         // Create SASaperture entry 
    169         String apertureBase = instrumentBase + ":sasaperture" 
    170         NewDataFolder/O/S $(apertureBase) 
    171         Make/O/T/N=5 $(apertureBase + ":attr") = {"canSAS_class","NX_class"} 
    172         Make/O/T/N=5 $(apertureBase + ":attrVals") = {"SASaperture","NXaperture"} 
    173         CreateStrNxCansas(fileID,apertureParent,"","",empty,$(apertureBase + ":attr"),$(apertureBase + ":attrVals")) 
    174          
    175         // Create SASaperture shape entry 
    176         Make/O/T/N=1 $(apertureBase + ":shape") = {"slit"}  
    177         CreateStrNxCansas(fileID,apertureParent,"sasaperture","shape",$(apertureBase + ":shape"),empty,empty) 
    178         // Create SASaperture x_gap entry 
    179         Make/O/N=1 $(apertureBase + ":x_gap") = {0.1} 
    180         CreateVarNxCansas(fileID,apertureParent,"sasaperture","x_gap",$(apertureBase + ":x_gap"),units,cm) 
    181         // Create SASaperture y_gap entry 
    182         Make/O/N=1 $(apertureBase + ":y_gap") = {5.0} 
    183         CreateVarNxCansas(fileID,apertureParent,"sasaperture","y_gap",$(apertureBase + ":y_gap"),units,cm) 
    184  
    185         // SASdetector 
    186         String detectorParent = instrParent + "sasdetector/" 
    187         // Create SASdetector entry 
    188         String detectorBase = instrumentBase + ":sasdetector" 
    189         NewDataFolder/O/S $(detectorBase) 
    190         Make/O/T/N=5 $(detectorBase + ":attr") = {"canSAS_class","NX_class"} 
    191         Make/O/T/N=5 $(detectorBase + ":attrVals") = {"SASdetector","NXdetector"} 
    192         CreateStrNxCansas(fileID,detectorParent,"","",empty,$(detectorBase + ":attr"),$(detectorBase + ":attrVals")) 
    193         // Create SASdetector name entry 
    194         Make/O/T/N=1 $(detectorBase + ":name") = {"BT5 DETECTOR ARRAY"} 
    195         CreateStrNxCansas(fileID,detectorParent,"","name",$(detectorBase + ":name"),empty,empty) 
    196          
    197         // SASsource 
    198         String sourceParent = instrParent + "sassource/" 
    199         // Create SASdetector entry 
    200         String sourceBase = instrumentBase + ":sassource" 
    201         NewDataFolder/O/S $(sourceBase) 
    202         Make/O/T/N=5 $(sourceBase + ":attr") = {"canSAS_class","NX_class"} 
    203         Make/O/T/N=5 $(sourceBase + ":attrVals") = {"SASsource","NXsource"} 
    204         CreateStrNxCansas(fileID,sourceParent,"","",empty,$(sourceBase + ":attr"),$(sourceBase + ":attrVals")) 
    205         // Create SASsource radiation entry 
    206         Make/O/T/N=1 $(sourceBase + ":radiation") = {"Reactor Neutron Source"} 
    207         CreateStrNxCansas(fileID,sourceParent,"","radiation",$(sourceBase + ":radiation"),empty,empty) 
    208         // Create SASsource incident_wavelength entry 
    209         Make/O/N=1 $(sourceBase + ":incident_wavelength") = {2.38} 
    210         CreateVarNxCansas(fileID,sourceParent,"","incident_wavelength",$(sourceBase + ":incident_wavelength"),units,angstrom) 
    211         // Create SASsource incident_wavelength_spread entry 
    212         Make/O/N=1 $(sourceBase + ":incident_wavelength_spread") = {0.06} 
    213         CreateVarNxCansas(fileID,sourceParent,"","incident_wavelength_spread",$(sourceBase + ":incident_wavelength_spread"),units,angstrom) 
    214          
    215         // SASsample 
    216         String sampleParent = parentBase + "sassample/" 
    217         // Create SASsample entry 
    218         String sampleBase = base + ":entry1:sassample" 
    219         NewDataFolder/O/S $(sampleBase) 
    220         Make/O/T/N=5 $(sampleBase + ":attr") = {"canSAS_class","NX_class"} 
    221         Make/O/T/N=5 $(sampleBase + ":attrVals") = {"SASsample","NXsample"} 
    222         CreateStrNxCansas(fileID,sampleParent,"","",empty,$(sampleBase + ":attr"),$(sampleBase + ":attrVals")) 
    223         // Create SASsample name entry 
    224         Make/O/T/N=1 $(sampleBase + ":name") = {StringByKey("LABEL",note(inten),":",";")} 
    225         CreateStrNxCansas(fileID,sampleParent,"","name",$(sampleBase + ":name"),empty,empty) 
    226         // Create SASsample thickness entry 
    227         Make/O/N=1 $(sampleBase + ":thickness") = {thick} 
    228         CreateVarNxCansas(fileID,sampleParent,"","thickness",$(sampleBase + ":thickness"),units,cm) 
    229         // Create SASsample transmission entry 
    230         Make/O/N=1 $(sampleBase + ":transmission") = {TransWide} 
    231         CreateVarNxCansas(fileID,sampleParent,"","transmission",$(sampleBase + ":transmission"),empty,empty) 
    232          
    233         // SASProcess 
    234         String processParent = parentBase + "sasprocess/" 
    235         // Create SASsample entry 
    236         String processBase = base + ":entry1:sasprocess" 
    237         NewDataFolder/O/S $(processBase) 
    238         Make/O/T/N=5 $(processBase + ":attr") = {"canSAS_class","NX_class"} 
    239         Make/O/T/N=5 $(processBase + ":attrVals") = {"SASprocess","NXprocess"} 
    240         CreateStrNxCansas(fileID,processParent,"","",empty,$(processBase + ":attr"),$(processBase + ":attrVals")) 
    241         // Create SASsample name entry 
    242         Make/O/T/N=1 $(processBase + ":name") = {"NIST IGOR"} 
    243         CreateStrNxCansas(fileID,processParent,"","name",$(processBase + ":name"),empty,empty) 
    244         // Create SASsample thickness entry 
    245         Make/O/T/N=1 $(sampleBase + ":note") = {processNote} 
    246         CreateVarNxCansas(fileID,processParent,"","note",$(processBase + ":note"),units,cm) 
     112        // Write the meta data to the file 
     113        WriteUSANSNXcanSASMetaData(fileID,type,parentBase,nxcansasBase,dateStr) 
    247114         
    248115        //write confirmation of write operation to history area 
    249         Print "Averaged XML File written: ", GetFileNameFromPathNoSemi(fullPath) 
     116        Print "Averaged NXcanSAS File written: ", GetFileNameFromPathNoSemi(fullPath) 
    250117        KillWaves/Z dumWave 
    251118         
     
    257124End 
    258125 
    259  
    260126Function WriteNXcanSASUSANSDesmeared(fullpath,lo,hi,dialog) 
    261127         
     
    271137        String dateStr=date()+" "+time() 
    272138 
    273         String parentBase = "/sasentry/" // HDF5 base path for all  
     139        String parentBase,nxcansasBase 
    274140        String/G base = "root:NXcanSAS_USANS_file" 
     141         
     142        Variable sasentry = NumVarOrDefault("root:Packages:NIST:gSASEntryNumber", 1) 
     143        sPrintf parentBase,"%s:sasentry%d",base,sasentry // Igor memory base path for all 
     144        sPrintf nxcansasBase,"/sasentry%d/",sasentry // HDF5 base path for all 
    275145         
    276146        KillDataFolder/Z $base 
     
    325195         
    326196        // Run Name and title 
    327         NewDataFolder/O/S $(base + ":entry1") 
    328         Make/T/N=1 $(base + ":entry1:title") = {StringByKey("LABEL",note(inten),":",";")} 
    329         CreateStrNxCansas(fileID,parentBase,"","title",$(base + ":entry1:title"),empty,empty) 
    330         Make/T/N=1 $(base + ":entry1:run") = {""} 
    331         CreateStrNxCansas(fileID,parentBase,"","run",$(base + ":entry1:run"),empty,empty) 
     197        NewDataFolder/O/S $(parentBase) 
     198        Make/T/N=1 $(parentBase + ":title") = {StringByKey("LABEL",note(inten),":",";")} 
     199        CreateStrNxCansas(fileID,nxcansasBase,"","title",$(parentBase + ":title"),empty,empty) 
     200        Make/T/N=1 $(parentBase + ":run") = {""} 
     201        CreateStrNxCansas(fileID,nxcansasBase,"","run",$(parentBase + ":run"),empty,empty) 
    332202         
    333203        // SASData 
    334         String dataParent = parentBase + "sasdata/" 
     204        String dataParent = nxcansasBase + "sasdata/" 
    335205        // Create SASdata entry 
    336         String dataBase = base + ":entry1:sasdata" 
     206        String dataBase = parentBase + ":sasdata" 
    337207        NewDataFolder/O/S $(dataBase) 
    338208        Make/O/T/N=5 $(dataBase + ":attr") = {"canSAS_class","signal","I_axes","NX_class","Q_indices", "timestamp"} 
     
    363233        // Write USANS meta data 
    364234         
    365          
    366         //tailor the output given the type of data written out... 
     235        WriteUSANSNXcanSASMetaData(fileID,"SMEARED",parentBase,nxcansasBase,dateStr) 
     236         
     237        //write confirmation of write operation to history area 
     238        Print "Averaged NXcanSAS File written: ", GetFileNameFromPathNoSemi(fullPath) 
     239        KillWaves/Z dumWave 
     240         
     241        // Close the file 
     242        if(fileID) 
     243                HDF5CloseFile /Z fileID 
     244        endif 
     245         
     246End      
     247 
     248Function WriteUSANSNXcanSASMetaData(fileID,type,parentBase,nxcansasBase,dateStr) 
     249        Variable fileID 
     250        String type,parentBase,nxcansasBase,dateStr 
     251         
     252        // tailor the output given the type of data written out... 
     253        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder 
    367254        WAVE inten_EMP=$(USANSFolder+":EMP:DetCts") 
    368255        String samStr="",empStr="",samLabelStr="",paramStr="",empLevStr="",bkgLevStr="" 
     
    374261        NVAR thick = $(USANSFolder+":Globals:MainPanel:gThick") 
    375262         
    376         samStr = "SMEARED FILES: "+StringByKey("FILE",note(inten),":",";") 
    377         empStr = "EMP FILES: "+StringByKey("FILE",note(inten_EMP),":",";")       
    378         empLevStr = "EMP LEVEL: " + num2str(empCts) 
    379         bkgLevStr = "BKG LEVEL: " + num2str(bkgCts) 
    380         paramStr = "Ds = "+num2str(thick)+" cm ; " 
    381         paramStr += "Twide = "+num2Str(TransWide)+" ; " 
    382         paramStr += "Trock = "+num2str(TransRock)        
    383         pkStr += "SAM PEAK ANGLE: "+num2str(QpkFromNote("SAM")) 
    384         pkStr += " ; EMP PEAK ANGLE: "+num2str(QpkFromNote("EMP")) 
     263        strswitch(type) 
     264                case "SAM":              
     265                        samStr = type +" FILES: "+StringByKey("FILE",note(inten),":",";") 
     266                        empStr = "Uncorrected SAM data" 
     267                        empLevStr = "Uncorrected SAM data" 
     268                        bkgLevStr = "Uncorrected SAM data" 
     269                        paramStr = "Uncorrected SAM data" 
     270                        pkStr += "SAM PEAK ANGLE: "+num2str(QpkFromNote("SAM")) 
     271                        break                                            
     272                case "EMP":      
     273                        samStr = type +" FILES: "+StringByKey("FILE",note(inten),":",";") 
     274                        empStr = "Uncorrected EMP data" 
     275                        empLevStr = "Uncorrected EMP data" 
     276                        bkgLevStr = "Uncorrected EMP data" 
     277                        paramStr = "Uncorrected EMP data" 
     278                        pkStr += "EMP PEAK ANGLE: "+num2str(QpkFromNote("EMP")) 
     279                        break 
     280                case "SMEARED": 
     281                        samStr = "SMEARED FILES: "+StringByKey("FILE",note(inten),":",";") 
     282                        empStr = "EMP FILES: "+StringByKey("FILE",note(inten_EMP),":",";")       
     283                        empLevStr = "EMP LEVEL: " + num2str(empCts) 
     284                        bkgLevStr = "BKG LEVEL: " + num2str(bkgCts) 
     285                        paramStr = "Ds = "+num2str(thick)+" cm ; " 
     286                        paramStr += "Twide = "+num2Str(TransWide)+" ; " 
     287                        paramStr += "Trock = "+num2str(TransRock)        
     288                        pkStr += "SAM PEAK ANGLE: "+num2str(QpkFromNote("SAM")) 
     289                        pkStr += " ; EMP PEAK ANGLE: "+num2str(QpkFromNote("EMP")) 
     290                default:                //"COR" is the default   
     291                        samStr = type +" FILES: "+StringByKey("FILE",note(inten),":",";") 
     292                        empStr = "EMP FILES: "+StringByKey("FILE",note(inten_EMP),":",";")       
     293                        empLevStr = "EMP LEVEL: " + num2str(empCts) 
     294                        bkgLevStr = "BKG LEVEL: " + num2str(bkgCts) 
     295                        paramStr = "Ds = "+num2str(thick)+" cm ; " 
     296                        paramStr += "Twide = "+num2Str(TransWide)+" ; " 
     297                        paramStr += "Trock = "+num2str(TransRock)        
     298                        pkStr += "SAM PEAK ANGLE: "+num2str(QpkFromNote("SAM")) 
     299                        pkStr += " ; EMP PEAK ANGLE: "+num2str(QpkFromNote("EMP"))                               
     300        endswitch 
    385301 
    386302        processNote = samStr+"\n"+dateStr+"\n"+samLabelStr+"\n"+empStr+"\n"+paramStr+"\n"+pkStr+"\n" 
     
    388304         
    389305        // SASinstrument 
    390         String instrParent = parentBase + "sasinstrument/" 
     306        String instrParent = nxcansasBase + "sasinstrument/" 
    391307        // Create SASinstrument entry 
    392         String instrumentBase = base + ":entry1:sasinstrument" 
     308        String instrumentBase = parentBase + ":sasinstrument" 
    393309        NewDataFolder/O/S $(instrumentBase) 
    394310        Make/O/T/N=5 $(instrumentBase + ":attr") = {"canSAS_class","NX_class"} 
     
    446362         
    447363        // SASsample 
    448         String sampleParent = parentBase + "sassample/" 
     364        String sampleParent = nxcansasBase + "sassample/" 
    449365        // Create SASsample entry 
    450         String sampleBase = base + ":entry1:sassample" 
     366        String sampleBase = parentBase + ":sassample" 
    451367        NewDataFolder/O/S $(sampleBase) 
    452368        Make/O/T/N=5 $(sampleBase + ":attr") = {"canSAS_class","NX_class"} 
     
    464380         
    465381        // SASProcess 
    466         String processParent = parentBase + "sasprocess/" 
     382        String processParent = nxcansasBase + "sasprocess/" 
    467383        // Create SASsample entry 
    468         String processBase = base + ":entry1:sasprocess" 
     384        String processBase = parentBase + ":sasprocess" 
    469385        NewDataFolder/O/S $(processBase) 
    470386        Make/O/T/N=5 $(processBase + ":attr") = {"canSAS_class","NX_class"} 
     
    477393        Make/O/T/N=1 $(sampleBase + ":note") = {processNote} 
    478394        CreateVarNxCansas(fileID,processParent,"","note",$(processBase + ":note"),units,cm) 
    479          
    480         //write confirmation of write operation to history area 
    481         Print "Averaged XML File written: ", GetFileNameFromPathNoSemi(fullPath) 
    482         KillWaves/Z dumWave 
    483          
    484         // Close the file 
    485         if(fileID) 
    486                 HDF5CloseFile /Z fileID 
    487         endif 
    488          
    489 End      
     395End 
Note: See TracChangeset for help on using the changeset viewer.