Hi Tommy-
If there was a publicly available repository, I'd tell you to just check
it in. ;-)
It would probably be easiest if you just sent the modified version of
the latest DataUtil source to support-idv@xxxxxxxxxxxxxxxx so they can
check it in.
Don
On 6/20/11 8:13 AM, Tommy Jasmin wrote:
Guys - oops... the method I sent in the original report was not
quite right. This is what Ghansham and I believe the toFloatArray()
method should look like. The further change is near the beginning,
setting fromClass. Previously, the method was basing the originating
class type on the destination class type, which we know is float!
Previous two lines:
Object dst = arr.get1DJavaArray(float.class);
Class fromClass = dst.getClass().getComponentType();
/**
* Get the 1D values for an array as floats.
*
* @param arr Array of values
* @return float representation
*/
public static float[] toFloatArray(Array arr) {
Class fromClass = arr.getElementType();
if (fromClass.equals(float.class)) {
//It should always be a float
return (float[]) dst;
} else {
float[] values = new float[(int) arr.getSize()];
boolean isUnsigned = arr.isUnsigned();
if (fromClass.equals(byte.class)) {
byte[] fromArray = (byte[]) dst;
for (int i = 0; i < fromArray.length; ++i) {
if (isUnsigned) {
values[i] = (int) fromArray[i] & 0xFF;
} else {
values[i] = fromArray[i];
}
}
} else if (fromClass.equals(short.class)) {
short[] fromArray = (short[]) dst;
for (int i = 0; i < fromArray.length; ++i) {
if (isUnsigned) {
values[i] = (int) fromArray[i] & 0xFFFF;
} else {
values[i] = fromArray[i];
}
}
} else if (fromClass.equals(int.class)) {
int[] fromArray = (int[]) dst;
for (int i = 0; i < fromArray.length; ++i) {
if (isUnsigned) {
values[i] = (long) fromArray[i] & 0xFFFFFFFF;
} else {
values[i] = fromArray[i];
}
}
} else if (fromClass.equals(double.class)) {
double[] fromArray = (double[]) dst;
for (int i = 0; i < fromArray.length; ++i) {
values[i] = (float) fromArray[i];
}
} else {
throw new IllegalArgumentException("Unknown array type:"
+ fromClass.getName());
}
return values;
}
}
--
Don Murray
NOAA/ESRL/PSD and CIRES
303-497-3596
http://www.esrl.noaa.gov/psd/people/don.murray/