Changeset 1172


Ignore:
Timestamp:
17/01/09 00:55:20 (3 years ago)
Author:
Paul Kienzle
Message:

Improve handling of CDF0.0 and other HDF4 problems. Refs #149.

Location:
trunk/bindings/python
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/bindings/python/nxs/napi.py

    r1171 r1172  
    1 # This program is public domain 
    2  
     1# This program is public domain  
    32# Author: Paul Kienzle 
    43 
     
    107106  nxs.MAXNAMELEN  - names must be shorter than this 
    108107  nxs.MAXPATHLEN  - total path length must be shorter than this 
    109  
     108  nxs.H4SKIP - class names that may appear in HDF4 files but can be ignored 
    110109 
    111110Caveats 
     
    123122.. _NAPI:  http://www.nexusformat.org/Application_Program_Interface 
    124123""" 
    125 __all__ = ['UNLIMITED', 'MAXRANK', 'MAXNAMELEN','MAXPATHLEN', 
     124__all__ = ['UNLIMITED', 'MAXRANK', 'MAXNAMELEN','MAXPATHLEN','H4SKIP', 
    126125           'NeXus','NeXusError','open'] 
    127126 
     
    156155MAXNAMELEN=64 
    157156MAXPATHLEN=1024 # inferred from code 
     157 
     158# bogus groups; these groups are ignored in HDFView from NCSA. 
     159H4SKIP = ['CDF0.0','_HDF_CHK_TBL_','Attr0.0', 
     160          'RIG0.0','RI0.0', 'RIATTR0.0N','RIATTR0.0C'] 
    158161 
    159162# HDF data types from numpy types 
     
    602605        since getinfo returns shape and storage, both of which are required 
    603606        to read the data. 
     607 
     608        Note that HDF4 files can have entries in the file with classes 
     609        that don't need to be processed.  If the file follows the standard 
     610        NeXus DTDs then skip any entry for which nxclass.startswith('NX')  
     611        is False.  For non-conforming files, skip those entries with  
     612        nxclass in nxs.H4SKIP. 
    604613        """ 
    605614        name = ctypes.create_string_buffer(MAXNAMELEN) 
     
    630639        This does not correspond to an existing NeXus API function, 
    631640        but instead combines the work of initgroupdir/getnextentry 
    632         and open/close on data and group. 
     641        and open/close on data and group.  Entries in nxs.H4SKIP are 
     642        ignored. 
    633643        """ 
    634644        # To preserve the semantics we must read in the whole list 
     
    642652        L = [] 
    643653        for i in range(n): 
    644             L.append(self.getnextentry()) 
     654            name,nxclass = self.getnextentry() 
     655            if nxclass not in H4SKIP: 
     656                L.append((name,nxclass)) 
    645657        for name,nxclass in L: 
    646658            self.openpath(path)  # Reset the file cursor 
  • trunk/bindings/python/nxstest.py

    r1171 r1172  
    4545        print "%(prefix)s@%(attr)s: %(value)s" % locals() 
    4646    for name,nxclass in file.entries(): 
    47         if nxclass.startswith("CDF"): continue # Root has an extra CDF class 
    4847        if nxclass == "SDS": 
    4948            shape,dtype = file.getinfo() 
Note: See TracChangeset for help on using the changeset viewer.