static int unpack_long(grib_accessor* a, long* val, size_t *len) { grib_accessor_validity_date* self = (grib_accessor_validity_date*)a; int ret=0; long date = 0; long time = 0; long step = 0; long stepUnits = 0; long hours = 0, minutes=0, step_mins=0, tmp, tmp_hrs; if (self->year) { long year,month,day; if ((ret=grib_get_long_internal(a->parent->h, self->year,&year))!=GRIB_SUCCESS) return ret; if ((ret=grib_get_long_internal(a->parent->h, self->month,&month))!=GRIB_SUCCESS) return ret; if ((ret=grib_get_long_internal(a->parent->h, self->day,&day))!=GRIB_SUCCESS) return ret; *val=year*10000+month*100+day; return GRIB_SUCCESS; } if ((ret=grib_get_long_internal(a->parent->h, self->date,&date))!=GRIB_SUCCESS) return ret; if ((ret=grib_get_long_internal(a->parent->h, self->time,&time))!=GRIB_SUCCESS) return ret; if ((ret=grib_get_long_internal(a->parent->h, self->step,&step))!=GRIB_SUCCESS) return ret; if (self->stepUnits) { if ((ret=grib_get_long_internal(a->parent->h, self->stepUnits,&stepUnits))!=GRIB_SUCCESS) return ret; step_mins = convert_to_minutes(step, stepUnits); } minutes = time % 100; hours = time / 100; tmp = minutes + step_mins; /* add the step to our minutes */ tmp_hrs = tmp/60; /* how many hours and mins is that? */ /* tmp_mins = tmp%60; */ hours += tmp_hrs; /* increment hours */ date = grib_date_to_julian (date); /* does the new 'hours' exceed 24? if so increment julian */ while(hours>=24) { date ++; hours -= 24; } /* GRIB-29: Negative forecast time */ while(hours<0) { date--; hours += 24; } if(*len < 1) return GRIB_ARRAY_TOO_SMALL; *val = grib_julian_to_date(date); return GRIB_SUCCESS; }
static int unpack_long(grib_accessor* a, long* val, size_t *len) { grib_accessor_validity_time* self = (grib_accessor_validity_time*)a; int ret=0; long date = 0; long time = 0; long step = 0; long stepUnits = 0; long hours = 0, minutes=0, step_mins=0, tmp, tmp_hrs, tmp_mins; if (self->hours) { long hours,minutes; if ((ret=grib_get_long_internal(a->parent->h, self->hours,&hours))!=GRIB_SUCCESS) return ret; if ((ret=grib_get_long_internal(a->parent->h, self->minutes,&minutes))!=GRIB_SUCCESS) return ret; *val=hours*100+minutes; return GRIB_SUCCESS; } if ((ret=grib_get_long_internal(a->parent->h, self->date,&date))!=GRIB_SUCCESS) return ret; if ((ret=grib_get_long_internal(a->parent->h, self->time,&time))!=GRIB_SUCCESS) return ret; if ((ret=grib_get_long_internal(a->parent->h, self->step,&step))!=GRIB_SUCCESS) return ret; /* Seconds will always be zero. So convert to minutes */ if (self->stepUnits) { if ((ret=grib_get_long_internal(a->parent->h, self->stepUnits,&stepUnits))!=GRIB_SUCCESS) return ret; step_mins = convert_to_minutes(step, stepUnits); } minutes = time % 100; hours = time / 100; tmp = minutes + step_mins; /* add the step to our minutes */ tmp_hrs = tmp/60; /* how many hours and mins is that? */ tmp_mins = tmp%60; hours += tmp_hrs; /* increment hours */ if (hours>0) { hours = hours % 24; /* wrap round if >= 24 */ } else { /* GRIB-29: Negative forecast time */ while (hours<0) { hours += 24; } } time = hours * 100 + tmp_mins; if(*len < 1) return GRIB_ARRAY_TOO_SMALL; *val = time; return GRIB_SUCCESS; }