ECC-319: GRIBEditionNumber returns '?' if queried as a string

This commit is contained in:
Shahram Najm 2016-08-22 10:54:47 +01:00
parent c8bc74c8a9
commit f2111f03e4
1 changed files with 81 additions and 78 deletions

View File

@ -152,9 +152,9 @@ static void init(grib_accessor* a, const long len, grib_arguments *arg )
static void post_init(grib_accessor* a)
{
grib_accessor_lookup* self = (grib_accessor_lookup*)a;
if(self->real_name )
if(self->real_name ) {
grib_dependency_observe_expression(a,self->real_name );
}
}
static void dump(grib_accessor* a,grib_dumper* dumper)
@ -182,11 +182,10 @@ static void dump(grib_accessor* a,grib_dumper* dumper)
sprintf(buf,"%s %lu %ld-%ld", msg, v, (long)a->offset+self->loffset, (long)self->llength);
grib_dump_long(dumper,a,buf);
}
static int unpack_string(grib_accessor*a , char* v, size_t *len){
static int unpack_string(grib_accessor*a , char* v, size_t *len)
{
grib_accessor_lookup* self = (grib_accessor_lookup*)a;
unsigned char bytes[1024] = {0,};
int i;
@ -195,16 +194,28 @@ static int unpack_string(grib_accessor*a , char* v, size_t *len){
grib_unpack_bytes(a, bytes, &llen); /* TODO: Unpack byte unpack the wrong offset */
bytes[llen] = 0;
for(i = 0; i < llen; i++)
{
v[i] = isprint(bytes[i]) ? bytes[i] : '?';
}
v[llen] = 0;
if (llen==1 && v[0] == '?') {
/* Try unpack as long */
size_t length = 10;
long lval = 0;
int err = unpack_long(a, &lval, &length);
if (!err) {
char str[5];
int conv = sprintf(str, "%ld", lval);
if (conv == 1) {
v[0] = str[0];
}
}
}
return GRIB_SUCCESS;
}
static int unpack_long(grib_accessor* a, long* val, size_t *len)
@ -212,10 +223,8 @@ static int unpack_long(grib_accessor* a, long* val, size_t *len)
grib_accessor_lookup* al = (grib_accessor_lookup*)a;
grib_handle *h = grib_handle_of_accessor(a);
long pos = (a->offset+al->loffset)*8;
if(len[0] < 1)
{
grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s it contains %d values ", a->name , 1 );
@ -232,10 +241,9 @@ static int unpack_long(grib_accessor* a, long* val, size_t *len)
val[0] = grib_decode_unsigned_long(h->buffer->data , &pos, al->llength*8);
len[0] = 1;
/* printf("lookup: %s %ld %ld\n",a->name,pos/8,val[0]); */
/*printf("###########lookup unpack_long: %s %ld %ld\n",a->name, pos/8, val[0]);*/
return GRIB_SUCCESS;
}
static int pack_long(grib_accessor* a, const long* val, size_t *len)
@ -243,7 +251,6 @@ static int pack_long (grib_accessor* a, const long* val, size_t *len)
return GRIB_NOT_IMPLEMENTED;
}
static long byte_count(grib_accessor* a)
{
grib_accessor_lookup* al = (grib_accessor_lookup*)a;
@ -261,7 +268,3 @@ static int notify_change(grib_accessor* self,grib_accessor* changed)
/* Forward changes */
return grib_dependency_notify_change(self);
}