Re: nc2



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.pdf

BTW, 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
dmurray@xxxxxxxxxxxxxxxx                        P.O. Box 3000
(303) 497-8628                              Boulder, CO 80307
http://www.unidata.ucar.edu/staff/donm
*************************************************************





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