29
29
MEMBERS = double lon_first
30
30
MEMBERS = double lon_last
31
31
MEMBERS = int legacy
32
+ MEMBERS = int rotated
32
33
END_CLASS_DEF
33
34
34
35
*/
@@ -69,6 +70,7 @@ typedef struct grib_nearest_reduced{
69
70
double lon_first;
70
71
double lon_last;
71
72
int legacy;
73
+ int rotated;
72
74
} grib_nearest_reduced;
73
75
74
76
extern grib_nearest_class* grib_nearest_class_gen;
@@ -101,6 +103,7 @@ static int init(grib_nearest* nearest, grib_handle* h, grib_arguments* args)
101
103
self->pl = grib_arguments_get_name (h, args, self->cargs ++);
102
104
self->j = (size_t *)grib_context_malloc (h->context , 2 * sizeof (size_t ));
103
105
self->legacy = -1 ;
106
+ self->rotated = -1 ;
104
107
if (!self->j )
105
108
return GRIB_OUT_OF_MEMORY;
106
109
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,
138
141
static int is_legacy (grib_handle* h, int * legacy)
139
142
{
140
143
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);
143
147
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;
145
159
return GRIB_SUCCESS;
146
160
}
147
161
@@ -152,10 +166,13 @@ static int find(grib_nearest* nearest, grib_handle* h,
152
166
{
153
167
int err = 0 ;
154
168
grib_nearest_reduced* self = (grib_nearest_reduced*)nearest;
155
- long isRotated = 0 ;
156
- err = grib_get_long (h, " isRotatedGrid" , &isRotated);
157
169
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 ) {
159
176
err = find_global (nearest, h,
160
177
inlat, inlon, flags,
161
178
outlats, outlons, values,
0 commit comments