From 05caaefa2823cbe059dcbb553bb9bc339d3e3d27 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Wed, 28 Sep 2016 13:27:20 +0100 Subject: [PATCH 1/5] Rename the CMake target to avoid clashes inside bundles --- python/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 202aab310..f8a0079af 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -35,7 +35,7 @@ if( HAVE_PYTHON ) add_custom_command( OUTPUT ${_gribapi_swig} COMMAND ${PYTHON_EXECUTABLE} setup.py build_ext --inplace --rpath ${CMAKE_BINARY_DIR}/lib DEPENDS grib_interface.h grib_interface.c swig_wrap_numpy.c setup.py.in eccodes ) - add_custom_target(build_swig_wrapper ALL DEPENDS ${_gribapi_swig}) + add_custom_target(eccodes_build_swig_wrapper ALL DEPENDS ${_gribapi_swig}) #ecbuild_add_library(TARGET _gribapi_swig # TYPE SHARED From 197edb7744e01c2c7bb103b3d89b4b4d69ad67a8 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Thu, 29 Sep 2016 14:57:40 +0100 Subject: [PATCH 2/5] Fix version number --- VERSION.cmake | 2 +- version.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/VERSION.cmake b/VERSION.cmake index 9cd120fbf..5d3bef49e 100644 --- a/VERSION.cmake +++ b/VERSION.cmake @@ -1 +1 @@ -set( ${PROJECT_NAME}_VERSION_STR "2.1.0" ) +set( ${PROJECT_NAME}_VERSION_STR "2.0.0" ) diff --git a/version.sh b/version.sh index 4c24019a3..8f2b9bfcd 100644 --- a/version.sh +++ b/version.sh @@ -14,7 +14,7 @@ PACKAGE_NAME='eccodes' # Package version ECCODES_MAJOR_VERSION=2 -ECCODES_MINOR_VERSION=1 +ECCODES_MINOR_VERSION=0 ECCODES_REVISION_VERSION=0 ECCODES_CURRENT=1 From e1b06b641c0e7be85761bb949a073a8c34bcf6f3 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Wed, 5 Oct 2016 11:50:26 +0100 Subject: [PATCH 3/5] ECC-348: environment variable ECCODES_BUFRDC_MODE_ON --- src/action.c | 14 +-- src/grib_accessor_class_bufr_data_array.c | 120 ++++++++++++++-------- src/grib_api_internal.h | 3 +- src/grib_context.c | 60 ++++++----- 4 files changed, 120 insertions(+), 77 deletions(-) diff --git a/src/action.c b/src/action.c index 38dcd16f9..c59fee693 100644 --- a/src/action.c +++ b/src/action.c @@ -114,13 +114,13 @@ int grib_create_accessor(grib_section* p, grib_action* a, grib_loader* h) while(c) { if(c->create_accessor) { - int ret; - GRIB_MUTEX_INIT_ONCE(&once,&init_mutex); - GRIB_MUTEX_LOCK(&mutex1); + int ret; + GRIB_MUTEX_INIT_ONCE(&once,&init_mutex); + GRIB_MUTEX_LOCK(&mutex1); ret=c->create_accessor(p, a, h); - GRIB_MUTEX_UNLOCK(&mutex1); + GRIB_MUTEX_UNLOCK(&mutex1); return ret; - } + } c = c->super ? *(c->super) : NULL; } fprintf(stderr,"Cannot create accessor %s %s\n",a->name,a->cclass->name); @@ -132,8 +132,8 @@ int grib_action_notify_change( grib_action* a, grib_accessor *observer, grib_acc { grib_action_class *c = a->cclass; - GRIB_MUTEX_INIT_ONCE(&once,&init_mutex) - GRIB_MUTEX_LOCK(&mutex1) + GRIB_MUTEX_INIT_ONCE(&once,&init_mutex); + GRIB_MUTEX_LOCK(&mutex1); init(c); while(c) diff --git a/src/grib_accessor_class_bufr_data_array.c b/src/grib_accessor_class_bufr_data_array.c index a555cc4c2..e80d1b03c 100644 --- a/src/grib_accessor_class_bufr_data_array.c +++ b/src/grib_accessor_class_bufr_data_array.c @@ -222,6 +222,13 @@ static void init_class(grib_accessor_class* c) #define round(a) ( (a) >=0 ? ((a)+0.5) : ((a)-0.5) ) #endif +/* Set the error code, if it is bad and we should fail (default case), return */ +/* variable 'err' is assumed to be pointer to int */ +/* If BUFRDC mode is enabled, then we tolerate problems like wrong data section length */ +#define CHECK_END_DATA_RETURN(ctx,b,size) {*err=check_end_data(ctx,b,size); if (*err!=0 && ctx->bufrdc_mode==0) return; } +#define CHECK_END_DATA_RETURN_0(ctx,b,size) {*err=check_end_data(ctx,b,size); if (*err!=0 && ctx->bufrdc_mode==0) return 0; } +#define CHECK_END_DATA_RETURN_ERR(ctx,b,size) {*err=check_end_data(ctx,b,size); if (*err!=0 && ctx->bufrdc_mode==0) return *err; } + static int process_elements(grib_accessor* a,int flag,long onlySubset,long startSubset,long endSubset); typedef int (*codec_element_proc) (grib_context* c,grib_accessor_bufr_data_array* self,int subsetIndex, grib_buffer* b,unsigned char* data,long *pos,int i,bufr_descriptor* descriptor,long elementIndex,grib_darray* dval,grib_sarray* sval); @@ -418,31 +425,37 @@ static void decode_string_array(grib_context* c,unsigned char* data,long* pos, b grib_sarray* sa=grib_sarray_new(c,self->numberOfSubsets,10); modifiedWidth= bd->width; - /* modifiedReference= bd->reference; */ - /*modifiedFactor= bd->factor;*/ sval=(char*)grib_context_malloc_clear(c,modifiedWidth/8+1); - *err=check_end_data(c,self,modifiedWidth); - if (*err) return ; + CHECK_END_DATA_RETURN(c,self,modifiedWidth); + if (*err) { + grib_sarray_push(c,sa,sval); + grib_vsarray_push(c,self->stringValues,sa); + return; + } grib_decode_string(data,pos,modifiedWidth/8,sval); - /* clean_string(sval,modifiedWidth/8); */ - *err=check_end_data(c,self,6); - if (*err) return ; + CHECK_END_DATA_RETURN(c,self,6); + if (*err) { + grib_sarray_push(c,sa,sval); + grib_vsarray_push(c,self->stringValues,sa); + return; + } width=grib_decode_unsigned_long(data,pos,6); if (width) { - grib_context_free(c,sval); - *err=check_end_data(c,self,width*8*self->numberOfSubsets); - if (*err) return ; - for (j=0;jnumberOfSubsets;j++) { - sval=(char*)grib_context_malloc_clear(c,width+1); - grib_decode_string(data,pos,width,sval); - /* clean_string(sval,width); */ - grib_sarray_push(c,sa,sval); - } - } else { - /* for (j=0;jnumberOfSubsets;j++) { */ + CHECK_END_DATA_RETURN(c,self,width*8*self->numberOfSubsets); + if (*err) { grib_sarray_push(c,sa,sval); - /* } */ + grib_vsarray_push(c,self->stringValues,sa); + return; + } + grib_context_free(c,sval); + for (j=0;jnumberOfSubsets;j++) { + sval=(char*)grib_context_malloc_clear(c,width+1); + grib_decode_string(data,pos,width,sval); + grib_sarray_push(c,sa,sval); + } + } else { + grib_sarray_push(c,sa,sval); } grib_vsarray_push(c,self->stringValues,sa); } @@ -463,16 +476,32 @@ static grib_darray* decode_double_array(grib_context* c,unsigned char* data,long modifiedFactor= bd->factor; modifiedWidth= bd->width; - *err=check_end_data(c,self,modifiedWidth+6); - if (*err) return NULL; + CHECK_END_DATA_RETURN_0(c,self,modifiedWidth+6); + if (*err) { + dval=GRIB_MISSING_DOUBLE; + lval=0; + grib_context_log(c, GRIB_LOG_DEBUG," modifiedWidth=%ld lval=%ld dval=%g", modifiedWidth,lval,dval); + ret=grib_darray_new(c,100,100); + grib_darray_push(c,ret,dval); + *err=0; + return ret; + } lval=grib_decode_unsigned_long(data,pos,modifiedWidth); localReference=(long)lval+modifiedReference; localWidth=grib_decode_unsigned_long(data,pos,6); grib_context_log(c, GRIB_LOG_DEBUG,"BUFR data decoding: \tlocalWidth=%ld",localWidth); ret=grib_darray_new(c,100,100); if (localWidth) { - *err=check_end_data(c,self,localWidth*self->numberOfSubsets); - if (*err) return NULL; + CHECK_END_DATA_RETURN_0(c,self,localWidth*self->numberOfSubsets); + if (*err) { + dval=GRIB_MISSING_DOUBLE; + lval=0; + grib_context_log(c, GRIB_LOG_DEBUG," modifiedWidth=%ld lval=%ld dval=%g", modifiedWidth,lval,dval); + ret=grib_darray_new(c,100,100); + grib_darray_push(c,ret,dval); + *err=0; + return ret; + } for (j=0;jnumberOfSubsets;j++) { lval=grib_decode_unsigned_long(data,pos,localWidth); if (grib_is_all_bits_one(lval,localWidth) && canBeMissing) { @@ -725,9 +754,9 @@ static char* decode_string_value(grib_context* c,unsigned char* data,long* pos, len= bd->width / 8; - *err=check_end_data(c,self,bd->width); - if (*err) return NULL; + CHECK_END_DATA_RETURN_0(c,self,bd->width); sval=(char*)grib_context_malloc_clear(c,len+1); + if (*err) {*err=0; return sval;} grib_decode_string(data,pos,len,sval); /* clean_string(sval,len); */ @@ -750,8 +779,9 @@ static double decode_double_value(grib_context* c,unsigned char* data,long* pos, modifiedFactor= bd->factor; modifiedWidth= bd->width; - *err=check_end_data(c,self,modifiedWidth); - if (*err) return dval; + CHECK_END_DATA_RETURN_0(c,self,modifiedWidth); + if (*err) {*err=0; return GRIB_MISSING_DOUBLE;} + lval=grib_decode_unsigned_long(data,pos,modifiedWidth); if (grib_is_all_bits_one(lval,modifiedWidth) && canBeMissing) { dval=GRIB_MISSING_DOUBLE; @@ -820,32 +850,40 @@ static int decode_element(grib_context* c,grib_accessor_bufr_data_array* self,in static int decode_replication(grib_context* c,grib_accessor_bufr_data_array* self,int subsetIndex, grib_buffer* buff,unsigned char* data,long *pos,int i,long elementIndex,grib_darray* dval,long* numberOfRepetitions) { - int err=0; + int ret=0; + int *err; int localReference,width; bufr_descriptor** descriptors=0; + err=&ret; descriptors=self->expanded->v; grib_context_log(c, GRIB_LOG_DEBUG,"BUFR data decoding: -%ld- \tcode=%6.6ld width=%ld ", i,self->expanded->v[i]->code,self->expanded->v[i]->width); if (self->compressedData) { grib_context_log(c, GRIB_LOG_DEBUG,"BUFR data decoding: \tdelayed replication localReference width=%ld", descriptors[i]->width); - err=check_end_data(c,self,descriptors[i]->width+6); - if (err) return err; - localReference=grib_decode_unsigned_long(data,pos,descriptors[i]->width)+descriptors[i]->reference; - grib_context_log(c, GRIB_LOG_DEBUG,"BUFR data decoding: \tdelayed replication localWidth width=6"); - width=grib_decode_unsigned_long(data,pos,6); - if (width) { + CHECK_END_DATA_RETURN_ERR(c,self,descriptors[i]->width+6); + if (*err) { + *numberOfRepetitions=0; + } else { + localReference=grib_decode_unsigned_long(data,pos,descriptors[i]->width)+descriptors[i]->reference; + grib_context_log(c, GRIB_LOG_DEBUG,"BUFR data decoding: \tdelayed replication localWidth width=6"); + width=grib_decode_unsigned_long(data,pos,6); + if (width) { /* delayed replication number is not constant. NOT IMPLEMENTED */ return GRIB_NOT_IMPLEMENTED; - } else { + } else { *numberOfRepetitions=localReference*descriptors[i]->factor; grib_context_log(c, GRIB_LOG_DEBUG,"BUFR data decoding: \tdelayed replication value=%ld",*numberOfRepetitions); + } } } else { - err=check_end_data(c,self,descriptors[i]->width); - if (err) return err; - *numberOfRepetitions=grib_decode_unsigned_long(data,pos,descriptors[i]->width)+ - descriptors[i]->reference*descriptors[i]->factor; - grib_context_log(c, GRIB_LOG_DEBUG,"BUFR data decoding: \tdelayed replication value=%ld",*numberOfRepetitions); + CHECK_END_DATA_RETURN_ERR(c,self,descriptors[i]->width); + if (*err) { + *numberOfRepetitions=0; + } else { + *numberOfRepetitions=grib_decode_unsigned_long(data,pos,descriptors[i]->width)+ + descriptors[i]->reference*descriptors[i]->factor; + grib_context_log(c, GRIB_LOG_DEBUG,"BUFR data decoding: \tdelayed replication value=%ld",*numberOfRepetitions); + } } if (self->compressedData) { dval=grib_darray_new(c,1,100); @@ -854,7 +892,7 @@ static int decode_replication(grib_context* c,grib_accessor_bufr_data_array* sel } else { grib_darray_push(c,dval,(double)(*numberOfRepetitions)); } - return err; + return ret; } static int encode_new_bitmap(grib_context* c,grib_buffer* buff,long *pos,int idx,grib_accessor_bufr_data_array* self) diff --git a/src/grib_api_internal.h b/src/grib_api_internal.h index 7d7115d2f..d9d986122 100644 --- a/src/grib_api_internal.h +++ b/src/grib_api_internal.h @@ -1046,9 +1046,10 @@ struct grib_context int hash_array_count; grib_hash_array_value* hash_array[MAX_NUM_HASH_ARRAY]; grib_trie* def_files; - grib_string_list* blacklist; + grib_string_list* blacklist; int ieee_packing; int unpack; + int bufrdc_mode; FILE* log_stream; grib_trie* classes; grib_trie* lists; diff --git a/src/grib_context.c b/src/grib_context.c index 3059e18c5..0015b8d9c 100644 --- a/src/grib_context.c +++ b/src/grib_context.c @@ -314,11 +314,11 @@ static grib_context default_grib_context = { &default_log, /* logging_procedure */ &default_print, /* print procedure */ - 0, /* code tables */ - 0, /* smart tables */ - 0, /* files */ - 0, /* multigrib support on */ - 0, /* multigrib support */ + 0, /* grib_codetable* */ + 0, /* grib_smart_table* */ + 0, /* char* outfilename */ + 0, /* int multi_support_on */ + 0, /* grib_multi_support* multi_support*/ 0, /* grib_definition_files_dir */ 0, /* handle_file_count */ 0, /* handle_total_count */ @@ -327,23 +327,24 @@ static grib_context default_grib_context = { 0, /* gts_header_on */ 0, /* gribex_mode_on */ 0, /* large_constant_fields */ - 0, /* keys (grib_trie*) */ + 0, /* grib_itrie* keys */ 0, /* keys_count */ - 0, /* concepts_index */ + 0, /* grib_itrie* concepts_index */ 0, /* concepts_count */ {0,}, /* concepts */ - 0, /* hash_array_index */ - 0, /* hash_array_count */ - {0,}, /* hash_array */ + 0, /* hash_array_index */ + 0, /* hash_array_count */ + {0,}, /* hash_array */ 0, /* def_files */ - 0, /* ieee_packing */ - 0, /* unpack */ 0, /* blacklist */ + 0, /* ieee_packing */ + 0, /* unpack */ + 0, /* bufrdc_mode */ 0, /* log_stream */ - 0, /* classes */ - 0 /* lists */ + 0, /* classes */ + 0 /* lists */ #if GRIB_PTHREADS - ,PTHREAD_MUTEX_INITIALIZER /* mutex */ + ,PTHREAD_MUTEX_INITIALIZER /* mutex */ #endif }; @@ -361,20 +362,22 @@ grib_context* grib_context_get_default() if(!default_grib_context.inited) { - const char * write_on_fail = NULL; - const char * large_constant_fields = NULL; - const char * no_abort = NULL; - const char * debug = NULL; - const char *gribex=NULL; - const char *ieee_packing=NULL; - const char *io_buffer_size=NULL; - const char *log_stream=NULL; - const char *no_big_group_split=NULL; - const char *no_spd=NULL; - const char *keep_matrix=NULL; - const char *nounpack=NULL; + const char* write_on_fail = NULL; + const char* large_constant_fields = NULL; + const char* no_abort = NULL; + const char* debug = NULL; + const char* gribex = NULL; + const char* ieee_packing = NULL; + const char* io_buffer_size = NULL; + const char* log_stream = NULL; + const char* no_big_group_split = NULL; + const char* no_spd = NULL; + const char* keep_matrix = NULL; + const char* bufrdc_mode = NULL; + const char* nounpack = NULL; write_on_fail = codes_getenv("ECCODES_GRIB_WRITE_ON_FAIL"); + bufrdc_mode = codes_getenv("ECCODES_BUFRDC_MODE_ON"); large_constant_fields = codes_getenv("ECCODES_GRIB_LARGE_CONSTANT_FIELDS"); no_abort = codes_getenv("ECCODES_NO_ABORT"); debug = codes_getenv("ECCODES_DEBUG"); @@ -399,7 +402,7 @@ grib_context* grib_context_get_default() default_grib_context.no_big_group_split = no_big_group_split ? atoi(no_big_group_split) : 0; default_grib_context.no_spd = no_spd ? atoi(no_spd) : 0; default_grib_context.keep_matrix = keep_matrix ? atoi(keep_matrix) : 1; - default_grib_context.unpack = nounpack ? 0 : 1; + default_grib_context.unpack = nounpack ? 0 : 1; default_grib_context.write_on_fail = write_on_fail ? atoi(write_on_fail) : 0; default_grib_context.no_abort = no_abort ? atoi(no_abort) : 0; default_grib_context.debug = debug ? atoi(debug) : 0; @@ -469,6 +472,7 @@ grib_context* grib_context_get_default() default_grib_context.def_files=grib_trie_new(&(default_grib_context)); default_grib_context.lists=grib_trie_new(&(default_grib_context)); default_grib_context.classes=grib_trie_new(&(default_grib_context)); + default_grib_context.bufrdc_mode = bufrdc_mode ? atoi(bufrdc_mode) : 0; } GRIB_MUTEX_UNLOCK(&mutex_c); From 98c3708890ff68c1e24d67f28b0632baf55a148e Mon Sep 17 00:00:00 2001 From: Enrico Fucile Date: Wed, 5 Oct 2016 16:21:46 +0100 Subject: [PATCH 4/5] ECC-354 --- definitions/bufr/boot.def | 8 ++++++-- src/CMakeLists.txt | 1 + src/Makefile.am | 1 + src/grib_accessor_class.h | 1 + src/grib_accessor_factory.h | 1 + src/grib_accessor_factory_hash_list | 1 + src/grib_dumper_class.h | 2 +- src/grib_dumper_class_bufr_decode_C.c | 6 +++--- src/grib_dumper_class_bufr_decode_filter.c | 4 ++-- src/grib_dumper_class_bufr_decode_fortran.c | 6 +++--- src/grib_dumper_class_bufr_decode_python.c | 4 ++-- src/grib_dumper_class_bufr_encode_C.c | 6 +++--- src/grib_dumper_class_bufr_encode_filter.c | 4 ++-- src/grib_dumper_class_bufr_encode_fortran.c | 6 +++--- src/grib_dumper_class_bufr_encode_python.c | 4 ++-- src/grib_dumper_class_grib_encode_C.c | 4 ++-- src/grib_dumper_factory.h | 16 +++++++++++++++- 17 files changed, 49 insertions(+), 26 deletions(-) diff --git a/definitions/bufr/boot.def b/definitions/bufr/boot.def index 810b855d8..96b3b4e43 100644 --- a/definitions/bufr/boot.def +++ b/definitions/bufr/boot.def @@ -24,7 +24,7 @@ transient extractSubsetList={-1} : hidden; transient extractSubsetIntervalStart=-1 : hidden; transient extractSubsetIntervalEnd=-1 : hidden; -meta doExtractSubsets bufr_extract_subsets(numericValues,pack,numberOfSubsets,extractSubset,extractSubsetIntervalStart,extractSubsetIntervalEnd,extractSubsetList) : hidden; +meta doExtractSubsets bufr_extract_subsets(numericValues,pack,numberOfSubsets,extractSubset,extractSubsetIntervalStart,extractSubsetIntervalEnd,extractSubsetList)=0 : hidden; transient extractAreaWestLongitude=1.1 : hidden; transient extractAreaEastLongitude=1.1 : hidden; @@ -61,7 +61,11 @@ transient extractDateTimeMinuteRank=1 : hidden; transient extractDateTimeSecondRank=1 : hidden; transient extractedDateTimeNumberOfSubsets=0 : hidden; -meta doExtractDateTime bufr_extract_datetime_subsets(doExtractSubsets,numberOfSubsets,extractSubsetList) : hidden; +meta doExtractDateTime bufr_extract_datetime_subsets(doExtractSubsets,numberOfSubsets,extractSubsetList)=0 : hidden; + +transient simpleThinningStart=1 : hidden; +transient simpleThinningMissingRadius=0 : hidden; +meta simpleThinningSkip bufr_simple_thinning(doExtractSubsets,numberOfSubsets,extractSubsetList,simpleThinningStart,simpleThinningMissingRadius)=0 : hidden; template boot_edition "bufr/boot_edition_[ed:l].def"; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c3bb834f1..a60ac9e64 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -247,6 +247,7 @@ list( APPEND grib_api_srcs grib_accessor_class_unsigned.c grib_accessor_class_unsigned_bits.c grib_accessor_class_raw.c + grib_accessor_class_bufr_simple_thinning.c grib_accessor_class_bufr_extract_subsets.c grib_accessor_class_bufr_extract_area_subsets.c grib_accessor_class_bufr_extract_datetime_subsets.c diff --git a/src/Makefile.am b/src/Makefile.am index eb649b168..0244a061e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -265,6 +265,7 @@ libeccodes_la_prototypes= \ grib_accessor_class_unsigned_bits.c \ grib_accessor_class_raw.c \ grib_accessor_class_bufr_extract_subsets.c \ + grib_accessor_class_bufr_simple_thinning.c \ grib_accessor_class_spd.c \ grib_accessor_class_sum.c \ grib_accessor_class_to_integer.c \ diff --git a/src/grib_accessor_class.h b/src/grib_accessor_class.h index 21bc0b2b6..101a58a8b 100644 --- a/src/grib_accessor_class.h +++ b/src/grib_accessor_class.h @@ -21,6 +21,7 @@ extern grib_accessor_class* grib_accessor_class_bufr_extract_datetime_subsets; extern grib_accessor_class* grib_accessor_class_bufr_extract_subsets; extern grib_accessor_class* grib_accessor_class_bufr_group; extern grib_accessor_class* grib_accessor_class_bufr_has_delayed_replication; +extern grib_accessor_class* grib_accessor_class_bufr_simple_thinning; extern grib_accessor_class* grib_accessor_class_bufr_string_values; extern grib_accessor_class* grib_accessor_class_bufrdc_expanded_descriptors; extern grib_accessor_class* grib_accessor_class_bytes; diff --git a/src/grib_accessor_factory.h b/src/grib_accessor_factory.h index fe7e87ec0..e53f07cdd 100644 --- a/src/grib_accessor_factory.h +++ b/src/grib_accessor_factory.h @@ -21,6 +21,7 @@ { "bufr_extract_subsets", &grib_accessor_class_bufr_extract_subsets, }, { "bufr_group", &grib_accessor_class_bufr_group, }, { "bufr_has_delayed_replication", &grib_accessor_class_bufr_has_delayed_replication, }, +{ "bufr_simple_thinning", &grib_accessor_class_bufr_simple_thinning, }, { "bufr_string_values", &grib_accessor_class_bufr_string_values, }, { "bufrdc_expanded_descriptors", &grib_accessor_class_bufrdc_expanded_descriptors, }, { "bytes", &grib_accessor_class_bytes, }, diff --git a/src/grib_accessor_factory_hash_list b/src/grib_accessor_factory_hash_list index 832893ea8..721417514 100644 --- a/src/grib_accessor_factory_hash_list +++ b/src/grib_accessor_factory_hash_list @@ -23,6 +23,7 @@ bufr_extract_subsets, &grib_accessor_class_bufr_extract_subsets bufr_group, &grib_accessor_class_bufr_group bufr_group_number, &grib_accessor_class_bufr_group_number bufr_has_delayed_replication, &grib_accessor_class_bufr_has_delayed_replication +bufr_simple_thinning, &grib_accessor_class_bufr_simple_thinning bufr_string_values, &grib_accessor_class_bufr_string_values bufr_subset_number, &grib_accessor_class_bufr_subset_number bufr_uncompressed_data, &grib_accessor_class_bufr_uncompressed_data diff --git a/src/grib_dumper_class.h b/src/grib_dumper_class.h index b4094feb9..531d72a73 100644 --- a/src/grib_dumper_class.h +++ b/src/grib_dumper_class.h @@ -7,11 +7,11 @@ extern grib_dumper_class* grib_dumper_class_bufr_encode_C; extern grib_dumper_class* grib_dumper_class_bufr_encode_filter; extern grib_dumper_class* grib_dumper_class_bufr_encode_fortran; extern grib_dumper_class* grib_dumper_class_bufr_encode_python; -extern grib_dumper_class* grib_dumper_class_grib_encode_C; extern grib_dumper_class* grib_dumper_class_compare; extern grib_dumper_class* grib_dumper_class_debug; extern grib_dumper_class* grib_dumper_class_default; extern grib_dumper_class* grib_dumper_class_file; +extern grib_dumper_class* grib_dumper_class_grib_encode_C; extern grib_dumper_class* grib_dumper_class_json; extern grib_dumper_class* grib_dumper_class_keys; extern grib_dumper_class* grib_dumper_class_serialize; diff --git a/src/grib_dumper_class_bufr_decode_C.c b/src/grib_dumper_class_bufr_decode_C.c index 15a64067e..6b0c22549 100644 --- a/src/grib_dumper_class_bufr_decode_C.c +++ b/src/grib_dumper_class_bufr_decode_C.c @@ -59,7 +59,7 @@ static void footer (grib_dumper*,grib_handle*); typedef struct grib_dumper_bufr_decode_C { grib_dumper dumper; -/* Members defined in C */ +/* Members defined in bufr_decode_C */ long section_offset; long empty; long end; @@ -71,8 +71,8 @@ typedef struct grib_dumper_bufr_decode_C { static grib_dumper_class _grib_dumper_class_bufr_decode_C = { 0, /* super */ - "bufr_decode_C", /* name */ - sizeof(grib_dumper_bufr_decode_C), /* size */ + "bufr_decode_C", /* name */ + sizeof(grib_dumper_bufr_decode_C), /* size */ 0, /* inited */ &init_class, /* init_class */ &init, /* init */ diff --git a/src/grib_dumper_class_bufr_decode_filter.c b/src/grib_dumper_class_bufr_decode_filter.c index 036066984..7bbcb211b 100644 --- a/src/grib_dumper_class_bufr_decode_filter.c +++ b/src/grib_dumper_class_bufr_decode_filter.c @@ -57,7 +57,7 @@ static void dump_section (grib_dumper* d, grib_accessor* a,grib_block_of_acce typedef struct grib_dumper_bufr_decode_filter { grib_dumper dumper; -/* Members defined in filter */ +/* Members defined in bufr_decode_filter */ long section_offset; long begin; long empty; @@ -70,7 +70,7 @@ typedef struct grib_dumper_bufr_decode_filter { static grib_dumper_class _grib_dumper_class_bufr_decode_filter = { 0, /* super */ - "bufr_decode_filter", /* name */ + "bufr_decode_filter", /* name */ sizeof(grib_dumper_bufr_decode_filter), /* size */ 0, /* inited */ &init_class, /* init_class */ diff --git a/src/grib_dumper_class_bufr_decode_fortran.c b/src/grib_dumper_class_bufr_decode_fortran.c index 0cd4e3448..f80885da5 100644 --- a/src/grib_dumper_class_bufr_decode_fortran.c +++ b/src/grib_dumper_class_bufr_decode_fortran.c @@ -59,7 +59,7 @@ static void footer (grib_dumper*,grib_handle*); typedef struct grib_dumper_bufr_decode_fortran { grib_dumper dumper; -/* Members defined in fortran */ +/* Members defined in bufr_decode_fortran */ long section_offset; long empty; long end; @@ -71,8 +71,8 @@ typedef struct grib_dumper_bufr_decode_fortran { static grib_dumper_class _grib_dumper_class_bufr_decode_fortran = { 0, /* super */ - "bufr_decode_fortran", /* name */ - sizeof(grib_dumper_bufr_decode_fortran), /* size */ + "bufr_decode_fortran", /* name */ + sizeof(grib_dumper_bufr_decode_fortran), /* size */ 0, /* inited */ &init_class, /* init_class */ &init, /* init */ diff --git a/src/grib_dumper_class_bufr_decode_python.c b/src/grib_dumper_class_bufr_decode_python.c index c93101433..b9cd75059 100644 --- a/src/grib_dumper_class_bufr_decode_python.c +++ b/src/grib_dumper_class_bufr_decode_python.c @@ -59,7 +59,7 @@ static void footer (grib_dumper*,grib_handle*); typedef struct grib_dumper_bufr_decode_python { grib_dumper dumper; -/* Members defined in python */ +/* Members defined in bufr_decode_python */ long section_offset; long empty; long end; @@ -71,7 +71,7 @@ typedef struct grib_dumper_bufr_decode_python { static grib_dumper_class _grib_dumper_class_bufr_decode_python = { 0, /* super */ - "bufr_decode_python", /* name */ + "bufr_decode_python", /* name */ sizeof(grib_dumper_bufr_decode_python), /* size */ 0, /* inited */ &init_class, /* init_class */ diff --git a/src/grib_dumper_class_bufr_encode_C.c b/src/grib_dumper_class_bufr_encode_C.c index 3cd6f224f..9a8ce8d09 100644 --- a/src/grib_dumper_class_bufr_encode_C.c +++ b/src/grib_dumper_class_bufr_encode_C.c @@ -59,7 +59,7 @@ static void footer (grib_dumper*,grib_handle*); typedef struct grib_dumper_bufr_encode_C { grib_dumper dumper; -/* Members defined in C */ +/* Members defined in bufr_encode_C */ long section_offset; long empty; long end; @@ -71,8 +71,8 @@ typedef struct grib_dumper_bufr_encode_C { static grib_dumper_class _grib_dumper_class_bufr_encode_C = { 0, /* super */ - "bufr_encode_C", /* name */ - sizeof(grib_dumper_bufr_encode_C), /* size */ + "bufr_encode_C", /* name */ + sizeof(grib_dumper_bufr_encode_C), /* size */ 0, /* inited */ &init_class, /* init_class */ &init, /* init */ diff --git a/src/grib_dumper_class_bufr_encode_filter.c b/src/grib_dumper_class_bufr_encode_filter.c index 47c0a8d5c..313611578 100644 --- a/src/grib_dumper_class_bufr_encode_filter.c +++ b/src/grib_dumper_class_bufr_encode_filter.c @@ -57,7 +57,7 @@ static void dump_section (grib_dumper* d, grib_accessor* a,grib_block_of_acce typedef struct grib_dumper_bufr_encode_filter { grib_dumper dumper; -/* Members defined in filter */ +/* Members defined in bufr_encode_filter */ long section_offset; long begin; long empty; @@ -70,7 +70,7 @@ typedef struct grib_dumper_bufr_encode_filter { static grib_dumper_class _grib_dumper_class_bufr_encode_filter = { 0, /* super */ - "bufr_encode_filter", /* name */ + "bufr_encode_filter", /* name */ sizeof(grib_dumper_bufr_encode_filter), /* size */ 0, /* inited */ &init_class, /* init_class */ diff --git a/src/grib_dumper_class_bufr_encode_fortran.c b/src/grib_dumper_class_bufr_encode_fortran.c index a4d8f063c..e9b2659ae 100644 --- a/src/grib_dumper_class_bufr_encode_fortran.c +++ b/src/grib_dumper_class_bufr_encode_fortran.c @@ -59,7 +59,7 @@ static void footer (grib_dumper*,grib_handle*); typedef struct grib_dumper_bufr_encode_fortran { grib_dumper dumper; -/* Members defined in fortran */ +/* Members defined in bufr_encode_fortran */ long section_offset; long empty; long end; @@ -71,8 +71,8 @@ typedef struct grib_dumper_bufr_encode_fortran { static grib_dumper_class _grib_dumper_class_bufr_encode_fortran = { 0, /* super */ - "bufr_encode_fortran", /* name */ - sizeof(grib_dumper_bufr_encode_fortran), /* size */ + "bufr_encode_fortran", /* name */ + sizeof(grib_dumper_bufr_encode_fortran), /* size */ 0, /* inited */ &init_class, /* init_class */ &init, /* init */ diff --git a/src/grib_dumper_class_bufr_encode_python.c b/src/grib_dumper_class_bufr_encode_python.c index b7a15f7bc..26abceb47 100644 --- a/src/grib_dumper_class_bufr_encode_python.c +++ b/src/grib_dumper_class_bufr_encode_python.c @@ -59,7 +59,7 @@ static void footer (grib_dumper*,grib_handle*); typedef struct grib_dumper_bufr_encode_python { grib_dumper dumper; -/* Members defined in python */ +/* Members defined in bufr_encode_python */ long section_offset; long empty; long end; @@ -71,7 +71,7 @@ typedef struct grib_dumper_bufr_encode_python { static grib_dumper_class _grib_dumper_class_bufr_encode_python = { 0, /* super */ - "bufr_encode_python", /* name */ + "bufr_encode_python", /* name */ sizeof(grib_dumper_bufr_encode_python), /* size */ 0, /* inited */ &init_class, /* init_class */ diff --git a/src/grib_dumper_class_grib_encode_C.c b/src/grib_dumper_class_grib_encode_C.c index 7c758642e..6c1bb4d14 100644 --- a/src/grib_dumper_class_grib_encode_C.c +++ b/src/grib_dumper_class_grib_encode_C.c @@ -53,14 +53,14 @@ static void footer (grib_dumper*,grib_handle*); typedef struct grib_dumper_grib_encode_C { grib_dumper dumper; -/* Members defined in c_code */ +/* Members defined in grib_encode_C */ int cr; } grib_dumper_grib_encode_C; static grib_dumper_class _grib_dumper_class_grib_encode_C = { 0, /* super */ - "grib_encode_C", /* name */ + "grib_encode_C", /* name */ sizeof(grib_dumper_grib_encode_C), /* size */ 0, /* inited */ &init_class, /* init_class */ diff --git a/src/grib_dumper_factory.h b/src/grib_dumper_factory.h index 1e6b8cd21..860a1ccbd 100644 --- a/src/grib_dumper_factory.h +++ b/src/grib_dumper_factory.h @@ -1,17 +1,31 @@ /* This file is automatically generated by ./make_class.pl, do not edit */ { "bufr_decode_C", &grib_dumper_class_bufr_decode_C, }, +{ "bufr_decode_C", &grib_dumper_class_bufr_decode_C, }, { "bufr_decode_filter", &grib_dumper_class_bufr_decode_filter, }, +{ "bufr_decode_filter", &grib_dumper_class_bufr_decode_filter, }, { "bufr_decode_fortran", &grib_dumper_class_bufr_decode_fortran, }, { "bufr_decode_python", &grib_dumper_class_bufr_decode_python, }, +{ "bufr_decode_python", &grib_dumper_class_bufr_decode_python, }, { "bufr_encode_C", &grib_dumper_class_bufr_encode_C, }, +{ "bufr_encode_C", &grib_dumper_class_bufr_encode_C, }, { "bufr_encode_filter", &grib_dumper_class_bufr_encode_filter, }, +{ "bufr_encode_filter", &grib_dumper_class_bufr_encode_filter, }, { "bufr_encode_fortran", &grib_dumper_class_bufr_encode_fortran, }, { "bufr_encode_python", &grib_dumper_class_bufr_encode_python, }, -{ "grib_encode_C", &grib_dumper_class_grib_encode_C, }, +{ "bufr_encode_python", &grib_dumper_class_bufr_encode_python, }, { "debug", &grib_dumper_class_debug, }, +{ "debug", &grib_dumper_class_debug, }, { "default", &grib_dumper_class_default, }, +{ "default", &grib_dumper_class_default, }, +{ "grib_encode_C", &grib_dumper_class_grib_encode_C, }, +{ "grib_encode_C", &grib_dumper_class_grib_encode_C, }, { "json", &grib_dumper_class_json, }, +{ "json", &grib_dumper_class_json, }, { "keys", &grib_dumper_class_keys, }, +{ "keys", &grib_dumper_class_keys, }, { "serialize", &grib_dumper_class_serialize, }, +{ "serialize", &grib_dumper_class_serialize, }, { "wmo", &grib_dumper_class_wmo, }, +{ "wmo", &grib_dumper_class_wmo, }, { "xml", &grib_dumper_class_xml, }, +{ "xml", &grib_dumper_class_xml, }, From 3d10d553bbecf86c201aa64a8bbd212054d7a285 Mon Sep 17 00:00:00 2001 From: Enrico Fucile Date: Wed, 5 Oct 2016 16:24:46 +0100 Subject: [PATCH 5/5] ECC-354 --- ...grib_accessor_class_bufr_simple_thinning.c | 224 ++++++++++++++++++ 1 file changed, 224 insertions(+) create mode 100644 src/grib_accessor_class_bufr_simple_thinning.c diff --git a/src/grib_accessor_class_bufr_simple_thinning.c b/src/grib_accessor_class_bufr_simple_thinning.c new file mode 100644 index 000000000..325d15855 --- /dev/null +++ b/src/grib_accessor_class_bufr_simple_thinning.c @@ -0,0 +1,224 @@ +/* + * Copyright 2005-2016 ECMWF. + * + * This software is licensed under the terms of the Apache Licence Version 2.0 + * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. + * + * In applying this licence, ECMWF does not waive the privileges and immunities granted to it by + * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. + */ + +#include "grib_api_internal.h" +/* + This is used by make_class.pl + + START_CLASS_DEF + CLASS = accessor + SUPER = grib_accessor_class_gen + IMPLEMENTS = init; get_native_type + IMPLEMENTS = pack_long; + MEMBERS = const char* doExtractSubsets + MEMBERS = const char* numberOfSubsets + MEMBERS = const char* extractSubsetList + MEMBERS = const char* simpleThinningStart + MEMBERS = const char* simpleThinningMissingRadius + END_CLASS_DEF + + */ + +/* START_CLASS_IMP */ + +/* + +Don't edit anything between START_CLASS_IMP and END_CLASS_IMP +Instead edit values between START_CLASS_DEF and END_CLASS_DEF +or edit "accessor.class" and rerun ./make_class.pl + +*/ + +static int get_native_type(grib_accessor*); +static int pack_long(grib_accessor*, const long* val,size_t *len); +static void init(grib_accessor*,const long, grib_arguments* ); +static void init_class(grib_accessor_class*); + +typedef struct grib_accessor_bufr_simple_thinning { + grib_accessor att; +/* Members defined in gen */ +/* Members defined in bufr_simple_thinning */ + const char* doExtractSubsets; + const char* numberOfSubsets; + const char* extractSubsetList; + const char* simpleThinningStart; + const char* simpleThinningMissingRadius; +} grib_accessor_bufr_simple_thinning; + +extern grib_accessor_class* grib_accessor_class_gen; + +static grib_accessor_class _grib_accessor_class_bufr_simple_thinning = { + &grib_accessor_class_gen, /* super */ + "bufr_simple_thinning", /* name */ + sizeof(grib_accessor_bufr_simple_thinning), /* size */ + 0, /* inited */ + &init_class, /* init_class */ + &init, /* init */ + 0, /* post_init */ + 0, /* free mem */ + 0, /* describes himself */ + 0, /* get length of section */ + 0, /* get length of string */ + 0, /* get number of values */ + 0, /* get number of bytes */ + 0, /* get offset to bytes */ + &get_native_type, /* get native type */ + 0, /* get sub_section */ + 0, /* grib_pack procedures long */ + 0, /* grib_pack procedures long */ + &pack_long, /* grib_pack procedures long */ + 0, /* grib_unpack procedures long */ + 0, /* grib_pack procedures double */ + 0, /* grib_unpack procedures double */ + 0, /* grib_pack procedures string */ + 0, /* grib_unpack procedures string */ + 0, /* grib_pack array procedures string */ + 0, /* grib_unpack array procedures string */ + 0, /* grib_pack procedures bytes */ + 0, /* grib_unpack procedures bytes */ + 0, /* pack_expression */ + 0, /* notify_change */ + 0, /* update_size */ + 0, /* preferred_size */ + 0, /* resize */ + 0, /* nearest_smaller_value */ + 0, /* next accessor */ + 0, /* compare vs. another accessor */ + 0, /* unpack only ith value */ + 0, /* unpack a subarray */ + 0, /* clear */ + 0, /* clone accessor */ +}; + + +grib_accessor_class* grib_accessor_class_bufr_simple_thinning = &_grib_accessor_class_bufr_simple_thinning; + + +static void init_class(grib_accessor_class* c) +{ + c->dump = (*(c->super))->dump; + c->next_offset = (*(c->super))->next_offset; + c->string_length = (*(c->super))->string_length; + c->value_count = (*(c->super))->value_count; + c->byte_count = (*(c->super))->byte_count; + c->byte_offset = (*(c->super))->byte_offset; + c->sub_section = (*(c->super))->sub_section; + c->pack_missing = (*(c->super))->pack_missing; + c->is_missing = (*(c->super))->is_missing; + c->unpack_long = (*(c->super))->unpack_long; + c->pack_double = (*(c->super))->pack_double; + c->unpack_double = (*(c->super))->unpack_double; + c->pack_string = (*(c->super))->pack_string; + c->unpack_string = (*(c->super))->unpack_string; + c->pack_string_array = (*(c->super))->pack_string_array; + c->unpack_string_array = (*(c->super))->unpack_string_array; + c->pack_bytes = (*(c->super))->pack_bytes; + c->unpack_bytes = (*(c->super))->unpack_bytes; + c->pack_expression = (*(c->super))->pack_expression; + c->notify_change = (*(c->super))->notify_change; + c->update_size = (*(c->super))->update_size; + c->preferred_size = (*(c->super))->preferred_size; + c->resize = (*(c->super))->resize; + c->nearest_smaller_value = (*(c->super))->nearest_smaller_value; + c->next = (*(c->super))->next; + c->compare = (*(c->super))->compare; + c->unpack_double_element = (*(c->super))->unpack_double_element; + c->unpack_double_subarray = (*(c->super))->unpack_double_subarray; + c->clear = (*(c->super))->clear; + c->make_clone = (*(c->super))->make_clone; +} + +/* END_CLASS_IMP */ + +static void init(grib_accessor* a, const long len , grib_arguments* arg ) +{ + int n=0; + grib_accessor_bufr_simple_thinning *self =(grib_accessor_bufr_simple_thinning*)a; + + a->length=0; + self->doExtractSubsets = grib_arguments_get_name(grib_handle_of_accessor(a),arg,n++); + self->numberOfSubsets = grib_arguments_get_name(grib_handle_of_accessor(a),arg,n++); + self->extractSubsetList = grib_arguments_get_name(grib_handle_of_accessor(a),arg,n++); + self->simpleThinningStart = grib_arguments_get_name(grib_handle_of_accessor(a),arg,n++); + self->simpleThinningMissingRadius = grib_arguments_get_name(grib_handle_of_accessor(a),arg,n++); + + a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; +} + +static int get_native_type(grib_accessor* a) +{ + return GRIB_TYPE_LONG; +} + +static int apply_thinning(grib_accessor* a,long skip) { + grib_accessor_bufr_simple_thinning *self =(grib_accessor_bufr_simple_thinning*)a; + int ret=0; + grib_handle* h=grib_handle_of_accessor(a); + grib_context* c=h->context; + long compressed=0,nsubsets; + long numberOfSubsets,i; + grib_iarray* subsets; + long *subsets_ar=0; + long start=0,radius=0; + + ret=grib_get_long(h,"compressedData",&compressed); + if (ret) return ret; + if (compressed) { + long numberOfSubsets=0; + ret=grib_get_long(h,self->numberOfSubsets,&numberOfSubsets); + if (ret) return ret; + + ret=grib_get_long(h,self->simpleThinningStart,&start); + if (ret) return ret; + + ret=grib_get_long(h,self->simpleThinningMissingRadius,&radius); + if (ret) return ret; + + subsets=grib_iarray_new(c,numberOfSubsets / skip + 1 ,10); + for (i=0;iextractSubsetList,subsets_ar,nsubsets); + if (ret) return ret; + + ret=grib_set_long(h,"unpack",1); + if (ret) return ret; + + ret=grib_set_long(h,self->doExtractSubsets,1); + if (ret) return ret; + } + + } else { + return GRIB_NOT_IMPLEMENTED; + } + + + return ret; +} + +static int pack_long(grib_accessor* a, const long* val, size_t *len) +{ + int err=0; + grib_accessor_bufr_simple_thinning *self =(grib_accessor_bufr_simple_thinning*)a; + + if (*len==0) return GRIB_SUCCESS; + err=apply_thinning(a,*val); + if (err) return err; + + err=grib_set_long(a->parent->h,self->doExtractSubsets,1); + if (err) return err; + + return err; +}