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

[netCDFJava #YTS-175923]: what's wrong with this code?



> John-
> 
> I'm trying to help CJ read in her netCDF files without going through the
> CDM since that seems problematic.  I'm just trying to read the values in
> each of the variables.  I'm trying something like the attached program.
> However, I get a NullPointerException on the nextFloat() call.  What
> do I need to do differently?  You can use program on any file that has a
> time variable.
> 
> Thanks.
> 
> Don
> --
> Don Murray
> NOAA/ESRL/PSD and CIRES
> 303-497-3596
> http://www.esrl.noaa.gov/psd/people/don.murray/
> 
> 

import ucar.nc2.dataset.NetcdfDataset;
import ucar.nc2.Variable;
import ucar.ma2.Array;

public class TestNCRead {

  public static void main(String[] args) throws Exception {
    NetcdfDataset ncd = NetcdfDataset.openDataset(args[0]);
    Variable timeVar = ncd.findVariable("time");
    if (timeVar == null) {
      System.out.println("no time variable");
      System.exit(0);
    }
    
    Array timeArray = timeVar.read();
    timeArray.resetLocalIterator();
    
    int count = 0;
    while (timeArray.hasNext()) {
      System.out.println("time[" + count + "]= " + timeArray.nextFloat());
      count++;
    }

  }
}


Ticket Details
===================
Ticket ID: YTS-175923
Department: Support netCDF Java
Priority: Normal
Status: Closed