Class FloatPackingScheme

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

public class FloatPackingScheme extends Object implements PackingScheme
The FloatPackingScheme class implements a scale and offset packing scheme for primitive float data. Float values are packed as integer = float/scale + offset and then rounded to the nearest integer. Various convenience methods are available for packing and unpacking primitive data arrays.
Since:
3.4.0
Author:
Peter Hollemans
  • Field Summary

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

    Constructors
    Constructor
    Description
    FloatPackingScheme(float scale, float 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.
    int
    packFloat(float value)
    Packs a float value to an integer.
    void
    packToByteData(float[] floatData, byte[] byteData, Byte missing, boolean isUnsigned)
    Packs primitive data from a float array into a byte array.
    void
    packToIntData(float[] floatData, int[] intData, Integer missing)
    Packs primitive data from a float array into a int array.
    void
    packToShortData(float[] floatData, short[] shortData, Short missing, boolean isUnsigned)
    Packs primitive data from a float array into a short array.
    float
    unpackFloat(int packed)
    Unpacks an integer value to a float.
    void
    unpackFromByteData(byte[] byteData, float[] floatData, Byte missing, boolean isUnsigned)
    Unpacks primitive data from a byte array into a float array.
    void
    unpackFromIntData(int[] intData, float[] floatData, Integer missing)
    Unpacks primitive data from a int array into a float array.
    void
    unpackFromShortData(short[] shortData, float[] floatData, Short missing, boolean isUnsigned)
    Unpacks primitive data from a short array into a float array.

    Methods inherited from class java.lang.Object

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

    • scale

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

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

    • FloatPackingScheme

      public FloatPackingScheme(float scale, float 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, float[] floatData, Byte missing, boolean isUnsigned)
      Unpacks primitive data from a byte array into a float array.
      Parameters:
      byteData - the source array to unpack.
      floatData - 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 Float.NaN in the destination array.
      isUnsigned - the unsigned flag, true if the data is unsigned or false if not.
    • packToByteData

      public void packToByteData(float[] floatData, byte[] byteData, Byte missing, boolean isUnsigned)
      Packs primitive data from a float array into a byte array.
      Parameters:
      floatData - 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, float[] floatData, Short missing, boolean isUnsigned)
      Unpacks primitive data from a short array into a float array.
      Parameters:
      shortData - the source array to unpack.
      floatData - 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 Float.NaN in the destination array.
      isUnsigned - the unsigned flag, true if the data is unsigned or false if not.
    • packToShortData

      public void packToShortData(float[] floatData, short[] shortData, Short missing, boolean isUnsigned)
      Packs primitive data from a float array into a short array.
      Parameters:
      floatData - 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, float[] floatData, Integer missing)
      Unpacks primitive data from a int array into a float array.
      Parameters:
      intData - the source array to unpack.
      floatData - 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 Float.NaN in the destination array.
    • packToIntData

      public void packToIntData(float[] floatData, int[] intData, Integer missing)
      Packs primitive data from a float array into a int array.
      Parameters:
      floatData - 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.
    • packFloat

      public int packFloat(float value)
      Packs a float value to an integer.
      Parameters:
      value - the float value to pack.
      Returns:
      the packed value as an integer, or 0 if the value is Float.NaN.
    • unpackFloat

      public float unpackFloat(int packed)
      Unpacks an integer value to a float.
      Parameters:
      packed - the integer value to unpack.
      Returns:
      the unpacked float 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