Package noaa.coastwatch.io
Class NCReader
java.lang.Object
noaa.coastwatch.io.EarthDataReader
noaa.coastwatch.io.NCReader
- All Implemented Interfaces:
GridSubsetReader
,NCSD
- Direct Known Subclasses:
ACSPONCCFReader
,ACSPONCReader
,CommonDataModelNCReader
,CWCFNCReader
,CWNCReader
The
NCReader
class is the base class for readers that
use the Java NetCDF API to read and parse metadata. Supported file
formats include NetCDF 3/4, HDF5, and OPeNDAP network connections.- Since:
- 3.2.0
- Author:
- Peter Hollemans
-
Field Summary
Modifier and TypeFieldDescriptionprotected ucar.nc2.dataset.NetcdfDataset
The NetCDF dataset for accessing data.Fields inherited from class noaa.coastwatch.io.EarthDataReader
dataProjection, info, rawMetadataMap, variables
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes the reader.protected static Object
convertAttributeValue
(ucar.nc2.Attribute att, boolean asArray) Converts an attribute into a Java string, primitive array, or wrapped primitive.protected abstract DataVariable
getActualVariable
(int index) Gets the actual variable with data.getAttribute
(String name) Gets a NetCDF global file attribute from this reader and converts it to a Java string, primitive array, or wrapped primitive.static Object
getAttribute
(ucar.nc2.NetcdfFile file, String name) Gets a NetCDF global file attribute and converts it to a Java string, primitive array, or wrapped primitive.static Object
getAttribute
(ucar.nc2.Variable var, String name) Gets a NetCDF variable attribute and converts it to a Java string, primitive array, or wrapped primitive.getAttributeAsArray
(String name) Gets a NetCDF global file attribute from this reader and converts it to a primitive array.static Object
getAttributeAsArray
(ucar.nc2.NetcdfFile file, String name) Gets a NetCDF global file attribute and converts it to a primitive array.static Object
getAttributeAsArray
(ucar.nc2.Variable var, String name) Gets a NetCDF variable attribute and converts it to a primitive array.List<ucar.nc2.dataset.CoordinateSystem>
Gets the NetCDF CDM style coordinate systems accessed by this reader.ucar.nc2.dataset.NetcdfDataset
Gets the NetCDF scientific dataset.Gets the NetCDF scientific dataset file name.getGridSubset
(String varName, int[] start, int[] stride, int[] length) Reads a subset of a data grid.getRawMetadata
(int index) Gets the detailed raw metadata for a variable.protected ucar.nc2.NetcdfFile
Gets the NetCDF file referenced in this reader.getVariable
(int index) Creates a data variable object.getVariablesForSystem
(ucar.nc2.dataset.CoordinateSystem system) Gets the variable names for the specified NetCDF CDM style coordinate systems accessed by this reader.protected void
Performs reader initialization after the dataset has been opened.boolean
Returns true if this reader is network-connected.Methods inherited from class noaa.coastwatch.io.EarthDataReader
canUpdateNavigation, containsVariable, finalize, getAllGrids, getAllVariables, getChunkProducer, getDataFormat, getIndex, getInfo, getName, getPreview, getPreview, getPreviewImpl, getRawMetadata, getSceneTime, getSource, getStatistics, getStatisticsVariables, getVariable, getVariables, putStatistics, setDataProjection, setUnitsMap, updateNavigation
-
Field Details
-
dataset
protected ucar.nc2.dataset.NetcdfDataset datasetThe NetCDF dataset for accessing data.
-
-
Constructor Details
-
NCReader
Creates a new reader using the dataset at the specified location.- Parameters:
name
- the file or network location.- Throws:
IOException
- if an error occurred accessing the dataset.
-
-
Method Details
-
getDataset
public ucar.nc2.dataset.NetcdfDataset getDataset()Description copied from interface:NCSD
Gets the NetCDF scientific dataset.- Specified by:
getDataset
in interfaceNCSD
-
getFilename
Description copied from interface:NCSD
Gets the NetCDF scientific dataset file name.- Specified by:
getFilename
in interfaceNCSD
-
initializeReader
Performs reader initialization after the dataset has been opened.- Throws:
IOException
- if an error occurred on initialization.
-
convertAttributeValue
Converts an attribute into a Java string, primitive array, or wrapped primitive.- Parameters:
att
- the attribute to convert.asArray
- the array flag, true to return single values as an array, false to return as a wrapped primitive.
-
getAttribute
Gets a NetCDF global file attribute from this reader and converts it to a Java string, primitive array, or wrapped primitive.- Parameters:
name
- the name of the attribute.- Returns:
- the attribute value or null if none exists.
-
getAttributeAsArray
Gets a NetCDF global file attribute from this reader and converts it to a primitive array. Strings are returned as an array of bytes, and arrays of length 1 are returned as-is (and not converted to a wrapped primitive).- Parameters:
name
- the name of the attribute.- Returns:
- the attribute value or null if none exists.
-
getAttribute
Gets a NetCDF global file attribute and converts it to a Java string, primitive array, or wrapped primitive.- Parameters:
file
- the NetCDF file to access.name
- the name of the attribute.- Returns:
- the attribute value or null if none exists.
-
getAttributeAsArray
Gets a NetCDF global file attribute and converts it to a primitive array. Strings are returned as an array of bytes, and arrays of length 1 are returned as-is (and not converted to a wrapped primitive).- Parameters:
file
- the NetCDF file to access.name
- the name of the attribute.- Returns:
- the attribute value or null if none exists.
-
getAttribute
Gets a NetCDF variable attribute and converts it to a Java string, primitive array, or wrapped primitive.- Parameters:
var
- the variable to access.name
- the name of the attribute.- Returns:
- the attribute value or null if none exists.
-
getAttributeAsArray
Gets a NetCDF variable attribute and converts it to a primitive array. Strings are returned as an array of bytes, and arrays of length 1 are returned as-is (and not converted to a wrapped primitive).- Parameters:
var
- the variable to access.name
- the name of the attribute.- Returns:
- the attribute value or null if none exists.
-
isNetwork
public boolean isNetwork()Returns true if this reader is network-connected. -
getActualVariable
Gets the actual variable with data. This method should be implemented in the child class and is only called if the variable is not already in the cache. SeegetVariable(int)
for the required behaviour.- 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:
-
close
Closes the reader.- Specified by:
close
in classEarthDataReader
- Throws:
IOException
- if the data source had I/O errors.
-
getReferencedFile
protected ucar.nc2.NetcdfFile getReferencedFile()Gets the NetCDF file referenced in this reader.- Returns:
- the NetCDF file.
- Since:
- 3.6.1
-
getGridSubset
public Grid getGridSubset(String varName, int[] start, int[] stride, int[] length) throws IOException Description copied from interface:GridSubsetReader
Reads a subset of a data grid. This is similar to theEarthDataReader.getVariable(String)
method except that it reads only grid variables and is capable of returning just a subset of the data values. In some cases, such as across a network connection, it may be more efficient to access only a subset or subsampling of data in a variable.- Specified by:
getGridSubset
in interfaceGridSubsetReader
- Parameters:
varName
- the variable name to access.start
- the 2D starting data coordinates.stride
- the 2D data stride.length
- the total number of values to read in each dimension.- Returns:
- the subset and/or subsampled grid variable.
- Throws:
IOException
- if the data source had I/O errors.
-
getCoordinateSystems
Description copied from class:EarthDataReader
Gets the NetCDF CDM style coordinate systems accessed by this reader.- Overrides:
getCoordinateSystems
in classEarthDataReader
- Returns:
- the list of coordinate systems, possibly empty.
-
getVariablesForSystem
Description copied from class:EarthDataReader
Gets the variable names for the specified NetCDF CDM style coordinate systems accessed by this reader.- Overrides:
getVariablesForSystem
in classEarthDataReader
- Returns:
- the list of variable names, possibly empty.
-
getRawMetadata
Description copied from class:EarthDataReader
Gets the detailed raw metadata for a variable.- Overrides:
getRawMetadata
in classEarthDataReader
- Parameters:
index
- the index of the variable for raw metadata.- Returns:
- the map of attribute name to attribute value.
- Throws:
IOException
- if the data source had I/O errors.- See Also:
-