Package noaa.coastwatch.io
Class NCCachedGrid
java.lang.Object
noaa.coastwatch.util.MetadataContainer
noaa.coastwatch.util.DataVariable
noaa.coastwatch.util.Grid
noaa.coastwatch.io.CachedGrid
noaa.coastwatch.io.NCCachedGrid
- All Implemented Interfaces:
Cloneable
,ValueSource
The
NCCachedGrid
class is a cached grid that understands how to
read variable data from NetCDF files.- Since:
- 3.3.0
- Author:
- Peter Hollemans
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Default cache size in bytes.static final int
Default tile size in bytes.Fields inherited from class noaa.coastwatch.io.CachedGrid
accessMode, DEFAULT_MAX_TILES, DEFAULT_TILE_DIMS, READ_ONLY, READ_WRITE, tiling
Fields inherited from class noaa.coastwatch.util.DataVariable
data, dims, isUnsigned, lookup, unsignedType
-
Constructor Summary
ConstructorDescriptionNCCachedGrid
(Grid grid, NCReader reader) Constructs a new read-only NetCDF cached grid with the specified properties.NCCachedGrid
(Grid grid, NCReader reader, int[] start) Constructs a new read-only NetCDF cached grid with the specified properties.NCCachedGrid
(Grid grid, NCReader reader, String ncVarName, int[] start) Constructs a new read-only NetCDF cached grid with the specified properties. -
Method Summary
Modifier and TypeMethodDescriptionGets the data class.Gets the cache data stream as an object.static void
TESTING: Traverses an HDF file's structure and prints out dataset information.protected TilingScheme.Tile
Reads the specified tile.void
setTileDims
(int[] dims) Creates a new cache where each tile has the specified dimensions.protected void
writeTile
(TilingScheme.Tile tile) Writes the specified tile.Methods inherited from class noaa.coastwatch.io.CachedGrid
clearCache, flush, getCoveringPositions, getData, getData, getMaxTiles, getTileDims, getTileSize, getTilingScheme, getValue, getValue, resetCache, setCacheSize, setData, setData, setMaxTiles, setOptimizedCacheSize, setTileSize, setValue, setValue
Methods inherited from class noaa.coastwatch.util.Grid
arraycopy, checkSubset, getNavigation, getSubset, getValue, interpolate, navigate, setNavigation, setValue
Methods inherited from class noaa.coastwatch.util.DataVariable
convertUnits, dispose, format, format, format, getClassBits, getDecimals, getDimensions, getFormat, getLongName, getMissing, getName, getOptimalStride, getRank, getScaling, getStatistics, getStatistics, getStatistics, getStatistics, getUnits, getUnsigned, getValue, getValues, setAccessHint, setFormat, setLongName, setLookup, setMissing, setName, setUnits, setUnsigned, setValue, toString
Methods inherited from class noaa.coastwatch.util.MetadataContainer
clone, getMetadataMap
-
Field Details
-
DEFAULT_TILE_SIZE
public static final int DEFAULT_TILE_SIZEDefault tile size in bytes.- See Also:
-
DEFAULT_CACHE_SIZE
public static final int DEFAULT_CACHE_SIZEDefault cache size in bytes.- See Also:
-
-
Constructor Details
-
NCCachedGrid
Constructs a new read-only NetCDF cached grid with the specified properties. Unchunked NetCDF variables will be given the default tile size, otherwise the tile size is determined from the file.- Parameters:
grid
- the grid to use for attributes. In this constructor, the grid name is not used as the NetCDF variable name.reader
- the NetCDF reader data source.ncVarName
- the NetCDF variable name to read data from.start
- the starting coordinates to read data from. This array should have the same rank as the NetCDF variable, and have values filled in for all dimensions _except_ row and column, which should have -1 as the value. The row and column dimensions are assumed to be adjacent to each other and row to be the first dimension, and then column to be the second dimension. For example if the dimensions are [time, level, row, column], then the start array could be [0, 0, -1, -1] to select the first time and level index.- Throws:
IOException
- if a problem occurred accessing the NetCDF file.- See Also:
-
NCCachedGrid
Constructs a new read-only NetCDF cached grid with the specified properties. Unchunked NetCDF variables will be given the default tile size, otherwise the tile size is determined from the file.- Parameters:
grid
- the grid to use for attributes.reader
- the NetCDF reader data source.start
- the starting coordinates to read data from. This array should have the same rank as the NetCDF variable, and have values filled in for all dimensions _except_ row and column, which should have -1 as the value. The row and column dimensions are assumed to be adjacent to each other and row to be the first dimension, and then column to be the second dimension. For example if the dimensions are [time, level, row, column], then the start array could be [0, 0, -1, -1] to select the first time and level index.- Throws:
IOException
- if a problem occurred accessing the NetCDF file.
-
NCCachedGrid
Constructs a new read-only NetCDF cached grid with the specified properties. Unchunked NetCDF variables will be given the default tile size, otherwise the tile size is determined from the file. The NetCDF variable named by the grid must have rank 2.- Parameters:
grid
- the grid to use for attributes.reader
- the NetCDF reader data source.- Throws:
IOException
- if a problem occurred accessing the NetCDF file.
-
-
Method Details
-
getDataClass
Gets the data class. This method overrides the parent because the data class for an NC cached grid is not available from the data array when needed in some cases.- Overrides:
getDataClass
in classDataVariable
- Returns:
- the Java class of the data array.
-
getDataStream
Description copied from class:CachedGrid
Gets the cache data stream as an object. This is useful for classes that read and write cached grids.- Specified by:
getDataStream
in classCachedGrid
- Returns:
- the data stream used for reading and writing data.
-
setTileDims
public void setTileDims(int[] dims) Creates a new cache where each tile has the specified dimensions. Only unchunked NetCDF variables may have the tile dimensions set. For chunked variables, the method has no effect.- Overrides:
setTileDims
in classCachedGrid
- Parameters:
dims
- the tile dimensions as [rows, columns].
-
readTile
Description copied from class:CachedGrid
Reads the specified tile.- Specified by:
readTile
in classCachedGrid
- Parameters:
pos
- the tile position to read.- Returns:
- the tile at the specified position.
- Throws:
IOException
- if an error occurred reading the tile data.
-
writeTile
Description copied from class:CachedGrid
Writes the specified tile. The implementation of this method must set the tile to be not dirty upon successfully writing it, or throw an error.- Specified by:
writeTile
in classCachedGrid
- Parameters:
tile
- the tile to write.- Throws:
IOException
- if an error occurred writing the tile data.
-
main
TESTING: Traverses an HDF file's structure and prints out dataset information.- Throws:
Exception
-