ECC-976: Add hint

This commit is contained in:
Shahram Najm 2019-08-22 16:13:53 +01:00
parent 56aca66573
commit 62cc82ac52
3 changed files with 22 additions and 3 deletions

View File

@ -245,6 +245,7 @@ static int unpack_double (grib_accessor* a, double*v, size_t *len)
char val[1024];
size_t l = sizeof(val);
char *last = NULL;
grib_unpack_string (a , val, &l);
*v = strtod(val,&last);
@ -255,7 +256,8 @@ static int unpack_double (grib_accessor* a, double*v, size_t *len)
return GRIB_SUCCESS;
}
grib_context_log(a->context,GRIB_LOG_ERROR,"Cannot unpack %s as double",a->name);
grib_context_log(a->context,GRIB_LOG_ERROR,"Cannot unpack %s as double. Hint: Try unpacking as string",a->name);
return GRIB_NOT_IMPLEMENTED;
}

View File

@ -463,6 +463,7 @@ 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) {
@ -480,8 +481,16 @@ 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));
}
return GRIB_DECODING_ERROR;
}
return GRIB_SUCCESS;
}

View File

@ -268,6 +268,7 @@ static int clear(grib_accessor* a)
static int unpack_long (grib_accessor* a, long* v, size_t *len)
{
int type = GRIB_TYPE_UNDEFINED;
if(a->cclass->unpack_double && a->cclass->unpack_double != &unpack_double)
{
double val = 0.0;
@ -295,11 +296,15 @@ static int unpack_long (grib_accessor* a, long* v, size_t *len)
}
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_NOT_IMPLEMENTED;
}
static int unpack_double (grib_accessor* a, double*v, size_t *len)
{
int type = GRIB_TYPE_UNDEFINED;
if(a->cclass->unpack_long && a->cclass->unpack_long != &unpack_long)
{
long val = 0;
@ -327,12 +332,15 @@ static int unpack_double (grib_accessor* a, double*v, size_t *len)
}
grib_context_log(a->context,GRIB_LOG_ERROR,"Cannot unpack %s as double",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_NOT_IMPLEMENTED;
}
static int unpack_string(grib_accessor*a , char* v, size_t *len)
{
if(a->cclass->unpack_double && a->cclass->unpack_double != &unpack_double)
{
double val = 0.0;