Class NCCachedGrid

All Implemented Interfaces:
Cloneable, ValueSource

public class NCCachedGrid extends CachedGrid
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 Details

    • DEFAULT_TILE_SIZE

      public static final int DEFAULT_TILE_SIZE
      Default tile size in bytes.
      See Also:
    • DEFAULT_CACHE_SIZE

      public static final int DEFAULT_CACHE_SIZE
      Default cache size in bytes.
      See Also:
  • Constructor Details

    • NCCachedGrid

      public NCCachedGrid(Grid grid, NCReader reader, String ncVarName, int[] start) throws IOException
      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

      public NCCachedGrid(Grid grid, NCReader reader, int[] start) throws IOException
      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

      public NCCachedGrid(Grid grid, NCReader reader) throws IOException
      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

      public Class 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 class DataVariable
      Returns:
      the Java class of the data array.
    • getDataStream

      public Object 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 class CachedGrid
      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 class CachedGrid
      Parameters:
      dims - the tile dimensions as [rows, columns].
    • readTile

      protected TilingScheme.Tile readTile(TilingScheme.TilePosition pos) throws IOException
      Description copied from class: CachedGrid
      Reads the specified tile.
      Specified by:
      readTile in class CachedGrid
      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

      protected void writeTile(TilingScheme.Tile tile) throws IOException
      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 class CachedGrid
      Parameters:
      tile - the tile to write.
      Throws:
      IOException - if an error occurred writing the tile data.
    • main

      public static void main(String[] argv) throws Exception
      TESTING: Traverses an HDF file's structure and prints out dataset information.
      Throws:
      Exception