Ignore:
Timestamp:
Jun 17, 2019 4:52:45 PM (3 years ago)
Author:
krzywon
Message:

Fixed most of the issues saving USANS data in NXcanSAS format.

File:
1 edited

Legend:

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

    r1172 r1173  
    1010 
    1111//************************ 
    12 // Vers 1.00 20190603 
     12// Vers 1.03 20190617 
    1313// 
    1414//************************ 
     
    2424         
    2525        Variable fileID 
    26         String destStr="" 
    27         destStr = USANSFolder+":"+type 
     26        String destStr=USANSFolder+":"+type 
    2827        String dateStr=date()+" "+time() 
    2928 
     
    3534        sPrintf nxcansasBase,"/sasentry%d/",sasentry // HDF5 base path for all 
    3635         
    37         KillDataFolder/Z $base 
     36        NewDataFolder/O/S $(base) 
    3837         
    3938        // Define common attribute waves 
    40         Make/T/N=1 empty = {""} 
    41         Make/T/N=1 units = {"units"} 
    42         Make/T/N=1 m = {"m"} 
    43         Make/T/N=1 mm = {"mm"} 
    44         Make/T/N=1 cm = {"cm"} 
    45         Make/T/N=1 angstrom = {"A"} 
    46         Make/T/N=1 inv_cm = {"1/cm"} 
    47         Make/T/N=1 inv_angstrom = {"1/A"} 
     39        Make/O/T/N=1 empty = {""} 
     40        Make/O/T/N=1 units = {"units"} 
     41        Make/O/T/N=1 m = {"m"} 
     42        Make/O/T/N=1 mm = {"mm"} 
     43        Make/O/T/N=1 cm = {"cm"} 
     44        Make/O/T/N=1 angstrom = {"A"} 
     45        Make/O/T/N=1 inv_cm = {"1/cm"} 
     46        Make/O/T/N=1 inv_angstrom = {"1/A"} 
    4847         
    4948        Variable refNum,integer,realval 
    50          
    51         //*****these waves MUST EXIST, or IGOR Pro will crash, with a type 2 error**** 
    52         WAVE qvals =$(destStr + ":Qvals") 
    53         WAVE inten=$(destStr + ":DetCts") 
    54         WAVE sig=$(destStr + ":ErrDetCts") 
    5549                 
    5650        if(dialog || stringmatch(fullpath, "")) 
     
    6054        Endif 
    6155         
     56        if(!fileID) 
     57                abort "Unable to create file at " + fullpath + "." 
     58        else 
     59                //*****these waves MUST EXIST, or IGOR Pro will crash, with a type 2 error**** 
     60                WAVE qvals = $(destStr + ":Qvals") 
     61                WAVE inten = $(destStr + ":DetCts") 
     62                WAVE sig = $(destStr + ":ErrDetCts") 
     63        endif 
     64         
    6265        //check each wave 
    6366        If(!(WaveExists(qvals))) 
     
    7174        Endif 
    7275         
     76        //write out partial set? 
     77        Duplicate/O qvals,tq,ti,te 
     78        ti=inten 
     79        te=sig 
     80        if( (lo!=hi) && (lo<hi)) 
     81                redimension/N=(hi-lo+1) tq,ti,te,dumWave                //lo to hi, inclusive 
     82                tq=qvals[p+lo] 
     83                ti=inten[p+lo] 
     84                te=sig[p+lo] 
     85        endif 
     86         
    7387        //Use the evil extra column for the resolution "information". Should probably switch to using slit_length in collimation. 
    7488        Duplicate/O qvals,dumWave 
    7589        dumWave = dQv 
    7690         
    77         Make/N= (numpnts(dumWave)) dQw = 0 
     91        Make/O/N= (numpnts(dumWave)) dQw = 0 
    7892         
    7993        // Run Name and title 
    8094        NewDataFolder/O/S $(parentBase) 
    81         Make/T/N=1 $(parentBase + ":title") = {StringByKey("LABEL",note(inten),":",";")} 
     95         
     96        // 
     97        // FIXME: Get useful title - For now, sending empty string 
     98        // 
     99         
     100        Make/T/N=1 $(parentBase + ":title") = {""} //StringByKey("LABEL",note(inten),":",";")} 
    82101        CreateStrNxCansas(fileID,nxcansasBase,"","title",$(parentBase + ":title"),empty,empty) 
     102         
     103        // 
     104        // TODO: Any way to programatically get the old filename? 
     105        // 
     106         
    83107        Make/T/N=1 $(parentBase + ":run") = {""} 
    84108        CreateStrNxCansas(fileID,nxcansasBase,"","run",$(parentBase + ":run"),empty,empty) 
     
    107131        CreateVarNxCansas(fileID,dataParent,"sasdata","dQl",dumWave,units,inv_angstrom) 
    108132        CreateVarNxCansas(fileID,dataParent,"sasdata","dQw",dQw,units,inv_angstrom) 
    109         CreateVarNxCansas(fileID,dataParent,"sasdata","Qmean",res2,units,inv_angstrom) 
    110          
    111         ////////////////////////////////////////////////////////////////////////////////////////////// 
     133         
    112134        // Write the meta data to the file 
    113135        WriteUSANSNXcanSASMetaData(fileID,type,parentBase,nxcansasBase,dateStr) 
     
    116138        Print "Averaged NXcanSAS File written: ", GetFileNameFromPathNoSemi(fullPath) 
    117139        KillWaves/Z dumWave 
     140        KillDataFolder/Z $base 
    118141         
    119142        // Close the file 
     
    134157        Variable fileID 
    135158        String destStr="" 
    136         destStr = USANSFolder+":Smeared" 
     159        destStr = USANSFolder+":DSM" 
    137160        String dateStr=date()+" "+time() 
    138161 
     
    225248        CreateVarNxCansas(fileID,dataParent,"sasdata","dQw",res1,units,inv_angstrom) 
    226249        CreateVarNxCansas(fileID,dataParent,"sasdata","Qmean",res2,units,inv_angstrom) 
    227          
    228         // 
    229         ////////////////////////////////////////////////////////////////////////////////////////////// 
    230          
    231         ////////////////////////////////////////////////////////////////////////////////////////////// 
    232         // 
     250 
    233251        // Write USANS meta data 
    234          
    235252        WriteUSANSNXcanSASMetaData(fileID,"SMEARED",parentBase,nxcansasBase,dateStr) 
    236253         
     
    238255        Print "Averaged NXcanSAS File written: ", GetFileNameFromPathNoSemi(fullPath) 
    239256        KillWaves/Z dumWave 
     257        KillDataFolder/Z $base 
    240258         
    241259        // Close the file 
     
    303321        processNote += empLevStr + " ; "+bkglevStr+"\n" 
    304322         
     323        Make/O/T/N=1 empty = {""} 
     324        Make/O/T/N=1 units = {"units"} 
     325        Make/O/T/N=1 m = {"m"} 
     326        Make/O/T/N=1 mm = {"mm"} 
     327        Make/O/T/N=1 cm = {"cm"} 
     328        Make/O/T/N=1 angstrom = {"A"} 
     329        Make/O/T/N=1 inv_cm = {"1/cm"} 
     330        Make/O/T/N=1 inv_angstrom = {"1/A"} 
     331         
    305332        // SASinstrument 
    306333        String instrParent = nxcansasBase + "sasinstrument/" 
     
    320347        Make/O/T/N=5 $(apertureBase + ":attrVals") = {"SASaperture","NXaperture"} 
    321348        CreateStrNxCansas(fileID,apertureParent,"","",empty,$(apertureBase + ":attr"),$(apertureBase + ":attrVals")) 
    322          
    323349        // Create SASaperture shape entry 
    324350        Make/O/T/N=1 $(apertureBase + ":shape") = {"slit"}  
     
    336362        String detectorBase = instrumentBase + ":sasdetector" 
    337363        NewDataFolder/O/S $(detectorBase) 
    338         Make/O/T/N=5 $(detectorBase + ":attr") = {"canSAS_class","NX_class"} 
    339         Make/O/T/N=5 $(detectorBase + ":attrVals") = {"SASdetector","NXdetector"} 
     364        Make/O/T/N=2 $(detectorBase + ":attr") = {"canSAS_class","NX_class"} 
     365        Make/O/T/N=2 $(detectorBase + ":attrVals") = {"SASdetector","NXdetector"} 
    340366        CreateStrNxCansas(fileID,detectorParent,"","",empty,$(detectorBase + ":attr"),$(detectorBase + ":attrVals")) 
    341367        // Create SASdetector name entry 
    342368        Make/O/T/N=1 $(detectorBase + ":name") = {"BT5 DETECTOR ARRAY"} 
    343369        CreateStrNxCansas(fileID,detectorParent,"","name",$(detectorBase + ":name"),empty,empty) 
    344          
     370 
    345371        // SASsource 
    346372        String sourceParent = instrParent + "sassource/" 
     
    348374        String sourceBase = instrumentBase + ":sassource" 
    349375        NewDataFolder/O/S $(sourceBase) 
    350         Make/O/T/N=5 $(sourceBase + ":attr") = {"canSAS_class","NX_class"} 
    351         Make/O/T/N=5 $(sourceBase + ":attrVals") = {"SASsource","NXsource"} 
     376        Make/O/T/N=2 $(sourceBase + ":attr") = {"canSAS_class","NX_class"} 
     377        Make/O/T/N=2 $(sourceBase + ":attrVals") = {"SASsource","NXsource"} 
    352378        CreateStrNxCansas(fileID,sourceParent,"","",empty,$(sourceBase + ":attr"),$(sourceBase + ":attrVals")) 
    353379        // Create SASsource radiation entry 
     
    370396        CreateStrNxCansas(fileID,sampleParent,"","",empty,$(sampleBase + ":attr"),$(sampleBase + ":attrVals")) 
    371397        // Create SASsample name entry 
     398         
     399        // 
     400        // FIXME: reinstate sample name once format is correct (same as title) 
     401        // 
     402         
    372403        Make/O/T/N=1 $(sampleBase + ":name") = {StringByKey("LABEL",note(inten),":",";")} 
    373404        CreateStrNxCansas(fileID,sampleParent,"","name",$(sampleBase + ":name"),empty,empty) 
     
    384415        String processBase = parentBase + ":sasprocess" 
    385416        NewDataFolder/O/S $(processBase) 
    386         Make/O/T/N=5 $(processBase + ":attr") = {"canSAS_class","NX_class"} 
    387         Make/O/T/N=5 $(processBase + ":attrVals") = {"SASprocess","NXprocess"} 
     417        Make/O/T/N=2 $(processBase + ":attr") = {"canSAS_class","NX_class"} 
     418        Make/O/T/N=2 $(processBase + ":attrVals") = {"SASprocess","NXprocess"} 
    388419        CreateStrNxCansas(fileID,processParent,"","",empty,$(processBase + ":attr"),$(processBase + ":attrVals")) 
    389420        // Create SASsample name entry 
     
    391422        CreateStrNxCansas(fileID,processParent,"","name",$(processBase + ":name"),empty,empty) 
    392423        // Create SASsample thickness entry 
    393         Make/O/T/N=1 $(sampleBase + ":note") = {processNote} 
    394         CreateVarNxCansas(fileID,processParent,"","note",$(processBase + ":note"),units,cm) 
     424        Make/O/T/N=1 $(processBase + ":processnote") = {processNote} 
     425        CreateStrNxCansas(fileID,processParent,"","note",$(processBase + ":processnote"),empty,empty) 
    395426End 
Note: See TracChangeset for help on using the changeset viewer.