NSF Unidata

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NetCDF Array to Java byte array, speed issue

This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.



theres not much else to do to speed up the read for now. we will rewrite the library using the java.nio package sometime in the future; preliminary tests suggest we will get a factor of 2 speedup.

you can extract the byte array through:

  byte[] data = (byte[]) fullA.getStorage();



William Ruddick wrote:

John / Support -

I have a huge 5120x5120 byte array representing a Sataelite image, that I am reading out of a NetCDF file using the

NetCDF Java Libraries v.2.

It is taking me an average of 10 seconds on a P2 233 Windows 200 machine with 512M ram.

I believe this is taking twice as long as it should be. Do you have any suggestions?

My code is a follows:

//////////////////////////////////

fullimagebytes = new byte[(int)5120*5120];

ucar.nc2.Variable lVar = cdfFile.findVariable("image");

ucar.ma2.Array fullA = lVar.read(); // This statement takes on average 5 seconds

ucar.ma2.IndexIterator iter = fullA.getIndexIteratorFast();
int xi = 0;
while (iter.hasNext()) { // This loop takes another 5 seconds on average
fullimagebytes[xi] = iter.getByteNext(); xi++;
   }

//////////////////////////////////

I believe there should be some way to go directly from a ucar.nc2.Variable to a primitive byte array in 5 seconds or less.

Thanks,

NOAA International Division - FX-Net

-William Ruddick

address@hidden <mailto:address@hidden>

303-497-6757