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

Problems reading NetCDF data - get NaNs

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.


  • Subject: Problems reading NetCDF data - get NaNs
  • Date: Thu, 19 Oct 2006 09:06:56 +0100

Dear all,

I'm having some problems reading data from a particular NetCDF file.
The code i'm using is:

 NetcdfDataset nc =
NetcdfDataset.openDataset("C:\\data\\OA_20060830.nc", true, null);
 GridDataset gd = new GridDataset(nc);
 GeoGrid gg = gd.findGridByName("temperature");
 Array arr = gg.readYXData(0, 0);
 IndexIterator it = arr.getIndexIteratorFast();
 while (it.hasNext()) {
     double val = it.getDoubleNext();
     System.out.println("" + val);
 }
 nc.close();

I just get a load of NaNs, even though I know that there are valid
data in the file (ncBrowse displays the data perfectly).  The only
unusual thing about the data is that the data are stored as short
integers, with an offset and scale factor:

    short temperature(time, depth, latitude, longitude);
       :long_name = "Temperature";
       :missing_value = 32767; // short
       :_FillValue = 32767; // short
       :units = "degree_Celsius";
       :valid_min = -3; // short
       :valid_max = 40; // short
       :add_offset = 20.0; // double
       :scale_factor = 0.0010; // double
       :comment = "Temperature estimate (by objective analysis)";

I understood that the NetcdfDataset class automatically dealt with
offsets and scale factors  in "enhanced" mode, which is what I am
using (or trying to use).  Hence I was expecting to "see" the data as
an array of doubles.  The same happens if I use getFloatNext() or
getShortNext().

Can anyone see what I'm doing wrong?

Thanks in advance,
Jon

--
--------------------------------------------------------------
Dr Jon Blower              Tel: +44 118 378 5213 (direct line)
Technical Director         Tel: +44 118 378 8741 (ESSC)
Reading e-Science Centre   Fax: +44 118 378 6413
ESSC                       Email: address@hidden
University of Reading
3 Earley Gate
Reading RG6 6AL, UK
--------------------------------------------------------------

===============================================================================
To unsubscribe netcdf-java, visit:
http://www.unidata.ucar.edu/mailing-list-delete-form.html
===============================================================================