static int unpack_long(grib_accessor* a, long* val, size_t *len) { grib_accessor_g1verificationdate* self = (grib_accessor_g1verificationdate*)a; int ret=0; long date = 0; long time = 0; long cdate = 0; long step = 0; long vtime = 0; long vdate = 0; long vd = 0; 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; time /= 100; cdate = (long)grib_date_to_julian (date); vtime = cdate * 24 + time + step; vd = vtime / 24; vdate = grib_julian_to_date (vd); /* printf("\n********\n date %d, time %d, step %d, vdate: %d, cdate %d, vd %d\n********\n", date, time, step, vdate, cdate, vd); */ if(*len < 1) return GRIB_ARRAY_TOO_SMALL; *val = vdate; /* fprintf(stdout,"\n********\n %d cdate %d vd %d\n********\n", vdate, cdate, step); */ return GRIB_SUCCESS; }
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 pack_long(grib_accessor* a, const long* val, size_t *len) { int ret=0; long v = val[0]; grib_accessor_g1date* self = (grib_accessor_g1date*)a; long year = 0; long century = 0; long month = 0; long day = 0; if(*len != 1) return GRIB_WRONG_ARRAY_SIZE; { long d = grib_julian_to_date((long)grib_date_to_julian(v)); if(v != d) { grib_context_log(a->parent->h->context,GRIB_LOG_ERROR,"grib_accessor_g1date: pack_long invalid date %ld, changed to %ld",v,d); return GRIB_ENCODING_ERROR; } } century = v / 1000000; v %= 1000000; year = v / 10000; v %= 10000; month = v / 100; v %= 100; day = v; if(year == 0) year = 100; else century++; if ((ret=grib_set_long_internal(a->parent->h,self->century,century))!=GRIB_SUCCESS) return ret; if ((ret=grib_set_long_internal(a->parent->h,self->day,day))!=GRIB_SUCCESS) return ret; if ((ret=grib_set_long_internal(a->parent->h,self->month,month))!=GRIB_SUCCESS) return ret; if ((ret=grib_set_long_internal(a->parent->h,self->year,year))!=GRIB_SUCCESS) return ret; return GRIB_SUCCESS; }
long codes_date_to_julian(long ddate) { return grib_date_to_julian(ddate); }