Package noaa.coastwatch.io
Class HDFReader
java.lang.Object
noaa.coastwatch.io.EarthDataReader
noaa.coastwatch.io.HDFReader
- All Implemented Interfaces:
HDFSD
- Direct Known Subclasses:
ACSPOHDFReader
,CWHDFReader
,TSHDFReader
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 Summary
Fields inherited from class noaa.coastwatch.io.EarthDataReader
dataProjection, info, rawMetadataMap, variables
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes the reader and frees any resources.static Object
getAttribute
(int sdid, int index) Gets an HDF attribute value.static Object
getAttribute
(int sdid, String name) Gets an HDF attribute value.static Object
getAttributeAsArray
(int sdid, int index) Gets an HDF attribute value.static Object
getAttributeAsArray
(int sdid, String name) Gets an HDF attribute value.static void
getAttributes
(int sdid, List attList, Map attMap) Gets a number of attributes specified by a list of name and stores them in a map.static void
getAttributes
(int sdid, Map map, boolean global) Gets all attributes and stores them in a map.static int[]
getChunkLengths
(int sdsid) Gets the chunk lengths for a chunked SDS HDF variable.getChunkProducer
(String name) Creates a chunk producer for the specified variable.static Class
getClass
(int type) Gets the Java primitive class associated with an HDF type.Gets the HDF scientific dataset file name.protected abstract EarthDataInfo
Reads the earth data info metadata.protected DataVariable
getPreviewImpl
(int index) Implementation for the subclass.int
getSDID()
Gets the HDF scientific dataset ID.static boolean
getUnsigned
(int type) Determines if the HDF datatype is unsigned.getVariable
(int index) Creates a data variable object.static int[]
getVariableDimensions
(int sdid, String varName) static String[]
getVariableNames
(int sdid) Gets an array of HDF dataset variable names.protected boolean
Determines if the full set of attributes should be read into the global EarthDataInfo object and DataVariable objects.Methods inherited from class noaa.coastwatch.io.EarthDataReader
canUpdateNavigation, containsVariable, finalize, findVariable, getAllGrids, getAllVariables, getCoordinateSystems, getDataFormat, getIndex, getInfo, getName, getPreview, getPreview, getRawMetadata, getRawMetadata, getSceneTime, getSource, getStatistics, getStatisticsVariables, getVariable, getVariables, getVariablesForSystem, putStatistics, setDataProjection, setUnitsMap, updateNavigation
-
Field Details
-
sdid
protected int sdidHDF file id.
-
-
Constructor Details
-
HDFReader
protected HDFReader(HDFWriter writer) throws hdf.hdflib.HDFException, IOException, NoninvertibleTransformException, ClassNotFoundException Constructs an HDF reader from the specified HDF writer.- Parameters:
writer
- the writer to use for reading.- 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.
-
HDFReader
Constructs an HDF reader from the specified file.- Parameters:
file
- the file name to read.- Throws:
IOException
- if an error opening or reading the file metadata.
-
-
Method Details
-
getSDID
public int getSDID()Description copied from interface:HDFSD
Gets the HDF scientific dataset ID. -
getFilename
Description copied from interface:HDFSD
Gets the HDF scientific dataset file name.- Specified by:
getFilename
in interfaceHDFSD
-
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, ClassNotFoundExceptionReads 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
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
Description copied from class:EarthDataReader
Implementation for the subclass.- Specified by:
getPreviewImpl
in classEarthDataReader
- Throws:
IOException
- See Also:
-
getChunkProducer
Description copied from class:EarthDataReader
Creates a chunk producer for the specified variable.- Overrides:
getChunkProducer
in classEarthDataReader
- Parameters:
name
- the variable name.- Returns:
- a chunk producer for the specified variable.
- Throws:
IOException
-
getVariable
Description copied from class:EarthDataReader
Creates a data variable object. The full data is read into the object.- Specified by:
getVariable
in classEarthDataReader
- 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
Description copied from class:EarthDataReader
Closes the reader and frees any resources.- Specified by:
close
in classEarthDataReader
- Throws:
IOException
- if the data source had I/O errors.
-
getVariableDimensions
- Throws:
hdf.hdflib.HDFException
-