Revert changes for ECC-976 and ECC-980

This commit is contained in:
Shahram Najm 2019-08-23 15:45:58 +01:00
parent 20ea673a21
commit 102372d478
3 changed files with 109 additions and 106 deletions

View File

@ -463,7 +463,6 @@ static long get_ECMWF_local_paramId(grib_accessor* a, grib_handle* h)
static int unpack_long(grib_accessor* a, long* val, size_t *len)
{
char *endptr;
const char *p = concept_evaluate(a);
if(!p) {
@ -481,17 +480,26 @@ static int unpack_long(grib_accessor* a, long* val, size_t *len)
return GRIB_NOT_FOUND;
}
*val = atol(p);
*len = 1;
*val = strtol(p, &endptr, 10);
if (endptr == p) {
int type = GRIB_TYPE_UNDEFINED;
grib_context_log(a->context,GRIB_LOG_ERROR,"Cannot unpack %s as long",a->name);
if (grib_get_native_type(grib_handle_of_accessor(a), a->name, &type) == GRIB_SUCCESS) {
grib_context_log(a->context,GRIB_LOG_ERROR,"Hint: Try unpacking as %s", grib_get_type_name(type));
#if 0
/* ECC-980: Changes reverted because of side-effects!
* e.g. marsType being a codetable and concept! see ifsParam
*/
{
char *endptr;
*val = strtol(p, &endptr, 10);
if (endptr == p || *endptr != '\0') {
/* Failed to convert string into integer */
int type = GRIB_TYPE_UNDEFINED;
grib_context_log(a->context,GRIB_LOG_ERROR,"Cannot unpack %s as long",a->name);
if (grib_get_native_type(grib_handle_of_accessor(a), a->name, &type) == GRIB_SUCCESS) {
grib_context_log(a->context,GRIB_LOG_ERROR,"Hint: Try unpacking as %s", grib_get_type_name(type));
}
return GRIB_DECODING_ERROR;
}
return GRIB_DECODING_ERROR;
}
#endif
return GRIB_SUCCESS;
}

View File

@ -144,129 +144,124 @@ static void init_class(grib_accessor_class* c)
static void init(grib_accessor* a,const long l, grib_arguments* c)
{
grib_accessor_scale* self = (grib_accessor_scale*)a;
int n = 0;
self->value = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++);
self->multiplier = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++);
self->divisor = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++);
self->truncating = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++);
grib_accessor_scale* self = (grib_accessor_scale*)a;
int n = 0;
self->value = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++);
self->multiplier = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++);
self->divisor = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++);
self->truncating = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++);
}
static int unpack_double (grib_accessor* a, double* val, size_t *len)
static int unpack_double(grib_accessor* a, double* val, size_t *len)
{
grib_accessor_scale* self = (grib_accessor_scale*)a;
int ret = 0;
long value = 0;
long multiplier = 0;
long divisor = 0;
grib_accessor_scale* self = (grib_accessor_scale*)a;
int ret = 0;
long value = 0;
long multiplier = 0;
long divisor = 0;
if(*len < 1){
ret = GRIB_ARRAY_TOO_SMALL;
grib_context_log(a->context, GRIB_LOG_ERROR,
"Accessor %s cannot gather value for %s and/or %s error %d",
a->name,self->multiplier, self->divisor, ret);
return ret;
}
if((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->divisor,&divisor)) != GRIB_SUCCESS)
return ret;
if((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->multiplier,&multiplier)) != GRIB_SUCCESS)
return ret;
if((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->value,&value)) != GRIB_SUCCESS)
return ret;
if (value == GRIB_MISSING_LONG) *val=GRIB_MISSING_DOUBLE;
else *val = ((double)(value*multiplier))/divisor;
/*printf("unpack_double: divisor=%ld multiplier=%ld long_value=%ld scaled_value=%.30f\n",(double)divisor,(double)multiplier,value,*val);*/
if (ret == GRIB_SUCCESS) *len = 1;
if(*len < 1){
ret = GRIB_ARRAY_TOO_SMALL;
grib_context_log(a->context, GRIB_LOG_ERROR,
"Accessor %s cannot gather value for %s and/or %s error %d",
a->name,self->multiplier, self->divisor, ret);
return ret;
}
if((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->divisor,&divisor)) != GRIB_SUCCESS)
return ret;
if((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->multiplier,&multiplier)) != GRIB_SUCCESS)
return ret;
if((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->value,&value)) != GRIB_SUCCESS)
return ret;
if (value == GRIB_MISSING_LONG) *val=GRIB_MISSING_DOUBLE;
else *val = ((double)(value*multiplier))/divisor;
/*printf("unpack_double: divisor=%ld multiplier=%ld long_value=%ld scaled_value=%.30f\n",(double)divisor,(double)multiplier,value,*val);*/
if (ret == GRIB_SUCCESS) *len = 1;
return ret;
}
static int pack_long(grib_accessor* a, const long* val, size_t *len)
{
const double dval=(double)*val ;
return pack_double(a, &dval,len);
const double dval=(double)*val ;
return pack_double(a, &dval,len);
}
static int pack_double(grib_accessor* a, const double* val, size_t *len)
{
grib_accessor_scale* self = (grib_accessor_scale*)a;
int ret = 0;
grib_accessor_scale* self = (grib_accessor_scale*)a;
int ret = 0;
long value = 0;
long divisor = 0;
long multiplier = 0;
long truncating=0;
double x;
long value = 0;
long divisor = 0;
long multiplier = 0;
long truncating=0;
double x;
ret = grib_get_long_internal(grib_handle_of_accessor(a), self->divisor,&divisor);
if(ret != GRIB_SUCCESS) {
grib_context_log(a->context, GRIB_LOG_ERROR, "Accessor %s cannont gather value for %s error %d \n", a->name, self->divisor, ret);
return ret;
}
ret = grib_get_long_internal(grib_handle_of_accessor(a), self->multiplier,&multiplier);
if(ret != GRIB_SUCCESS){
grib_context_log(a->context, GRIB_LOG_ERROR, "Accessor %s cannont gather value for %s error %d \n", a->name, self->divisor, ret);
return ret;
}
if (self->truncating) {
ret = grib_get_long_internal(grib_handle_of_accessor(a), self->truncating,&truncating);
if(ret != GRIB_SUCCESS){
grib_context_log(a->context, GRIB_LOG_ERROR, "Accessor %s cannont gather value for %s error %d \n", a->name, self->truncating, ret);
return ret;
ret = grib_get_long_internal(grib_handle_of_accessor(a), self->divisor,&divisor);
if(ret != GRIB_SUCCESS) {
grib_context_log(a->context, GRIB_LOG_ERROR, "Accessor %s cannont gather value for %s error %d \n", a->name, self->divisor, ret);
return ret;
}
ret = grib_get_long_internal(grib_handle_of_accessor(a), self->multiplier,&multiplier);
if(ret != GRIB_SUCCESS){
grib_context_log(a->context, GRIB_LOG_ERROR, "Accessor %s cannont gather value for %s error %d \n", a->name, self->divisor, ret);
return ret;
}
if (self->truncating) {
ret = grib_get_long_internal(grib_handle_of_accessor(a), self->truncating,&truncating);
if(ret != GRIB_SUCCESS){
grib_context_log(a->context, GRIB_LOG_ERROR, "Accessor %s cannont gather value for %s error %d \n", a->name, self->truncating, ret);
return ret;
}
}
}
if (multiplier == 0) {
grib_context_log(a->context, GRIB_LOG_ERROR, "Accessor %s cannont divide by a zero multiplier %s error %d \n", a->name, self->multiplier, ret);
return GRIB_ENCODING_ERROR;
}
if (multiplier == 0) {
grib_context_log(a->context, GRIB_LOG_ERROR, "Accessor %s cannont divide by a zero multiplier %s error %d \n", a->name, self->multiplier, ret);
return GRIB_ENCODING_ERROR;
}
x=*val * (double)divisor / (double)multiplier;
if (*val == GRIB_MISSING_DOUBLE) value = GRIB_MISSING_LONG;
else if (truncating) {
value = (long)x;
} else {
value = x > 0 ? (long)(x+0.5) : (long)(x-0.5) ;
}
x=*val * (double)divisor / (double)multiplier;
if (*val == GRIB_MISSING_DOUBLE) value = GRIB_MISSING_LONG;
else if (truncating) {
value = (long)x;
} else {
value = x > 0 ? (long)(x+0.5) : (long)(x-0.5) ;
}
ret = grib_set_long_internal(grib_handle_of_accessor(a), self->value,value);
if(ret )
grib_context_log(a->context, GRIB_LOG_ERROR, "Accessor %s cannont pack value for %s error %d \n", a->name, self->value, ret);
ret = grib_set_long_internal(grib_handle_of_accessor(a), self->value,value);
if(ret )
grib_context_log(a->context, GRIB_LOG_ERROR, "Accessor %s cannont pack value for %s error %d \n", a->name, self->value, ret);
if (ret == GRIB_SUCCESS) *len = 1;
if (ret == GRIB_SUCCESS) *len = 1;
return ret;
return ret;
}
static int is_missing(grib_accessor* a){
grib_accessor_scale* self = (grib_accessor_scale*)a;
grib_accessor* av=grib_find_accessor(grib_handle_of_accessor(a),self->value);
static int is_missing(grib_accessor* a)
{
grib_accessor_scale* self = (grib_accessor_scale*)a;
grib_accessor* av=grib_find_accessor(grib_handle_of_accessor(a),self->value);
if (!av) return GRIB_NOT_FOUND;
return grib_is_missing_internal(av);
if (!av) return GRIB_NOT_FOUND;
return grib_is_missing_internal(av);
#if 0
int ret=0;
long value=0;
int ret=0;
long value=0;
if((ret = grib_get_long_internal(grib_handle_of_accessor(a),self->value,
&value) ) != GRIB_SUCCESS){
grib_context_log(a->context, GRIB_LOG_ERROR,
"Accessor %s cannont gather value for %s error %d \n", a->name,
self->value, ret);
return 0;
}
if((ret = grib_get_long_internal(grib_handle_of_accessor(a),self->value, &value))!= GRIB_SUCCESS){
grib_context_log(a->context, GRIB_LOG_ERROR,
"Accessor %s cannont gather value for %s error %d \n", a->name,
self->value, ret);
return 0;
}
return (value == GRIB_MISSING_LONG);
return (value == GRIB_MISSING_LONG);
#endif
}

View File

@ -65,7 +65,7 @@ typedef struct grib_dumper_bufr_simple {
long end;
long isLeaf;
long isAttribute;
long numberOfSubsets;
long numberOfSubsets;
grib_string_list* keys;
} grib_dumper_bufr_simple;