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- 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)); // looping IndexIterator ii= a.getIndexIterator(); while (ii.hasNext()) lat = ii.getDoubleNext(); if you know the type and rank, a convenient variant is: Variable v = ncFile.findVariable("Latitude"); ArrayDouble.D1 a = (ArrayDouble.D1) v.read(); double lat = a.get(0); // looping for (int i=0; i<a.size(); i++) lat = a.get(i);I keep a copy of the users manual around as it has a convenient API summary im always refering to:
http://www.unidata.ucar.edu/packages/netcdf-java/manual.pdfBTW, im working on a version 2.1 of nc2 that will have some important improvements to dods access.
to get a particular value from a variable. How would I do this using ucar.nc2? 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 *************************************************************