diff --git a/src/grib_accessor_class_bufr_extract_datetime_subsets.c b/src/grib_accessor_class_bufr_extract_datetime_subsets.c index 9b7ef6956..d0aedd7c2 100644 --- a/src/grib_accessor_class_bufr_extract_datetime_subsets.c +++ b/src/grib_accessor_class_bufr_extract_datetime_subsets.c @@ -151,217 +151,212 @@ static int get_native_type(grib_accessor* a) return GRIB_TYPE_LONG; } -static int select_datetime(grib_accessor* a) { - int ret=0; - long compressed=0; - grib_accessor_bufr_extract_datetime_subsets *self =(grib_accessor_bufr_extract_datetime_subsets*)a; - grib_handle* h=grib_handle_of_accessor(a); - grib_context* c=h->context; +static int select_datetime(grib_accessor* a) +{ + int ret=0; + long compressed=0; + grib_accessor_bufr_extract_datetime_subsets *self =(grib_accessor_bufr_extract_datetime_subsets*)a; + grib_handle* h=grib_handle_of_accessor(a); + grib_context* c=h->context; - ret=grib_get_long(h,"compressedData",&compressed); - if (ret) return ret; - - if (compressed) { - size_t n; - struct tm start; - struct tm end; - struct tm datetime; - time_t start_t,end_t,datetime_t; - char start_str[80]={0,},end_str[80]={0,},datetime_str[80]={0,}; - long yearRank,monthRank,dayRank,hourRank,minuteRank,secondRank; - long yearStart,monthStart,dayStart,hourStart,minuteStart,secondStart; - long yearEnd,monthEnd,dayEnd,hourEnd,minuteEnd,secondEnd; - long *year,*month,*hour,*day,*minute; - double *second; - long numberOfSubsets,i; - grib_iarray* subsets; - long *subsets_ar=0; - size_t nsubsets=0; - char yearstr[20]={0,}; - char monthstr[20]={0,}; - char daystr[20]={0,}; - char hourstr[20]={0,}; - char minutestr[20]={0,}; - char secondstr[20]={0,}; - - ret=grib_get_long(h,self->numberOfSubsets,&numberOfSubsets); + ret=grib_get_long(h,"compressedData",&compressed); if (ret) return ret; - subsets=grib_iarray_new(c,numberOfSubsets,10); + if (compressed) { + size_t n; + double julianStart=0, julianEnd=0, julianDT=0; + char start_str[80]={0,},end_str[80]={0,}; + long yearRank,monthRank,dayRank,hourRank,minuteRank,secondRank; + long yearStart,monthStart,dayStart,hourStart,minuteStart,secondStart; + long yearEnd,monthEnd,dayEnd,hourEnd,minuteEnd,secondEnd; + long *year,*month,*hour,*day,*minute; + double *second; + long numberOfSubsets,i; + grib_iarray* subsets; + long *subsets_ar=0; + size_t nsubsets=0; + char yearstr[20]={0,}; + char monthstr[20]={0,}; + char daystr[20]={0,}; + char hourstr[20]={0,}; + char minutestr[20]={0,}; + char secondstr[20]={0,}; - ret=grib_set_long(h,"unpack",1); - if (ret) return ret; + ret=grib_get_long(h,self->numberOfSubsets,&numberOfSubsets); + if (ret) return ret; - ret=grib_get_long(h,"extractDateTimeYearRank",&yearRank); - if (ret) return ret; - sprintf(yearstr,"#%ld#year",yearRank); + subsets=grib_iarray_new(c,numberOfSubsets,10); - ret=grib_get_long(h,"extractDateTimeMonthRank",&monthRank); - if (ret) return ret; - sprintf(monthstr,"#%ld#month",monthRank); + ret=grib_set_long(h,"unpack",1); + if (ret) return ret; - ret=grib_get_long(h,"extractDateTimeDayRank",&dayRank); - if (ret) return ret; - sprintf(daystr,"#%ld#day",dayRank); + ret=grib_get_long(h,"extractDateTimeYearRank",&yearRank); + if (ret) return ret; + sprintf(yearstr,"#%ld#year",yearRank); - ret=grib_get_long(h,"extractDateTimeHourRank",&hourRank); - if (ret) return ret; - sprintf(hourstr,"#%ld#hour",hourRank); + ret=grib_get_long(h,"extractDateTimeMonthRank",&monthRank); + if (ret) return ret; + sprintf(monthstr,"#%ld#month",monthRank); - ret=grib_get_long(h,"extractDateTimeMinuteRank",&minuteRank); - if (ret) return ret; - sprintf(minutestr,"#%ld#minute",minuteRank); + ret=grib_get_long(h,"extractDateTimeDayRank",&dayRank); + if (ret) return ret; + sprintf(daystr,"#%ld#day",dayRank); - ret=grib_get_long(h,"extractDateTimeSecondRank",&secondRank); - if (ret) return ret; - sprintf(secondstr,"#%ld#second",secondRank); + ret=grib_get_long(h,"extractDateTimeHourRank",&hourRank); + if (ret) return ret; + sprintf(hourstr,"#%ld#hour",hourRank); - n=numberOfSubsets; - year=grib_context_malloc_clear(c,sizeof(long)*numberOfSubsets); - ret=grib_get_long_array(h,yearstr,year,&n); - if (ret) return ret; - if (n!=numberOfSubsets) { - if (n==1) { - for (i=1;i=julianStart && julianEnd>=julianDT) { + grib_iarray_push(subsets,i+1); + /* printf("++++++++ %ld\n",i+1); */ + } + } + + nsubsets=grib_iarray_used_size(subsets); + ret=grib_set_long(h,"extractDateTimeNumberOfSubsets",nsubsets); + if (ret) return ret; + + if (nsubsets!=0) { + subsets_ar=grib_iarray_get_array(subsets); + ret=grib_set_long_array(h,self->extractSubsetList,subsets_ar,nsubsets); + if (ret) return ret; + + ret=grib_set_long(h,self->doExtractSubsets,1); + if (ret) return ret; + } + + grib_context_free(c,year); + grib_context_free(c,month); + grib_context_free(c,day); + grib_context_free(c,hour); + grib_context_free(c,minute); + grib_context_free(c,second); + grib_iarray_delete(subsets); + subsets=0; + + } else { + return GRIB_NOT_IMPLEMENTED; } - n=numberOfSubsets; - month=grib_context_malloc_clear(c,sizeof(long)*numberOfSubsets); - ret=grib_get_long_array(h,monthstr,month,&n); - if (ret) return ret; - if (n!=numberOfSubsets) { - if (n==1) { - for (i=1;i=0 && difftime(end_t,datetime_t)>=0) { - grib_iarray_push(subsets,i+1); - /* printf("++++++++ %ld\n",i+1); */ - } - } - - nsubsets=grib_iarray_used_size(subsets); - ret=grib_set_long(h,"extractDateTimeNumberOfSubsets",nsubsets); - if (ret) return ret; - - if (nsubsets!=0) { - subsets_ar=grib_iarray_get_array(subsets); - ret=grib_set_long_array(h,self->extractSubsetList,subsets_ar,nsubsets); - if (ret) return ret; - - ret=grib_set_long(h,self->doExtractSubsets,1); - if (ret) return ret; - } - - grib_context_free(c,year); - grib_context_free(c,month); - grib_context_free(c,day); - grib_context_free(c,hour); - grib_context_free(c,minute); - grib_context_free(c,second); - grib_iarray_delete(subsets); - subsets=0; - - } else { - return GRIB_NOT_IMPLEMENTED; - } - - return ret; + return ret; } static int pack_long(grib_accessor* a, const long* val, size_t *len) diff --git a/src/grib_api_internal.h b/src/grib_api_internal.h index e6ab325c1..43afdafaf 100644 --- a/src/grib_api_internal.h +++ b/src/grib_api_internal.h @@ -59,7 +59,6 @@ extern "C" { #include #include #include -#include /* Microsoft Windows Visual Studio support */ #include "eccodes_windef.h" diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2a6296712..8a4c7d590 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -52,7 +52,7 @@ list( APPEND tests2 bufr_count bufr_get bufr_filter - #bufr_filter_extract_datetime + bufr_filter_extract_datetime bufr_filter_extract_area bufr_json bufr_ls