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.
Don Murray wrote:
John- 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 = v.read(); // 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 = v.read(); Index ima = a.getIndex(); return a.getDouble(ima.set(index)); } to replace var.getDouble(index) with 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 readin 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.
Thanks. Don ************************************************************* Don Murray UCAR Unidata Program address@hidden P.O. Box 3000 (303) 497-8628 Boulder, CO 80307 http://www.unidata.ucar.edu/staff/donm *************************************************************