Ignore:
Timestamp:
Jun 13, 2019 4:25:22 PM (4 years ago)
Author:
krzywon
Message:

Load in NXcanSAS SANS files, meta data and all.

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  
    2424        // Define local function variables 
    2525        Variable fileID 
    26         String destStr="" 
    27         String parentBase = "/sasentry/" // HDF5 base path for all  
     26        String destStr="", parentBase, nxcansasBase 
    2827        String/G base = "root:NXcanSAS_file" 
    29          
    30         KillDataFolder/Z $base 
    3128         
    3229        // Define local waves 
     
    4340        Endif 
    4441        if(!fileID) 
    45                 Print "Unable to create file at " + fullpath + "." 
     42                abort "Unable to create file at " + fullpath + "." 
    4643        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 
    4748                destStr = "root:Packages:NIST:"+type 
    4849                //*****these waves MUST EXIST, or IGOR Pro will crash, with a type 2 error**** 
     
    6263         
    6364        // 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"} 
    6869         
    6970        // 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) 
    7576         
    7677        // SASData 
    77         String dataParent = parentBase + "sasdata/" 
     78        String dataParent = nxcansasBase + "sasdata/" 
    7879        // Create SASdata entry 
    79         String dataBase = base + ":entry1:sasdata" 
     80        String dataBase = parentBase + ":sasdata" 
    8081        NewDataFolder/O/S $(dataBase) 
    8182        Make/O/T/N=5 $(dataBase + ":attr") = {"canSAS_class","signal","I_axes","NX_class","Q_indices", "timestamp"} 
     
    8990        // Create i entry 
    9091        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"} 
    9394        CreateVarNxCansas(fileID,dataParent,"sasdata","I",inten,$(dataBase + ":i:attr"),$(dataBase + ":i:attrVals")) 
    9495        // Create idev entry 
     
    99100         
    100101        // Write all meta data 
    101         WriteMetaData(fileID,base,parentBase,rw,textw) 
     102        WriteMetaData(fileID,parentBase,nxcansasBase,rw,textw) 
    102103         
    103104        // 
     
    130131        // Define local function variables 
    131132        Variable fileID 
    132         String destStr="",typeStr="" 
    133         String parentBase = "/sasentry/" // HDF5 base path for all  
     133        String destStr="",typeStr="", parentBase, nxcansasBase 
    134134        String/G base = "root:NXcanSAS_file" 
    135          
    136         KillDataFolder/Z $base 
    137135         
    138136        // Define local waves 
     
    149147        Endif 
    150148        if(!fileID) 
    151                 Print "Unable to create file at " + fullpath + "." 
     149                abort "Unable to create file at " + fullpath + "." 
    152150        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                 
    153155                destStr = "root:Packages:NIST:"+type 
    154156 
     
    160162                        typeStr = ":data" 
    161163                endif 
    162                         NVAR pixelsX = root:myGlobals:gNPixelsX 
     164                NVAR pixelsX = root:myGlobals:gNPixelsX 
    163165                NVAR pixelsY = root:myGlobals:gNPixelsY 
    164166                Wave data=$(destStr+typeStr) 
     
    260262         
    261263        // 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"} 
    266268         
    267269        // 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) 
    273275         
    274276        // SASData 
    275         String dataParent = parentBase + "sasdata/" 
     277        String dataParent = nxcansasBase + "sasdata/" 
    276278        // Create SASdata entry 
    277         String dataBase = base + ":entry1:sasdata" 
     279        String dataBase = base + parentBase + ":sasdata" 
    278280        NewDataFolder/O/S $(dataBase) 
    279281        Make/O/T/N=5 $(dataBase + ":attr") = {"canSAS_class","signal","I_axes","NX_class","Q_indices", "timestamp"} 
     
    282284        // Create i entry 
    283285        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"} 
    286288        CreateVarNxCansas(fileID,dataParent,"sasdata","I",data,$(dataBase + ":i:attr"),$(dataBase + ":i:attrVals")) 
    287289 
     
    293295        // Create qx and qy entry 
    294296        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"} 
    297299        CreateVarNxCansas(fileID,dataParent,"sasdata","Q",qxy_vals,$(dataBase + ":q:attr"),$(dataBase + ":q:attrVals")) 
    298300         
     
    305307         
    306308        // Write all meta data 
    307         WriteMetaData(fileID,base,parentBase,rw,textw) 
     309        WriteMetaData(fileID,parentBase,nxcansasBase,rw,textw) 
    308310         
    309311        // Close the file 
     
    330332         
    331333        // 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"} 
    339341         
    340342        // SASinstrument 
    341343        String instrParent = parentBase + "sasinstrument/" 
    342344        // Create SASinstrument entry 
    343         String instrumentBase = base + ":entry1:sasinstrument" 
     345        String instrumentBase = base + ":sasinstrument" 
    344346        NewDataFolder/O/S $(instrumentBase) 
    345347        Make/O/T/N=5 $(instrumentBase + ":attr") = {"canSAS_class","NX_class"} 
     
    430432        String sampleParent = parentBase + "sassample/" 
    431433        // Create SASsample entry 
    432         String sampleBase = base + ":entry1:sassample" 
     434        String sampleBase = base + ":sassample" 
    433435        NewDataFolder/O/S $(sampleBase) 
    434436        Make/O/T/N=5 $(sampleBase + ":attr") = {"canSAS_class","NX_class"} 
     
    479481End 
    480482 
    481  
    482483// Open\ file with a known path 
    483484Function NxCansas_OpenFile(fullpath) 
     
    486487        Variable fileID 
    487488        fileName = ParseFilePath(3,fullpath,":",0,0) 
    488         Print fileName 
    489489        Make/T/O/N=1 $("root:file_name") = fileName 
    490490        fullpath = ReplaceString(":\\", fullpath, ":") 
     
    511511Function NxCansas_InitializeFile(fileID) 
    512512        Variable fileID 
    513         String parent 
     513        String parent,nxParent 
    514514        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")) 
    523527End 
    524528 
     
    685689         
    686690        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" 
    693706         
    694707        //go back to the root folder and clean up before leaving 
    695708        NewDataFolder/O/S $loadDir 
     709        Make/O/N=52 $(loadDir + ":realsRead") 
     710        Make/O/T/N=11 $(loadDir + ":textRead") 
    696711         
    697712        if(fileID) 
    698713                HDF5ListGroup /F/R/Type=1/Z fileID,"/" 
    699714                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                // 
    701719         
    702720                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) 
    707742                 
    708743                //plot if desired 
     
    710745                        Print GetDataFolder(1) 
    711746                         
    712                         String w0 = loadDir + ":" + Q_dataStore 
    713                         String w1 = loadDir + ":" + I_dataStore 
    714                         String w2 = loadDir + ":" + dI_dataStore 
     747                        String w0 = Q_dataStore 
     748                        String w1 = I_dataStore 
     749                        String w2 = dI_dataStore 
    715750                         
    716751                        // assign colors randomly 
     
    731766                                else 
    732767                                //new graph 
    733                                         SetDataFolder $loadDir  //sometimes I end up back in root: here, and I can't figure out why! 
    734768                                        Display $w1 vs $w0 
    735769                                        ModifyGraph log=1,mode($w1)=3,marker($w1)=19,msize($w1)=2,rgb($w1)=(rr,gg,bb),tickUnit=1 
     
    760794                HDF5CloseFile /Z fileID 
    761795        endif 
    762          
    763         // KillDataFolder /Z $loadDir 
    764796 
    765797end 
     798 
     799Function 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         
     878End 
    766879 
    767880// 
     
    777890        String filestr 
    778891         
    779         Variable fileID = 0 
     892        Variable fileID=0,groupID=0 
    780893        Int isHDF5File = 0 
    781894         
    782895        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 
    783902         
    784903        if (fileID != 0) 
    785                 isHDF5File = 1 
    786904                // Close the file 
    787905                HDF5CloseFile /Z fileID 
  • sans/Dev/branches/nxcansas_writer/NCNR_User_Procedures/Common/Packages/PlotManager/PlotUtilsMacro_v40.ipf

    r1167 r1170  
    14271427        val = NumVarOrDefault("root:Packages:NIST:gDoAdjustRAW_Atten",0) 
    14281428        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 
    14291433         
    14301434        /// items for SANS Analysis 
Note: See TracChangeset for help on using the changeset viewer.