Re: nc2

Don Murray wrote:


John Caron wrote:

Don Murray wrote:

I have some code that reads a netCDF file using the ucar.netcdf
package.  I wanted to use VariableStandardized from ucar.nc2,
so need to move my code to use ucar.nc2.  I've got lines like:

   ncFile.get("Latitude").getDouble(new int[] {0}));

Variable v = ncFile.findVariable("Latitude");
Array a =;        // does the actual I/O
Index ima = a.getIndex();
double lat = a.getDouble(ima.set0(0));

I changed some of my code so that I now have a method:

public static double getDouble(Variable v, int[] index) throws IOException {
        Array a =;
        Index ima = a.getIndex();
        return a.getDouble(ima.set(index));

to replace



     getDouble(var, index)

This ends up taking WAY longer than the old ucar.netcdf stuff.
Is there any caching done or does it read the entire variable
into memory for each call?  In some cases, I'm looping over
a set of variables so the getDouble is being called 10-20 times
on each variable.  Is there a way to see if I've already read
in the Array if there is no caching?

theres no caching done on a regular Variable. There is caching on a DODS Variable, and some other subtypes.

im not sure why its taking longer than ucar.netcdf, since it uses that package underneath.If there is caching at the random access file, it should still be there.

otherwise, youve got a fair amount more overhead, since you have to create several extra objects. how much slowdown do you see?

i'll look at adding transparent caching in the next release. in the meanwhile, you might want to cache the full Array yourself.


Don Murray                               UCAR Unidata Program
dmurray@xxxxxxxxxxxxxxxx                        P.O. Box 3000
(303) 497-8628                              Boulder, CO 80307

  • 2003 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdf-java archives: