[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[netCDFDecoders #JNJ-582161]: FW: How to use Grib1GetData
- Subject: [netCDFDecoders #JNJ-582161]: FW: How to use Grib1GetData
- Date: Wed, 30 Sep 2009 12:47:31 -0600
Craig,
I suggest that you look at netcdf-java at:
http://www.unidata.ucar.edu/software/netcdf-java/
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.
RObb...
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) {
exc.printStackTrace();
}
}
}
Ticket Details
===================
Ticket ID: JNJ-582161
Department: Support netCDF Decoders
Priority: Normal
Status: Open