[netCDFJava #SCH-111122]: Problem casting Array
Unidata netCDF Java Support
support-netcdf-java at unidata.ucar.edu
Wed Aug 1 08:25:33 MDT 2007
Hi Philippe:
The most efficient solution:
Array data = v.read();
float[] fdata =(float []) data.get1DJavaArray(float.class);
this avoids copying if the data is already float.
However, you have a 1D array, not 2D. Since you are worried about efficiency, the fastest thing to do is to work with the 1D array (ie dont use a 2D array), and do the stride arithmetic yourself, so use fdata[j*nx+i] whenever you want f[j][i], where nx = data.getShape()[1]. Im assuming you know these are 2D arrays.
otherwise you have to allocate the 2D array and copy into it, in which case you might as well do
Index ima = data.getIndex();
int [] shape = data.getShape();
for (int j = 0; j<shape[0]; j++)
for (int i = 0; i<shape[1]; i++)
f[j][i] = data.getFloat( ima.set(j,i));
Regards,
John
Ticket Details
==================
Ticket ID: SCH-111122
Department: Support netCDF Java
Priority: Normal
Status: Open
More information about the Netcdf-java
mailing list