ECC-614: problem with datetime extraction

This commit is contained in:
Shahram Najm 2018-01-24 16:19:56 +00:00
parent 929f0685b7
commit f046ff8740
2 changed files with 44 additions and 3 deletions

View File

@ -344,17 +344,32 @@ static int select_datetime(grib_accessor* a)
for (i=0;i<numberOfSubsets;i++) {
long rounded_second=(long)round(second[i]);
if (rounded_second==60) { rounded_second=59;}
if (rounded_second==60) { rounded_second=59;} /* Yikes */
sprintf( datetime_str, "%04ld/%02ld/%02ld %02ld:%02ld:%02ld",year[i],month[i],day[i],hour[i],minute[i], rounded_second );
julianDT = date_to_julian( year[i],month[i],day[i],hour[i],minute[i],rounded_second );
if (julianDT == -1) {
grib_context_log(c,GRIB_LOG_ERROR,"Invalid date/time: %s", datetime_str);
return GRIB_INTERNAL_ERROR;
}
if (julianDT>=julianStart && julianEnd>=julianDT) {
grib_iarray_push(subsets,i+1);
/* printf("++++++++ %ld\n",i+1); */
/* Unfortunately our date_to_julian function does not deal with seconds as a double! */
/* This can cause errors during the rounding to an integer. See ECC-614 */
double julTemp1, julTemp2;
long second_floor = (long)floor(second[i]);
long second_ceil = (long)ceil(second[i]);
if (second_ceil==60) second_ceil=59; /* Yikes */
julTemp1 = date_to_julian( year[i],month[i],day[i],hour[i],minute[i],second_floor );
julTemp2 = date_to_julian( year[i],month[i],day[i],hour[i],minute[i],second_ceil );
// Check floor and ceiling of seconds as well
if (julTemp1 >= julianStart && julTemp1 <= julianEnd &&
julTemp2 >= julianStart && julTemp2 <= julianEnd)
{
grib_iarray_push(subsets,i+1);
}
}
}

View File

@ -190,6 +190,32 @@ if [ $status -eq 0 ]; then
exit 1
fi
#-----------------------------------------------------------
# Test boundary case
#-----------------------------------------------------------
cat > $fRules <<EOF
transient originalNumberOfSubsets=numberOfSubsets;
transient extractDateTimeYearStart =2012;
transient extractDateTimeMonthStart =10;
transient extractDateTimeDayStart =31;
transient extractDateTimeHourStart =0;
transient extractDateTimeMinuteStart=1;
transient extractDateTimeSecondStart=24;
transient extractDateTimeYearEnd =2012;
transient extractDateTimeMonthEnd =10;
transient extractDateTimeDayEnd =31;
transient extractDateTimeHourEnd =0;
transient extractDateTimeMinuteEnd =1;
transient extractDateTimeSecondEnd =31;#25;
set doExtractDateTime=1;
print "extracted [extractedDateTimeNumberOfSubsets] of [originalNumberOfSubsets] subsets";
assert(extractedDateTimeNumberOfSubsets==0);
EOF
inputBufr="amsa_55.bufr"
outputBufr=${label}.${inputBufr}.out
${tools_dir}/codes_bufr_filter -o $outputBufr $fRules $inputBufr
rm -f $outputRef $outputFilt $outputBufr $fLog $fRules