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

Re: [netcdf-java] GridCoordSys introduces rounding error when converting from km to m and integer axis-type



Heiko Klein wrote:
Hi John,

you can download a file from http://pastebin.met.no/pastebin/cgi-bin/file?id=84f2552e57e811173f846941bfab295a733bb219/mipom_nordic4_inM_small4.nc

We've been using the file through thredds/WCS and it didn't give a bounding-box in GetCapabilities. Changing the axes datatype to double solved the problem.

I guess, the problem lies in:
private CoordinateAxis convertUnits(CoordinateAxis axis) {
    ....
    Array data;
    try {
      data = axis.read();
    ....
    IndexIterator ii = data.getIndexIterator();
    while (ii.hasNext())
      ii.setDoubleCurrent(factor * ii.getDoubleNext());
    ....
with data having the same datatype as axis.

yes, thats the problem, thanks for figuring it out. Ill have to figure out a 
workaround, i guess i should promote to double. it sounds like you have a fix 
for now?


The class ucar.nc2.dt.grid.GridCoordSys converts internally all projection-axes to km. But it seems like it does not convert the datatype to a float or double datatype and introduces therefore large rounding errors.

I have given my axes as m (in integer):
-3716017, -3712004, -3707991

The isRegular function of Coordinate1D sees (with a debugger attched) the values:
-3716, -3712, -3707
and as such fails with my approx. 4km grid-distance.



Best regards,

Heiko