Skip to content

Commit 89e1a64

Browse files
committed
ECC-1781: Fix nearest
1 parent 08369d1 commit 89e1a64

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

src/grib_nearest_class_reduced.cc

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
MEMBERS = double lon_first
3030
MEMBERS = double lon_last
3131
MEMBERS = int legacy
32+
MEMBERS = int rotated
3233
END_CLASS_DEF
3334
3435
*/
@@ -69,6 +70,7 @@ typedef struct grib_nearest_reduced{
6970
double lon_first;
7071
double lon_last;
7172
int legacy;
73+
int rotated;
7274
} grib_nearest_reduced;
7375

7476
extern grib_nearest_class* grib_nearest_class_gen;
@@ -101,6 +103,7 @@ static int init(grib_nearest* nearest, grib_handle* h, grib_arguments* args)
101103
self->pl = grib_arguments_get_name(h, args, self->cargs++);
102104
self->j = (size_t*)grib_context_malloc(h->context, 2 * sizeof(size_t));
103105
self->legacy = -1;
106+
self->rotated = -1;
104107
if (!self->j)
105108
return GRIB_OUT_OF_MEMORY;
106109
self->k = (size_t*)grib_context_malloc(nearest->context, NUM_NEIGHBOURS * sizeof(size_t));
@@ -138,10 +141,21 @@ static int find_global(grib_nearest* nearest, grib_handle* h,
138141
static int is_legacy(grib_handle* h, int* legacy)
139142
{
140143
int err = 0;
141-
long lLegacy = 0;
142-
err = grib_get_long(h, "legacyGaussSubarea", &lLegacy);
144+
long lVal = 0;
145+
*legacy = 0; // false by default
146+
err = grib_get_long(h, "legacyGaussSubarea", &lVal);
143147
if (err) return err;
144-
*legacy = (int)lLegacy;
148+
*legacy = (int)lVal;
149+
return GRIB_SUCCESS;
150+
}
151+
static int is_rotated(grib_handle* h, int* rotated)
152+
{
153+
int err = 0;
154+
long lVal = 0;
155+
*rotated = 0; // false by default
156+
err = grib_get_long(h, "isRotatedGrid", &lVal);
157+
if (err) return err;
158+
*rotated = (int)lVal;
145159
return GRIB_SUCCESS;
146160
}
147161

@@ -152,10 +166,13 @@ static int find(grib_nearest* nearest, grib_handle* h,
152166
{
153167
int err = 0;
154168
grib_nearest_reduced* self = (grib_nearest_reduced*)nearest;
155-
long isRotated = 0;
156-
err = grib_get_long(h, "isRotatedGrid", &isRotated);
157169

158-
if (self->global && !isRotated) {
170+
if (self->rotated == -1 || (flags & GRIB_NEAREST_SAME_GRID) == 0) {
171+
err = is_rotated(h, &(self->rotated));
172+
if (err) return err;
173+
}
174+
175+
if (self->global && self->rotated == 0) {
159176
err = find_global(nearest, h,
160177
inlat, inlon, flags,
161178
outlats, outlons, values,

0 commit comments

Comments
 (0)