Package noaa.coastwatch.util.chunk
Class FloatPackingScheme
java.lang.Object
noaa.coastwatch.util.chunk.FloatPackingScheme
- All Implemented Interfaces:
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
-
Constructor Summary
ConstructorDescriptionFloatPackingScheme
(float scale, float 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.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.
-
Field Details
-
scale
public float scaleThe scaling factor for float data. -
offset
public float offsetThe 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
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, 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
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
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
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
-
hashCode
public int hashCode() -
main
Tests this class.- Parameters:
argv
- the array of command line parameters.- Throws:
Exception
-