ucar.nc2.dataset
Class CoordinateAxis1D

java.lang.Object
  extended by ucar.nc2.Variable
      extended by ucar.nc2.dataset.VariableDS
          extended by ucar.nc2.dataset.CoordinateAxis
              extended by ucar.nc2.dataset.CoordinateAxis1D
All Implemented Interfaces:
java.lang.Comparable, Enhancements, EnhanceScaleMissing, VariableEnhanced, VariableIF, VariableSimpleIF
Direct Known Subclasses:
CoordinateAxis1DTime

public class CoordinateAxis1D
extends CoordinateAxis

A 1-dimensional Coordinate Axis. Its values must be monotonic. If this is char valued, it will have rank 2, otherwise it will have rank 1.

If string or char valued, only getCoordName() can be called.

If the coordinates are regularly spaced, isRegular() is true, and the values are equal to getStart() + i * getIncrement().

Version:
$Revision:51 $ $Date:2006-07-12 17:13:13Z $
Author:
john caron
See Also:
CoordinateAxis.factory(ucar.nc2.dataset.NetcdfDataset, ucar.nc2.dataset.VariableDS)

Nested Class Summary
 
Nested classes/interfaces inherited from class ucar.nc2.dataset.CoordinateAxis
CoordinateAxis.AxisComparator
 
Field Summary
 
Fields inherited from class ucar.nc2.dataset.CoordinateAxis
POSITIVE_DOWN, POSITIVE_UP
 
Fields inherited from class ucar.nc2.Variable
defaultSizeToCache
 
Constructor Summary
CoordinateAxis1D(NetcdfDataset ds, Group group, java.lang.String shortName, DataType dataType, java.lang.String dims, java.lang.String units, java.lang.String desc)
          Constructor when theres no underlying variable.
CoordinateAxis1D(VariableDS vds)
          create a 1D coordinate axis from an existing Variable
 
Method Summary
 int findCoordElement(double pos)
          Given a coordinate position, find what grid element contains it.
 int findCoordElement(double pos, int lastIndex)
          Given a coordinate position, find what grid element contains it.
 int findCoordElementBounded(double pos)
          Given a coordinate position, find what grid element contains it, but always return valid index.
 int findCoordElementBounded(double pos, int lastIndex)
          Given a coordinate position, find what grid element contains it, but always return valid index.
 double[] getBound1()
          Get the coordinate bound1 as a double array.
 double[] getBound2()
          Get the coordinate bound1 as a double array.
 double getCoordEdge(int index)
          Get the ith coordinate edge.
 double[] getCoordEdges()
          Get the coordinate edges as a double array.
 double[] getCoordEdges(int i)
          Get the coordinate edges for the ith coordinate.
 java.lang.String getCoordName(int index)
          The "name" of the ith coordinate.
 double getCoordValue(int index)
          Get the ith coordinate value.
 double[] getCoordValues()
          Get the coordinate values as a double array.
 double getIncrement()
          Get Increment value if isRegular()
 int getIndex(java.lang.String name)
          Get the index corresponding to the name.
 double getMaxValue()
          Get the minimum coordinate value
 double getMinValue()
          Get the maximum coordinate value
 java.util.List getNames()
          Get the list of names, to be used for user selection.
 double getStart()
          Get Starting value if isRegular()
 boolean isLayer()
          If coordinate lies between a layer, or is at a point.
 boolean isRegular()
          If evenly spaced.
 Variable section(java.util.List section)
          Create a new Variable that is a logical subsection of this Variable.
 CoordinateAxis1D section(Range r)
          Create a new CoordinateAxis1D as a section of this CoordinateAxis1D.
 void setLayer(boolean isLayer)
          If coordinate lies between a layer, or is at a point.
 
Methods inherited from class ucar.nc2.dataset.CoordinateAxis
compareTo, equals, factory, getAxisType, getBoundaryRef, getInfo, getPositive, getUnitsString, hashCode, isContiguous, isNumeric, setAxisType, setBoundaryRef, setContiguous, setPositive
 
Methods inherited from class ucar.nc2.dataset.VariableDS
addCoordinateSystem, convertScaleOffsetMissing, convertScaleOffsetMissing, convertScaleOffsetMissing, convertScaleOffsetMissing, convertScaleOffsetMissing, enhance, getCoordinateSystems, getDescription, getOriginalDataType, getProxyReader, getUnitString, getValidMax, getValidMin, hasFillValue, hasInvalidData, hasMissing, hasMissingValue, hasScaleOffset, isEnhanced, isFillValue, isInvalidData, isMissing, isMissingValue, removeCoordinateSystem, setFillValueIsMissing, setInvalidDataIsMissing, setMissingDataIsMissing, setProxyReader, setUnitsString, setUseNaNs, slice
 
Methods inherited from class ucar.nc2.Variable
addAttribute, findAttribute, findAttributeIgnoreCase, findDimensionIndex, getAttributes, getCoordinateDimension, getDataType, getDimension, getDimensions, getDimensionsAll, getDimensionsString, getElementSize, getIOVar, getName, getNameAndDimensions, getNameAndDimensions, getParentGroup, getParentStructure, getRanges, getRank, getSectionRanges, getShape, getShortName, getSize, getSizeToCache, getSPobject, hasCachedData, invalidateCache, isCaching, isMemberOfStructure, isMetadata, isScalar, isUnknownLength, isUnlimited, isUnsigned, isVariableLength, read, read, read, read, readAllStructures, readAllStructuresSpec, readScalarByte, readScalarDouble, readScalarFloat, readScalarInt, readScalarLong, readScalarShort, readScalarString, remove, replaceDimension, setCachedData, setCaching, setDataType, setDimension, setDimensions, setDimensions, setDimensionsAnonymous, setElementSize, setIOVar, setIsCoordinateAxis, setName, setParentGroup, setParentStructure, setSizeToCache, setSPobject, toString, toStringDebug, writeCDL
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ucar.nc2.VariableSimpleIF
findAttributeIgnoreCase, getAttributes, getDataType, getDimensions, getName, getRank, getShape, getShortName
 
Methods inherited from interface ucar.nc2.VariableIF
findAttribute, findAttributeIgnoreCase, findDimensionIndex, getAttributes, getCoordinateDimension, getDataType, getDimension, getDimensions, getDimensionsAll, getElementSize, getName, getNameAndDimensions, getParentGroup, getParentStructure, getRanges, getRank, getShape, getShortName, getSize, isMemberOfStructure, isMetadata, isScalar, isUnlimited, isUnsigned, isVariableLength, read, read, read, read, readAllStructures, readAllStructuresSpec, readScalarByte, readScalarDouble, readScalarFloat, readScalarInt, readScalarLong, readScalarShort, readScalarString, toStringDebug
 

Constructor Detail

CoordinateAxis1D

public CoordinateAxis1D(VariableDS vds)
create a 1D coordinate axis from an existing Variable


CoordinateAxis1D

public CoordinateAxis1D(NetcdfDataset ds,
                        Group group,
                        java.lang.String shortName,
                        DataType dataType,
                        java.lang.String dims,
                        java.lang.String units,
                        java.lang.String desc)
Constructor when theres no underlying variable. You better set the values too!

Parameters:
ds - the containing dataset.
group - the containing group; if null, use rootGroup
shortName - axis name.
dataType - data type
dims - list of dimension names
units - units of coordinates, preferably udunit compatible.
desc - long name.
Method Detail

section

public CoordinateAxis1D section(Range r)
                         throws InvalidRangeException
Create a new CoordinateAxis1D as a section of this CoordinateAxis1D.

Parameters:
r - the section range
Returns:
a new CoordinateAxis1D as a section of this CoordinateAxis1D
Throws:
InvalidRangeException

section

public Variable section(java.util.List section)
                 throws InvalidRangeException
Description copied from class: Variable
Create a new Variable that is a logical subsection of this Variable. No data is read until a read method is called on it.

Specified by:
section in interface VariableIF
Overrides:
section in class VariableDS
Parameters:
section - List of type ucar.ma2.Range, with size equal to getRank(). Each Range corresponds to a Dimension, and specifies the section of data to read in that Dimension. A Range object may be null, which means use the entire dimension.
Returns:
a new Variable which is a logical section of this Variable.
Throws:
InvalidRangeException

getCoordName

public java.lang.String getCoordName(int index)
The "name" of the ith coordinate. If nominal, this is all there is to a coordinate. If numeric, this will return a String representation of the coordinate.


getCoordValue

public double getCoordValue(int index)
Get the ith coordinate value. This is the value of the coordinate axis at which the data value is associated. These must be strictly monotonic.

Parameters:
index - which coordinate. Between 0 and getNumElements()-1 inclusive.
Returns:
coordinate value.
Throws:
java.lang.UnsupportedOperationException - if !isNumeric()

getMinValue

public double getMinValue()
Description copied from class: CoordinateAxis
Get the maximum coordinate value

Overrides:
getMinValue in class CoordinateAxis

getMaxValue

public double getMaxValue()
Description copied from class: CoordinateAxis
Get the minimum coordinate value

Overrides:
getMaxValue in class CoordinateAxis

getCoordEdge

public double getCoordEdge(int index)
Get the ith coordinate edge. Exact only if isContiguous() is true, otherwise use getBound1() and getBound2(). This is the value where the underlying grid element switches from "belonging to" coordinate value i-1 to "belonging to" coordinate value i. In some grids, this may not be well defined, and so should be considered an approximation or a visualization hint.

  Coordinate edges must be strictly monotonic:
    coordEdge(0) < coordValue(0) < coordEdge(1) < coordValue(1) ...
    ... coordEdge(i) < coordValue(i) < coordEdge(i+1) < coordValue(i+1) ...
    ... coordEdge(n-1) < coordValue(n-1) < coordEdge(n)
  

Parameters:
index - which coordinate. Between 0 and getNumElements() inclusive.
Returns:
coordinate edge.
Throws:
java.lang.UnsupportedOperationException - if !isNumeric()

getCoordValues

public double[] getCoordValues()
Get the coordinate values as a double array.

Returns:
coordinate value.
Throws:
java.lang.UnsupportedOperationException - if !isNumeric()

getCoordEdges

public double[] getCoordEdges()
Get the coordinate edges as a double array. Exact only if isContiguous() is true, otherwise use getBound1() and getBound2().

Returns:
coordinate edges.
Throws:
java.lang.UnsupportedOperationException - if !isNumeric()

getBound1

public double[] getBound1()
Get the coordinate bound1 as a double array. bound1[i] # coordValue[i] # bound2[i], where # is < if increasing (bound1[i] < bound1[i+1]) else < if decreasing.

Returns:
coordinate bound1.
Throws:
java.lang.UnsupportedOperationException - if !isNumeric()

getBound2

public double[] getBound2()
Get the coordinate bound1 as a double array. bound1[i] # coordValue[i] # bound2[i], where # is < if increasing (bound1[i] < bound1[i+1]) else < if decreasing.

Returns:
coordinate bound2.
Throws:
java.lang.UnsupportedOperationException - if !isNumeric()

getCoordEdges

public double[] getCoordEdges(int i)
Get the coordinate edges for the ith coordinate. Can use this for isContiguous() true or false.

Parameters:
i - coordinate index
Returns:
double[2] edges for ith coordinate

findCoordElement

public int findCoordElement(double pos)
Given a coordinate position, find what grid element contains it. This means that
    edge[i] <= pos < edge[i+1] (if values are ascending)
    edge[i] > pos >= edge[i+1] (if values are descending)
    

Parameters:
pos - position in this coordinate system
Returns:
index of grid point containing it, or -1 if outside grid area

findCoordElement

public int findCoordElement(double pos,
                            int lastIndex)
Given a coordinate position, find what grid element contains it. This means that
    edge[i] <= pos < edge[i+1] (if values are ascending)
    edge[i] > pos >= edge[i+1] (if values are descending)
    

Parameters:
pos - position in this coordinate system
lastIndex - last position we looked for, or -1 if none
Returns:
index of grid point containing it, or -1 if outside grid area

findCoordElementBounded

public int findCoordElementBounded(double pos)
Given a coordinate position, find what grid element contains it, but always return valid index.

Parameters:
pos - position in this coordinate system
Returns:
index of grid point containing it

findCoordElementBounded

public int findCoordElementBounded(double pos,
                                   int lastIndex)
Given a coordinate position, find what grid element contains it, but always return valid index. This means that
      if values are ascending:
        pos < edge[0] return 0
        edge[n] < pos return n-1
        edge[i] <= pos < edge[i+1] return i

      if values are descending:
        pos > edge[0] return 0
        edge[n] > pos return n-1
        edge[i] > pos >= edge[i+1] return i
    

Parameters:
pos - position in this coordinate system
lastIndex - last position we looked for, or -1 if none
Returns:
index of grid point containing it

getStart

public double getStart()
Get Starting value if isRegular()


getIncrement

public double getIncrement()
Get Increment value if isRegular()


isLayer

public boolean isLayer()
If coordinate lies between a layer, or is at a point.


setLayer

public void setLayer(boolean isLayer)
If coordinate lies between a layer, or is at a point.


isRegular

public boolean isRegular()
If evenly spaced. Then value(i) = getStart() + i * getIncrement().


getNames

public java.util.List getNames()
Get the list of names, to be used for user selection. The ith one refers to the ith coordinate.

Returns:
List of ucar.nc2.util.NamedObject, or empty list.

getIndex

public int getIndex(java.lang.String name)
Get the index corresponding to the name.

Parameters:
name -
Returns:
index, or -1 if not found