diff --git a/definitions/grib1/grid_definition_1.def b/definitions/grib1/grid_definition_1.def index 0dbce8698..14caa71a8 100644 --- a/definitions/grib1/grid_definition_1.def +++ b/definitions/grib1/grid_definition_1.def @@ -64,6 +64,8 @@ iterator mercator(numberOfPoints,missingValue,values, jPointsAreConsecutive, alternativeRowScanning); +nearest mercator(values,radius,Nx,Ny); + meta latLonValues latlonvalues(values); alias latitudeLongitudeValues=latLonValues; meta latitudes latitudes(values,0); diff --git a/definitions/grib2/template.3.10.def b/definitions/grib2/template.3.10.def index 1a2f2d57f..818c43c09 100644 --- a/definitions/grib2/template.3.10.def +++ b/definitions/grib2/template.3.10.def @@ -75,6 +75,8 @@ iterator mercator(numberOfPoints,missingValue,values, iScansNegatively, jScansPositively, jPointsAreConsecutive, alternativeRowScanning); +nearest mercator(values,radius,Nx,Ny); + meta latLonValues latlonvalues(values); alias latitudeLongitudeValues=latLonValues; meta latitudes latitudes(values,0); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7db38f5c4..682f92310 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -346,6 +346,7 @@ list( APPEND grib_api_srcs grib_nearest_class_latlon_reduced.c grib_nearest_class_sh.c grib_nearest_class_lambert_conformal.c + grib_nearest_class_mercator.c grib_nearest_class_polar_stereographic.c grib_iterator_class_polar_stereographic.c grib_iterator_class_lambert_azimuthal_equal_area.c diff --git a/src/Makefile.am b/src/Makefile.am index 6055f9f33..2008953f4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -361,6 +361,7 @@ libeccodes_la_prototypes= \ grib_nearest_class_latlon_reduced.c \ grib_nearest_class_sh.c \ grib_nearest_class_lambert_conformal.c \ + grib_nearest_class_mercator.c \ grib_nearest_class_polar_stereographic.c \ grib_iterator_class_polar_stereographic.c \ grib_iterator_class_lambert_azimuthal_equal_area.c \ diff --git a/src/grib_nearest.c b/src/grib_nearest.c index 64d277436..ca482fb04 100644 --- a/src/grib_nearest.c +++ b/src/grib_nearest.c @@ -323,6 +323,11 @@ int grib_nearest_find_generic( return ret; nearest->values_count = nvalues; + if (grib_is_earth_oblate(h)) { + grib_context_log(h->context, GRIB_LOG_ERROR, "Nearest neighbour functionality only supported for spherical earth."); + return GRIB_NOT_IMPLEMENTED; + } + if ((ret = grib_get_long_internal(h, radius_keyname, &iradius)) != GRIB_SUCCESS) return ret; if (grib_is_missing(h, radius_keyname, &ret)) { diff --git a/src/grib_nearest_class.h b/src/grib_nearest_class.h index 772129e18..5962393cb 100644 --- a/src/grib_nearest_class.h +++ b/src/grib_nearest_class.h @@ -2,6 +2,7 @@ extern grib_nearest_class* grib_nearest_class_gen; extern grib_nearest_class* grib_nearest_class_lambert_conformal; extern grib_nearest_class* grib_nearest_class_latlon_reduced; +extern grib_nearest_class* grib_nearest_class_mercator; extern grib_nearest_class* grib_nearest_class_polar_stereographic; extern grib_nearest_class* grib_nearest_class_reduced; extern grib_nearest_class* grib_nearest_class_regular; diff --git a/src/grib_nearest_class_lambert_conformal.c b/src/grib_nearest_class_lambert_conformal.c index 994782d92..539dfe73f 100644 --- a/src/grib_nearest_class_lambert_conformal.c +++ b/src/grib_nearest_class_lambert_conformal.c @@ -107,9 +107,9 @@ static int find(grib_nearest* nearest, grib_handle* h, { grib_nearest_lambert_conformal* self = (grib_nearest_lambert_conformal*)nearest; return grib_nearest_find_generic( - nearest, h, inlat, inlon, flags, + nearest, h, inlat, inlon, flags, /* inputs */ - self->values_key, + self->values_key, /* outputs to set the 'self' object */ self->radius, &(self->lats), &(self->lats_count), @@ -119,7 +119,7 @@ static int find(grib_nearest* nearest, grib_handle* h, self->Ni, self->Nj, - outlats, outlons, + outlats, outlons, /* outputs of the find function */ values, distances, indexes, len); } diff --git a/src/grib_nearest_class_mercator.c b/src/grib_nearest_class_mercator.c index 11dfa7a3f..699a103fb 100644 --- a/src/grib_nearest_class_mercator.c +++ b/src/grib_nearest_class_mercator.c @@ -107,9 +107,9 @@ static int find(grib_nearest* nearest, grib_handle* h, { grib_nearest_mercator* self = (grib_nearest_mercator*)nearest; return grib_nearest_find_generic( - nearest, h, inlat, inlon, flags, + nearest, h, inlat, inlon, flags, /* inputs */ - self->values_key, + self->values_key, /* outputs to set the 'self' object */ self->radius, &(self->lats), &(self->lats_count), @@ -119,7 +119,7 @@ static int find(grib_nearest* nearest, grib_handle* h, self->Ni, self->Nj, - outlats, outlons, + outlats, outlons, /* outputs of the find function */ values, distances, indexes, len); } diff --git a/src/grib_nearest_class_polar_stereographic.c b/src/grib_nearest_class_polar_stereographic.c index 64bb558b2..95271c197 100644 --- a/src/grib_nearest_class_polar_stereographic.c +++ b/src/grib_nearest_class_polar_stereographic.c @@ -107,9 +107,9 @@ static int find(grib_nearest* nearest, grib_handle* h, { grib_nearest_polar_stereographic* self = (grib_nearest_polar_stereographic*)nearest; return grib_nearest_find_generic( - nearest, h, inlat, inlon, flags, + nearest, h, inlat, inlon, flags, /* inputs */ - self->values_key, + self->values_key, /* outputs to set the 'self' object */ self->radius, &(self->lats), &(self->lats_count), @@ -119,7 +119,7 @@ static int find(grib_nearest* nearest, grib_handle* h, self->Ni, self->Nj, - outlats, outlons, + outlats, outlons, /* outputs of the find function */ values, distances, indexes, len); } diff --git a/src/grib_nearest_factory.h b/src/grib_nearest_factory.h index 211969962..8ec5cfedf 100644 --- a/src/grib_nearest_factory.h +++ b/src/grib_nearest_factory.h @@ -2,6 +2,7 @@ { "gen", &grib_nearest_class_gen, }, { "lambert_conformal", &grib_nearest_class_lambert_conformal, }, { "latlon_reduced", &grib_nearest_class_latlon_reduced, }, +{ "mercator", &grib_nearest_class_mercator, }, { "polar_stereographic", &grib_nearest_class_polar_stereographic, }, { "reduced", &grib_nearest_class_reduced, }, { "regular", &grib_nearest_class_regular, }, diff --git a/tests/grib_mercator.sh b/tests/grib_mercator.sh index 1fb3f44bd..0a74ec485 100755 --- a/tests/grib_mercator.sh +++ b/tests/grib_mercator.sh @@ -30,5 +30,9 @@ EOF ${tools_dir}/grib_filter $tempFilter $input +# Nearest function +${tools_dir}/grib_ls -l 19,-97,1 $input > $tempOut +grep -q "Point chosen #1 index=618" $tempOut + # Clean up rm -f $tempFilter $tempOut