From 7329cb791717c74e1a84732c325c3e0dd7a7f4af Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Fri, 24 Nov 2017 13:41:27 +0000 Subject: [PATCH] Add more user friendly error messages --- ...accessor_class_bufr_extract_area_subsets.c | 156 +++++++++--------- ...ssor_class_bufr_extract_datetime_subsets.c | 1 + 2 files changed, 80 insertions(+), 77 deletions(-) diff --git a/src/grib_accessor_class_bufr_extract_area_subsets.c b/src/grib_accessor_class_bufr_extract_area_subsets.c index 89502c7f3..eaa8611a6 100644 --- a/src/grib_accessor_class_bufr_extract_area_subsets.c +++ b/src/grib_accessor_class_bufr_extract_area_subsets.c @@ -172,94 +172,96 @@ static int get_native_type(grib_accessor* a) return GRIB_TYPE_LONG; } -static int select_area(grib_accessor* a) { - int ret=0; - long compressed=0; - grib_accessor_bufr_extract_area_subsets *self =(grib_accessor_bufr_extract_area_subsets*)a; - grib_handle* h=grib_handle_of_accessor(a); - grib_context* c=h->context; +static int select_area(grib_accessor* a) +{ + int ret=0; + long compressed=0; + grib_accessor_bufr_extract_area_subsets *self =(grib_accessor_bufr_extract_area_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) { - double *lat=0; - double *lon=0; - size_t n; - double lonWest,lonEast,latNorth,latSouth; - long numberOfSubsets,i,latRank,lonRank; - grib_iarray* subsets; - long *subsets_ar=0; - size_t nsubsets=0; - char latstr[20]={0,}; - char lonstr[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) { + double *lat=0; + double *lon=0; + size_t n; + double lonWest,lonEast,latNorth,latSouth; + long numberOfSubsets,i,latRank,lonRank; + grib_iarray* subsets; + long *subsets_ar=0; + size_t nsubsets=0; + char latstr[20]={0,}; + char lonstr[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,self->extractAreaLongitudeRank,&lonRank); - if (ret) return ret; - sprintf(lonstr,"#%ld#longitude",lonRank); - ret=grib_get_long(h,self->extractAreaLatitudeRank,&latRank); - if (ret) return ret; - sprintf(latstr,"#%ld#latitude",latRank); + subsets=grib_iarray_new(c,numberOfSubsets,10); - n=numberOfSubsets; - lat=(double*)grib_context_malloc_clear(c,sizeof(double)*numberOfSubsets); - ret=grib_get_double_array(h,latstr,lat,&n); - if (ret) return ret; - if (n!=numberOfSubsets) return GRIB_INTERNAL_ERROR; + ret=grib_set_long(h,"unpack",1); + if (ret) return ret; - lon=(double*)grib_context_malloc_clear(c,sizeof(double)*numberOfSubsets); - ret=grib_get_double_array(h,lonstr,lon,&n); - if (ret) return ret; - if (n!=numberOfSubsets) return GRIB_INTERNAL_ERROR; + ret=grib_get_long(h,self->extractAreaLongitudeRank,&lonRank); + if (ret) return ret; + sprintf(lonstr,"#%ld#longitude",lonRank); + ret=grib_get_long(h,self->extractAreaLatitudeRank,&latRank); + if (ret) return ret; + sprintf(latstr,"#%ld#latitude",latRank); - ret=grib_get_double(h,self->extractAreaWestLongitude,&lonWest); - if (ret) return ret; - ret=grib_get_double(h,self->extractAreaEastLongitude,&lonEast); - if (ret) return ret; - ret=grib_get_double(h,self->extractAreaNorthLatitude,&latNorth); - if (ret) return ret; - ret=grib_get_double(h,self->extractAreaSouthLatitude,&latSouth); - if (ret) return ret; + n=numberOfSubsets; + lat=(double*)grib_context_malloc_clear(c,sizeof(double)*numberOfSubsets); + ret=grib_get_double_array(h,latstr,lat,&n); + if (ret) return ret; + if (n!=numberOfSubsets) return GRIB_INTERNAL_ERROR; - for (i=0;i=latSouth && lat[i]<=latNorth && lon[i]>=lonWest && lon[i]<=lonEast) { - grib_iarray_push(subsets,i+1); - /* printf("++++++++ %ld\n",i+1); */ - } + lon=(double*)grib_context_malloc_clear(c,sizeof(double)*numberOfSubsets); + ret=grib_get_double_array(h,lonstr,lon,&n); + if (ret) return ret; + if (n!=numberOfSubsets) return GRIB_INTERNAL_ERROR; + + ret=grib_get_double(h,self->extractAreaWestLongitude,&lonWest); + if (ret) return ret; + ret=grib_get_double(h,self->extractAreaEastLongitude,&lonEast); + if (ret) return ret; + ret=grib_get_double(h,self->extractAreaNorthLatitude,&latNorth); + if (ret) return ret; + ret=grib_get_double(h,self->extractAreaSouthLatitude,&latSouth); + if (ret) return ret; + + for (i=0;i=latSouth && lat[i]<=latNorth && lon[i]>=lonWest && lon[i]<=lonEast) { + grib_iarray_push(subsets,i+1); + /* printf("++++++++ %ld\n",i+1); */ + } + } + + nsubsets=grib_iarray_used_size(subsets); + ret=grib_set_long(h,self->extractedAreaNumberOfSubsets,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,lat); + grib_context_free(c,lon); + grib_iarray_delete(subsets); + subsets=0; + + } else { + grib_context_log(c, GRIB_LOG_ERROR, "Area extraction not implemented for uncompressed BUFR messages"); + return GRIB_NOT_IMPLEMENTED; } - nsubsets=grib_iarray_used_size(subsets); - ret=grib_set_long(h,self->extractedAreaNumberOfSubsets,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,lat); - grib_context_free(c,lon); - 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_accessor_class_bufr_extract_datetime_subsets.c b/src/grib_accessor_class_bufr_extract_datetime_subsets.c index b38ae1aac..4e16b5630 100644 --- a/src/grib_accessor_class_bufr_extract_datetime_subsets.c +++ b/src/grib_accessor_class_bufr_extract_datetime_subsets.c @@ -386,6 +386,7 @@ static int select_datetime(grib_accessor* a) subsets=0; } else { + grib_context_log(c, GRIB_LOG_ERROR, "Time interval extraction not implemented for uncompressed BUFR messages"); return GRIB_NOT_IMPLEMENTED; }