grib_get_data: GRIB2 file with missing jDirectionIncrement produces huge values
@@ -159,6 +159,22 @@ static int init(grib_iterator* iter, grib_handle* h,grib_arguments* args)
if((err = grib_get_long_internal(h, s_jPtsConsec, &self->jPointsAreConsecutive))) return err;
if((err = grib_get_long(h, "iteratorDisableUnrotate", &self->disableUnrotate))) return err;
+ /* If the jDirectionIncrement is missing, then we cannot use it (See jDirectionIncrementGiven) */
+ if (grib_is_missing(h, s_jdir, &err) && err == GRIB_SUCCESS) {
+ double lat2;
+ err = grib_get_double_internal(h, "latitudeLastInDegrees", &lat2);
+ if (!err) { /* try to compute jDirectionIncrementInDegrees */
+ const long Nj = self->nam;
+ Assert(Nj>1);
+ if (lat1 > lat2) {
+ jdir=(lat1-lat2)/(Nj-1);
+ } else {
+ jdir=(lat1+360.0-lat2)/(Nj-1);
+ }
+ grib_context_log(h->context, GRIB_LOG_INFO,
+ "%s is missing (See jDirectionIncrementGiven). Using value of %.6f obtained from lat1, lat2 and Nj",s_jdir,jdir);
+ }
+ }
if (jScansPositively) jdir=-jdir;
for( lai = 0; lai < self->nam; lai++ ) {
