From 640e7b36a650863d608f7c7d82636b672f6bb752 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Fri, 16 Sep 2016 16:57:06 +0100 Subject: [PATCH] ECC-236: clean up --- src/grib_value.c | 12 +++++++----- tools/grib_tools.c | 23 ++++++----------------- 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/src/grib_value.c b/src/grib_value.c index 89616ba8d..5fc53ad3e 100644 --- a/src/grib_value.c +++ b/src/grib_value.c @@ -541,18 +541,20 @@ int grib_is_missing_double(grib_accessor* a,double x) return ret; } -int grib_is_missing_string(grib_accessor* a,unsigned char* x,size_t len) +int grib_is_missing_string(grib_accessor* a, unsigned char* x, size_t len) { + /* For a string value to be missing, every character has to be */ + /* all 1's (i.e. 0xFF) */ int ret; size_t i=0; if (len==0) return 0; ret=1; for (i=0;iflags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) && ret==1 )) ? 1 : 0; diff --git a/tools/grib_tools.c b/tools/grib_tools.c index 480cc1ad0..f924c754c 100644 --- a/tools/grib_tools.c +++ b/tools/grib_tools.c @@ -786,22 +786,7 @@ void grib_skip_check(grib_runtime_options* options,grib_handle* h) } } -static int string_value_is_missing(const char* val, size_t length) -{ - /* For a string value to be missing, all its chars have to be */ - /* all 1's i.e. -1 */ - int i=0; - if (val == NULL || length == 0) - return 0; - for(i=0; iverbose) return; @@ -826,8 +812,10 @@ void grib_print_key_values(grib_runtime_options* options,grib_handle* h) grib_get_native_type(h, options->print_keys[i].name, &(options->print_keys[i].type)); switch (options->print_keys[i].type) { case GRIB_TYPE_STRING: + acc = grib_find_accessor(h, options->print_keys[i].name); ret=grib_get_string(h, options->print_keys[i].name, value, &len); - if (string_value_is_missing(value, len)) sprintf(value,"MISSING"); + if (grib_is_missing_string(acc, (unsigned char *)value, len)) + sprintf(value,"MISSING"); break; case GRIB_TYPE_DOUBLE: ret=grib_get_double(h, options->print_keys[i].name, &dvalue); @@ -848,6 +836,7 @@ void grib_print_key_values(grib_runtime_options* options,grib_handle* h) } } } else { + /* Other products e.g. GRIB */ if (grib_is_missing(h,options->print_keys[i].name,&ret) && ret==GRIB_SUCCESS) { sprintf(value,"MISSING"); }