Class DoublePackingScheme

java.lang.Object
noaa.coastwatch.util.chunk.DoublePackingScheme
All Implemented Interfaces:
PackingScheme

public class DoublePackingScheme extends Object implements PackingScheme
The DoublePackingScheme class implements a scale and offset packing scheme for primitive double data. Double values are packed as integer = double/scale + offset and then rounded to the nearest long integer.
Since:
3.4.0
Author:
Peter Hollemans
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    double
    The offset for float data.
    double
    The scaling factor for double data.
  • Constructor Summary

    Constructors
    Constructor
    Description
    DoublePackingScheme(double scale, double offset)
    Creates a new packing instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Accepts a visitor in this scheme.
    boolean
     
    Gets the unpacked data type that values in this packing scheme will be unpacked to.
    int
     
    static void
    main(String[] argv)
    Tests this class.
    long
    packDouble(double value)
    Packs a double value to an integer.
    void
    packToByteData(double[] doubleData, byte[] byteData, Byte missing, boolean isUnsigned)
    Packs primitive data from a double array into a byte array.
    void
    packToIntData(double[] doubleData, int[] intData, Integer missing, boolean isUnsigned)
    Packs primitive data from a double array into a int array.
    void
    packToLongData(double[] doubleData, long[] longData, Long missing)
    Packs primitive data from a double array into a long array.
    void
    packToShortData(double[] doubleData, short[] shortData, Short missing, boolean isUnsigned)
    Packs primitive data from a double array into a short array.
    double
    unpackDouble(long packed)
    Unpacks a long integer value to a double.
    void
    unpackFromByteData(byte[] byteData, double[] doubleData, Byte missing, boolean isUnsigned)
    Unpacks primitive data from a byte array into a double array.
    void
    unpackFromIntData(int[] intData, double[] doubleData, Integer missing, boolean isUnsigned)
    Unpacks primitive data from a int array into a double array.
    void
    unpackFromLongData(long[] longData, double[] doubleData, Long missing)
    Unpacks primitive data from a long array into a double array.
    void
    unpackFromShortData(short[] shortData, double[] doubleData, Short missing, boolean isUnsigned)
    Unpacks primitive data from a short array into a double array.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • scale

      public double scale
      The scaling factor for double data.
    • offset

      public double offset
      The offset for float data.
  • Constructor Details

    • DoublePackingScheme

      public DoublePackingScheme(double scale, double offset)
      Creates a new packing instance.
      Parameters:
      scale - the scaling factor.
      offset - the offset value.
      Since:
      3.6.1
  • Method Details

    • getUnpackedType

      public DataChunk.DataType getUnpackedType()
      Description copied from interface: PackingScheme
      Gets the unpacked data type that values in this packing scheme will be unpacked to.
      Specified by:
      getUnpackedType in interface PackingScheme
    • accept

      public void accept(PackingSchemeVisitor visitor)
      Description copied from interface: PackingScheme
      Accepts a visitor in this scheme.
      Specified by:
      accept in interface PackingScheme
      Parameters:
      visitor - the visitor to accept.
    • unpackFromByteData

      public void unpackFromByteData(byte[] byteData, double[] doubleData, Byte missing, boolean isUnsigned)
      Unpacks primitive data from a byte array into a double array.
      Parameters:
      byteData - the source array to unpack.
      doubleData - the destination array to unpack into.
      missing - the missing value to detect (or null for none). Values in the source array that match the missing value will be assigned Double.NaN in the destination array.
      isUnsigned - the unsigned flag, true if the data is unsigned or false if not.
    • packToByteData

      public void packToByteData(double[] doubleData, byte[] byteData, Byte missing, boolean isUnsigned)
      Packs primitive data from a double array into a byte array.
      Parameters:
      doubleData - the source array to pack.
      byteData - the destination array to pack into.
      missing - the missing value to detect (or null for none). Non-finite (NaN and infinity values) in the source array will be assigned the missing value in the destination array.
      isUnsigned - the unsigned flag, true if the destination data is unsigned or false if not.
    • unpackFromShortData

      public void unpackFromShortData(short[] shortData, double[] doubleData, Short missing, boolean isUnsigned)
      Unpacks primitive data from a short array into a double array.
      Parameters:
      shortData - the source array to unpack.
      doubleData - the destination array to unpack into.
      missing - the missing value to detect (or null for none). Values in the source array that match the missing value will be assigned Double.NaN in the destination array.
      isUnsigned - the unsigned flag, true if the data is unsigned or false if not.
    • packToShortData

      public void packToShortData(double[] doubleData, short[] shortData, Short missing, boolean isUnsigned)
      Packs primitive data from a double array into a short array.
      Parameters:
      doubleData - the source array to pack.
      shortData - the destination array to pack into.
      missing - the missing value to detect (or null for none). Non-finite (NaN and infinity values) in the source array will be assigned the missing value in the destination array.
      isUnsigned - the unsigned flag, true if the destination data is unsigned or false if not.
    • unpackFromIntData

      public void unpackFromIntData(int[] intData, double[] doubleData, Integer missing, boolean isUnsigned)
      Unpacks primitive data from a int array into a double array.
      Parameters:
      intData - the source array to unpack.
      doubleData - the destination array to unpack into.
      missing - the missing value to detect (or null for none). Values in the source array that match the missing value will be assigned Double.NaN in the destination array.
      isUnsigned - the unsigned flag, true if the data is unsigned or false if not.
    • packToIntData

      public void packToIntData(double[] doubleData, int[] intData, Integer missing, boolean isUnsigned)
      Packs primitive data from a double array into a int array.
      Parameters:
      doubleData - the source array to pack.
      intData - the destination array to pack into.
      missing - the missing value to detect (or null for none). Non-finite (NaN and infinity values) in the source array will be assigned the missing value in the destination array.
      isUnsigned - the unsigned flag, true if the destination data is unsigned or false if not.
    • unpackFromLongData

      public void unpackFromLongData(long[] longData, double[] doubleData, Long missing)
      Unpacks primitive data from a long array into a double array.
      Parameters:
      longData - the source array to unpack.
      doubleData - the destination array to unpack into.
      missing - the missing value to detect (or null for none). Values in the source array that match the missing value will be assigned Double.NaN in the destination array.
    • packToLongData

      public void packToLongData(double[] doubleData, long[] longData, Long missing)
      Packs primitive data from a double array into a long array.
      Parameters:
      doubleData - the source array to pack.
      longData - the destination array to pack into.
      missing - the missing value to detect (or null for none). Non-finite (NaN and infinity values) in the source array will be assigned the missing value in the destination array.
    • packDouble

      public long packDouble(double value)
      Packs a double value to an integer.
      Parameters:
      value - the double value to pack.
      Returns:
      the packed value as a long integer or 0 if the value is Double.NaN.
    • unpackDouble

      public double unpackDouble(long packed)
      Unpacks a long integer value to a double.
      Parameters:
      packed - the long integer value to unpack.
      Returns:
      the unpacked double value.
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • main

      public static void main(String[] argv) throws Exception
      Tests this class.
      Parameters:
      argv - the array of command line parameters.
      Throws:
      Exception