mirror of https://github.com/ecmwf/eccodes.git
ECC-1233: grib_filter: Allow printing of 'byte' keys like bitmap and section paddings
This commit is contained in:
parent
035d5635c4
commit
ded1337e56
|
@ -173,6 +173,7 @@ int grib_recompose_name(grib_handle* h, grib_accessor* observer, const char* una
|
|||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
#if 0
|
||||
int grib_accessor_print(grib_accessor* a, const char* name, int type, const char* format,
|
||||
const char* separator, int maxcols, int* newline, FILE* out)
|
||||
{
|
||||
|
@ -296,12 +297,13 @@ int grib_accessor_print(grib_accessor* a, const char* name, int type, const char
|
|||
}
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
int grib_accessors_list_print(grib_handle* h, grib_accessors_list* al, const char* name,
|
||||
int type, const char* format, const char* separator, int maxcols, int* newline, FILE* out)
|
||||
{
|
||||
size_t size = 0, len = 0, replen = 0;
|
||||
char* sval = NULL;
|
||||
size_t size = 0, len = 0, replen = 0, j = 0;
|
||||
unsigned char* bval = NULL;
|
||||
char* p = NULL;
|
||||
double* dval = 0;
|
||||
long* lval = 0;
|
||||
|
@ -336,14 +338,14 @@ int grib_accessors_list_print(grib_handle* h, grib_accessors_list* al, const cha
|
|||
}
|
||||
}
|
||||
else {
|
||||
int i = 0;
|
||||
int cols = 0;
|
||||
j = 0;
|
||||
cvals = (char**)grib_context_malloc_clear(h->context, sizeof(char*) * size);
|
||||
grib_accessors_list_unpack_string(al, cvals, &size);
|
||||
for (i = 0; i < size; i++) {
|
||||
for (j = 0; j < size; j++) {
|
||||
*newline = 1;
|
||||
fprintf(out, "%s", cvals[i]);
|
||||
if (i < size - 1)
|
||||
fprintf(out, "%s", cvals[j]);
|
||||
if (j < size - 1)
|
||||
fprintf(out, "%s", myseparator);
|
||||
cols++;
|
||||
if (cols >= maxcols) {
|
||||
|
@ -351,7 +353,7 @@ int grib_accessors_list_print(grib_handle* h, grib_accessors_list* al, const cha
|
|||
*newline = 1;
|
||||
cols = 0;
|
||||
}
|
||||
grib_context_free(h->context, cvals[i]);
|
||||
grib_context_free(h->context, cvals[j]);
|
||||
}
|
||||
}
|
||||
grib_context_free(h->context, cvals);
|
||||
|
@ -364,12 +366,12 @@ int grib_accessors_list_print(grib_handle* h, grib_accessors_list* al, const cha
|
|||
if (size == 1)
|
||||
fprintf(out, myformat, dval[0]);
|
||||
else {
|
||||
int i = 0;
|
||||
int cols = 0;
|
||||
for (i = 0; i < size; i++) {
|
||||
j = 0;
|
||||
for (j = 0; j < size; j++) {
|
||||
*newline = 1;
|
||||
fprintf(out, myformat, dval[i]);
|
||||
if (i < size - 1)
|
||||
fprintf(out, myformat, dval[j]);
|
||||
if (j < size - 1)
|
||||
fprintf(out, "%s", myseparator);
|
||||
cols++;
|
||||
if (cols >= maxcols) {
|
||||
|
@ -389,12 +391,12 @@ int grib_accessors_list_print(grib_handle* h, grib_accessors_list* al, const cha
|
|||
if (size == 1)
|
||||
fprintf(out, myformat, lval[0]);
|
||||
else {
|
||||
int i = 0;
|
||||
int cols = 0;
|
||||
for (i = 0; i < size; i++) {
|
||||
j = 0;
|
||||
for (j = 0; j < size; j++) {
|
||||
*newline = 1;
|
||||
fprintf(out, myformat, lval[i]);
|
||||
if (i < size - 1)
|
||||
fprintf(out, myformat, lval[j]);
|
||||
if (j < size - 1)
|
||||
fprintf(out, "%s", myseparator);
|
||||
cols++;
|
||||
if (cols >= maxcols) {
|
||||
|
@ -408,13 +410,13 @@ int grib_accessors_list_print(grib_handle* h, grib_accessors_list* al, const cha
|
|||
break;
|
||||
case GRIB_TYPE_BYTES:
|
||||
replen = a->length;
|
||||
sval = (char*)grib_context_malloc(h->context, replen * sizeof(char));
|
||||
ret = grib_unpack_string(al->accessor, sval, &replen);
|
||||
p = sval;
|
||||
while ((replen--) > 0)
|
||||
fprintf(out, "%c", *(p++));
|
||||
grib_context_free(h->context, sval);
|
||||
*newline = 0;
|
||||
bval = (unsigned char*)grib_context_malloc(h->context, replen * sizeof(unsigned char));
|
||||
ret = grib_unpack_bytes(al->accessor, bval, &replen);
|
||||
for (j = 0; j < replen; j++) {
|
||||
fprintf(out, "%02x", bval[j]);
|
||||
}
|
||||
grib_context_free(h->context, bval);
|
||||
*newline = 1;
|
||||
break;
|
||||
default:
|
||||
grib_context_log(h->context, GRIB_LOG_WARNING,
|
||||
|
|
Loading…
Reference in New Issue