Package noaa.coastwatch.util.chunk
Class DoublePackingScheme
java.lang.Object
noaa.coastwatch.util.chunk.DoublePackingScheme
- All Implemented Interfaces:
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
-
Constructor Summary
ConstructorDescriptionDoublePackingScheme
(double scale, double offset) Creates a new packing instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
accept
(PackingSchemeVisitor visitor) Accepts a visitor in this scheme.boolean
Gets the unpacked data type that values in this packing scheme will be unpacked to.int
hashCode()
static void
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.
-
Field Details
-
scale
public double scaleThe scaling factor for double data. -
offset
public double offsetThe 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
Description copied from interface:PackingScheme
Gets the unpacked data type that values in this packing scheme will be unpacked to.- Specified by:
getUnpackedType
in interfacePackingScheme
-
accept
Description copied from interface:PackingScheme
Accepts a visitor in this scheme.- Specified by:
accept
in interfacePackingScheme
- 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
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
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
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
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
-
hashCode
public int hashCode() -
main
Tests this class.- Parameters:
argv
- the array of command line parameters.- Throws:
Exception
-