Thanks for the fixes. It is best to send the completed code rather than
snippets if possible. I think Tommy is working on a version of DataUtil.
Please send all bugs to support-idv@xxxxxxxxxxxxxxxx and the Unidata
Support Team will address them.
Don
On 6/21/11 3:12 AM, Ghansham Sangar wrote:
On 06/20/2011 09:08 PM, Tommy Jasmin wrote:
On 6/20/11 9:36 AM, Don Murray wrote:
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.
Hi Don -
Don't have a version with all pertinent methods changed and tested. I
could
do that, but as always time is tight and was hoping Julien and Yuan
could take
it from there. I think it's just similar logic in toDoubleArray() and
toCharArray().
Besides, we got more coming down the pipe. Ghansham is a racehorse,
he leaves me in the dust even when I'm firing on all cylinders.
However... Julien and Yuan - I can do what Don suggested if you need,
just holler.
Hey guys.....
A very good morning to all of you.
I think you guys are simply the best of the lot.
Thanks a lot for all the support that you are giving to me.
Actually I did it only for byte class because that was the type of data
I was dealing with.
Tommy extended it for short and int. And I am sure that its quite fine.
I have done away with the 'dst' variable that was available in the
earlier method. I have extracted the
1DJavaArrays after deciding the elementtype of the array.
Just see the modified method below.
I have tested this one for byte data. It works very well for byte data.
/**
* 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[]) arr.get1DJavaArray(float.class);
} else {
float[] values = new float[(int) arr.getSize()];
boolean isUnsigned = arr.isUnsigned();
if (fromClass.equals(byte.class)) {
byte[] fromArray = (byte[]) arr.get1DJavaArray(byte.class);
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[]) arr.get1DJavaArray(short.class);
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[]) arr.get1DJavaArray(int.class);
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[]) arr.get1DJavaArray(double.class);
for (int i = 0; i < fromArray.length; ++i) {
values[i] = (float) fromArray[i];
}
} else {
throw new IllegalArgumentException("Unknown array type:"
+ fromClass.getName());
}
return values;
}
}
Just do guide me how to submit a bug request with IDV as I have a few
more :-).
Anyways thanks again for all the support you are providing.
regards
Ghansham
--
Don Murray
NOAA/ESRL/PSD and CIRES
303-497-3596
http://www.esrl.noaa.gov/psd/people/don.murray/