Class HDFReader

All Implemented Interfaces:
HDFSD
Direct Known Subclasses:
ACSPOHDFReader, CWHDFReader, TSHDFReader

public abstract class HDFReader extends EarthDataReader implements HDFSD
An HDF reader is an earth data reader that reads HDF format files using the HDF library class. The HDF reader class is abstract -- subclasses handle specific metadata variants.
Since:
3.1.0
Author:
Peter Hollemans
  • Field Details

    • sdid

      protected int sdid
      HDF file id.
  • Constructor Details

  • Method Details

    • getSDID

      public int getSDID()
      Description copied from interface: HDFSD
      Gets the HDF scientific dataset ID.
      Specified by:
      getSDID in interface HDFSD
    • getFilename

      public String getFilename()
      Description copied from interface: HDFSD
      Gets the HDF scientific dataset file name.
      Specified by:
      getFilename in interface HDFSD
    • getVariableNames

      public static String[] getVariableNames(int sdid) throws hdf.hdflib.HDFException, ClassNotFoundException
      Gets an array of HDF dataset variable names.
      Parameters:
      sdid - the HDF dataset to read.
      Returns:
      the array of variable names.
      Throws:
      hdf.hdflib.HDFException - if an error occurred in an HDF routine.
      ClassNotFoundException - if the HDF attribute type is unknown.
    • getGlobalInfo

      protected abstract EarthDataInfo getGlobalInfo() throws hdf.hdflib.HDFException, IOException, NoninvertibleTransformException, ClassNotFoundException
      Reads the earth data info metadata.
      Returns:
      the earth data info object.
      Throws:
      hdf.hdflib.HDFException - if an error occurred in an HDF routine.
      IOException - if an error occurred reading the file metadata.
      NoninvertibleTransformException - if the earth transform object could not be initialized.
      ClassNotFoundException - if the HDF attribute type is unknown.
    • readAllMetadata

      protected boolean readAllMetadata()
      Determines if the full set of attributes should be read into the global EarthDataInfo object and DataVariable objects. Generally this is only desirable if the HDF metadata in the data source is compatible with the intended HDF data sink. By default, this method returns false unless overridden in the child class.
      Returns:
      true if full metadata should be read, or false if not.
    • getClass

      public static Class getClass(int type) throws ClassNotFoundException
      Gets the Java primitive class associated with an HDF type.
      Parameters:
      type - the HDF data type.
      Returns:
      the Java primitive class.
      Throws:
      ClassNotFoundException - if a class cannot be found that matches the HDF type.
    • getUnsigned

      public static boolean getUnsigned(int type)
      Determines if the HDF datatype is unsigned.
      Parameters:
      type - the HDF type.
      Returns:
      true if the type is unsigned, false otherwise.
    • getAttribute

      public static Object getAttribute(int sdid, String name) throws hdf.hdflib.HDFException, ClassNotFoundException
      Gets an HDF attribute value.
      Parameters:
      sdid - the HDF scientific dataset ID.
      name - the attribute name.
      Returns:
      the attribute value. If the attribute is a character string, a Java String is returned. If the attribute has one value only, a Java object will be returned wrapping the primitive type. If the attribute has more than one value, a Java primitive array is returned.
      Throws:
      hdf.hdflib.HDFException - if an error occurred in an HDF routine.
      ClassNotFoundException - if the HDF attribute type is unknown.
    • getAttributeAsArray

      public static Object getAttributeAsArray(int sdid, String name) throws hdf.hdflib.HDFException, ClassNotFoundException
      Gets an HDF attribute value.
      Parameters:
      sdid - the HDF scientific dataset ID.
      name - the attribute name.
      Returns:
      the attribute data as an array of Java primitives.
      Throws:
      hdf.hdflib.HDFException - if an error occurred in an HDF routine.
      ClassNotFoundException - if the HDF attribute type is unknown.
    • getAttributeAsArray

      public static Object getAttributeAsArray(int sdid, int index) throws hdf.hdflib.HDFException, ClassNotFoundException
      Gets an HDF attribute value.
      Parameters:
      sdid - the HDF scientific dataset ID.
      index - the attribute index.
      Returns:
      the attribute data as an array of Java primitives.
      Throws:
      hdf.hdflib.HDFException - if an error occurred in an HDF routine.
      ClassNotFoundException - if the HDF attribute type is unknown.
    • getAttribute

      public static Object getAttribute(int sdid, int index) throws hdf.hdflib.HDFException, ClassNotFoundException
      Gets an HDF attribute value.
      Parameters:
      sdid - the HDF scientific dataset ID.
      index - the attribute index.
      Returns:
      the attribute value. If the attribute is a character string, a Java String is returned. If the attribute has one value only, a Java object will be returned wrapping the primitive type. If the attribute has more than one value, a Java primitive array is returned.
      Throws:
      hdf.hdflib.HDFException - if an error occurred in an HDF routine.
      ClassNotFoundException - if the HDF attribute type is unknown.
    • getAttributes

      public static void getAttributes(int sdid, List attList, Map attMap) throws hdf.hdflib.HDFException, ClassNotFoundException
      Gets a number of attributes specified by a list of name and stores them in a map.
      Parameters:
      sdid - the HDF scientific dataset or variable ID for reading.
      attList - the list of attribute names to store.
      attMap - the attribute map for storing attribute values (modified). If an attribute value cannot be found for the attribute name, no attribute value is stored.
      Throws:
      hdf.hdflib.HDFException - if an error occurred in an HDF routine.
      ClassNotFoundException - if the HDF attribute type is unknown.
    • getAttributes

      public static void getAttributes(int sdid, Map map, boolean global) throws hdf.hdflib.HDFException, ClassNotFoundException
      Gets all attributes and stores them in a map.
      Parameters:
      sdid - the HDF scientific dataset or variable ID for reading.
      map - the attribute map.
      global - set to true if the HDF attributes are global. If false, it is assumed that the attributes belong to an HDF variable.
      Throws:
      hdf.hdflib.HDFException - if an error occurred in an HDF routine.
      ClassNotFoundException - if the HDF attribute type is unknown.
    • getPreviewImpl

      protected DataVariable getPreviewImpl(int index) throws IOException
      Description copied from class: EarthDataReader
      Implementation for the subclass.
      Specified by:
      getPreviewImpl in class EarthDataReader
      Throws:
      IOException
      See Also:
    • getChunkProducer

      public ChunkProducer getChunkProducer(String name) throws IOException
      Description copied from class: EarthDataReader
      Creates a chunk producer for the specified variable.
      Overrides:
      getChunkProducer in class EarthDataReader
      Parameters:
      name - the variable name.
      Returns:
      a chunk producer for the specified variable.
      Throws:
      IOException
    • getVariable

      public DataVariable getVariable(int index) throws IOException
      Description copied from class: EarthDataReader
      Creates a data variable object. The full data is read into the object.
      Specified by:
      getVariable in class EarthDataReader
      Parameters:
      index - the index of the variable to get. Indexing starts at 0.
      Returns:
      a data variable object with full data value array.
      Throws:
      IOException - if the data source had I/O errors.
      See Also:
    • getChunkLengths

      public static int[] getChunkLengths(int sdsid) throws hdf.hdflib.HDFException
      Gets the chunk lengths for a chunked SDS HDF variable.
      Parameters:
      sdsid - the HDF SDS variable ID.
      Returns:
      the chunk lengths, one for each dimension or null if the variable is not chunked.
      Throws:
      hdf.hdflib.HDFException - if an HDF error occurred.
    • close

      public void close() throws IOException
      Description copied from class: EarthDataReader
      Closes the reader and frees any resources.
      Specified by:
      close in class EarthDataReader
      Throws:
      IOException - if the data source had I/O errors.
    • getVariableDimensions

      public static int[] getVariableDimensions(int sdid, String varName) throws hdf.hdflib.HDFException
      Throws:
      hdf.hdflib.HDFException