Hi all,
We're using the NetCDF-Java library to read some data from some netCDF files.
Some of these files have been remapped to an approximately 1 degree lat/lon
grid, due to this the lat/lon are on an unusual format, and not an actual
dimension in the file (see netcdf output right below). This file seems to work
in thredds data server, I can view the map nicely in godiva2, and it supposedly
seems to cover all oceans, with values everywhere.
---------------------------------------------------------------------------------------------------------
netcdf -h dump:
netcdf Variable_merged_mesh {
dimensions:
x = 182 ;
y = 149 ;
lev = 31 ;
time = UNLIMITED ; // (72 currently)
variables:
double lev(lev) ;
lev:long_name = "generic" ;
lev:units = "level" ;
lev:axis = "Z" ;
double time(time) ;
time:standard_name = "time" ;
time:units = "months since 1990-01-01 00:00:00" ;
time:calendar = "standard" ;
float SomeVar(time, lev, y, x) ;
SomeVar:long_name = "SomeVar" ;
SomeVar:units = "m" ;
SomeVar:_FillValue = 1.91e+026f ;
SomeVar:coordinates = "nav_lon nav_lat time" ;
float nav_lon(y, x) ;
nav_lon:long_name = "longitude" ;
nav_lon:units = "degrees_east" ;
float nav_lat(y, x) ;
nav_lat:long_name = "latitude" ;
nav_lat:units = "degrees_north" ;
// global attributes:
:Conventions = "CF-1.0" ;
}
---------------------------------------------------------------------------------------------------------
Now, I want to be able to extract values on a lot of lon/lat coordinates, so in
this example I cover the larger part of the north-Atlantic with lat from 12 to
45 and lon from -57 to 21. Here is a test sample of a function that does not
work, and I have no idea why:
---------------------------------------------------------------------------------------------------------
NetcdfDataset ncfile = NetcdfDataset.openDataset(filename);
GridDataset gds = new GridDataset(ncfile);
GridDatatype grid = gds.findGridDatatype("SomeVar");
GridCoordSystem gcs = grid.getCoordinateSystem();
double lat = -15;
double lon = -40;
int count = 0;
int countHits = 0;
for (int i = 12; i <= 45; i++) {
for (int j = -57; j <= 21; j++) {
count++;
lat = i;
lon = j;
int[] xy = gcs.findXYindexFromLatLon(lat, lon, null);
if (xy[0] != -1 && xy[1] != -1) {
Array data = grid.readDataSlice(0, 0, xy[1], xy[0]);
double val = data.getDouble(0);
if (!Double.isNaN(val)) {
System.out.println("x,y:" + xy[0] + "," + xy[1]);
System.out.printf("Value at %f %f == %f%n", lat, lon, val);
LatLonPoint p = gcs.getLatLon(xy[0], xy[1]);
// System.out.println(data.toString());
System.out.println(p.getLatitude());
System.out.println(p.getLongitude());
countHits++;
}
}
}
}
System.out.println("hits/count:"+countHits+"/"+count);
---------------------------------------------------------------------------------------------------------
This function would print out hits/count:0/2686 - so it found no values on all
those coordinates. If I extend the search to -90 to 90 and -180 to 180, then I
find some valid data: hits/count:10341/65341.
What am I missing here? Is it something wrong on the netCDF format? Am I using
the library wrong? Is it a bug in the library with this specific format? This
functions works well for a bunch of other netCDF files on other formats.
I would greatly appreciate any help with this.
Many thanks,
Aleksander Vines
Programmer
Nansen Environmental and Remote Sensing Center
E-MAIL: aleksander.vines@xxxxxxxx, WEB: http://www.nersc.no
PHONE: +47 55 20 58 00,
ADDRESS: Thormøhlens gate 47, 5006 Bergen, Norway