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

[netCDFDecoders #JNJ-582161]: FW: How to use Grib1GetData


I suggest that you look at netcdf-java at: 
especially download and run the ToolsUI program. The documentation doesn't 
exist but to get started put the file name in the dataset slot and hit return, 
it will bring up a description of the file etc. Right click on the variable 
name and then
left click to get the declaration or ncdump the data. Click the ncdump tag and 
it will dump the data. If you look at the
top it has air_temperature(0:0:1, 0:0:1, 0:100:1, 0:270:1).  These are the 
dimensions of the data, this information is
needed in the example program.  0:0:1 means start at 0, end at 0, using stride 
of 1. Do some trial and error with the program, you will see it can do most 
task without getting into the details of the underlining data packages. The 
following sample program displays the lat, lon, and air_temperature 
information. You will have to set a classpath to reference the toolsui jar file 
so you can compile and run the program. I would also look at the JavaDocs for 
how to use the methods.


package ucar.nc2;

import ucar.ma2.Array;
import ucar.ma2.IndexIterator;

public class TestGetData {

   public static void main(String[] args) {
       try {
         NetcdfFile ncf = NetcdfFile.open( 
"/local/robb/data/grib/GR12009092706_air_temp" );
         Variable at = ncf.findVariable("air_temperature");
         Array adata = at.read( "0,0,0:100,0:270");
         Variable lat = ncf.findVariable("lat");
         Array latdata = lat.read( "0:100");
         Variable lon = ncf.findVariable("lon");         
         Array londata = lon.read( "0:270");
         IndexIterator aiter = adata.getIndexIterator();

         IndexIterator latiter = latdata.getIndexIterator();
         while(latiter.hasNext()) {
           double latval = latiter.getDoubleNext();
           IndexIterator loniter = londata.getIndexIterator();
           while(loniter.hasNext()) {
                float aval = aiter.getFloatNext();
                double lonval = loniter.getDoubleNext();
                System.out.println( latval +" "+ lonval +" "+ aval);

         System.out.println( "Success");
       } catch (Exception exc) {


Ticket Details
Ticket ID: JNJ-582161
Department: Support netCDF Decoders
Priority: Normal
Status: Open

NOTE: All email exchanges with Unidata User Support are recorded in the Unidata inquiry tracking system and then made publicly available through the web. If you do not want to have your interactions made available in this way, you must let us know in each email you send to us.