From a077fd8554b7fda2b9ca5a70a439f7a358a7b015 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Fri, 18 Dec 2020 17:00:35 +0000 Subject: [PATCH] WMO dump: Print user-friendly type for keys (-t option) --- src/grib_dumper_class_wmo.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/grib_dumper_class_wmo.c b/src/grib_dumper_class_wmo.c index a8bbb863c..bdeb862a8 100644 --- a/src/grib_dumper_class_wmo.c +++ b/src/grib_dumper_class_wmo.c @@ -167,7 +167,7 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) print_offset(self->dumper.out, self->begin, self->theEnd); if ((d->option_flags & GRIB_DUMP_FLAG_TYPE) != 0) - fprintf(self->dumper.out, "%s ", a->creator->op); + fprintf(self->dumper.out, "%s (int) ", a->creator->op); if (size > 1) { int cols = 19; @@ -274,7 +274,7 @@ static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) print_offset(self->dumper.out, self->begin, self->theEnd); if ((d->option_flags & GRIB_DUMP_FLAG_TYPE) != 0) - fprintf(self->dumper.out, "%s ", a->creator->op); + fprintf(self->dumper.out, "%s (double) ", a->creator->op); if (((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && grib_is_missing_internal(a)) fprintf(self->dumper.out, "%s = MISSING", a->name); @@ -324,7 +324,7 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) /*for(i = 0; i < d->depth ; i++) fprintf(self->dumper.out," ");*/ print_offset(self->dumper.out, self->begin, self->theEnd); if ((d->option_flags & GRIB_DUMP_FLAG_TYPE) != 0) - fprintf(self->dumper.out, "%s ", a->creator->op); + fprintf(self->dumper.out, "%s (str) ", a->creator->op); fprintf(self->dumper.out, "%s = %s", a->name, value); @@ -444,8 +444,17 @@ static void dump_values(grib_dumper* d, grib_accessor* a) /*for(i = 0; i < d->depth ; i++) fprintf(self->dumper.out," ");*/ print_offset(self->dumper.out, self->begin, self->theEnd); - if ((d->option_flags & GRIB_DUMP_FLAG_TYPE) != 0) - fprintf(self->dumper.out, "%s ", a->creator->op); + if ((d->option_flags & GRIB_DUMP_FLAG_TYPE) != 0) { + char type_name[32] = ""; + const long native_type = grib_accessor_get_native_type(a); + if (native_type == GRIB_TYPE_LONG) + strcpy(type_name, "(int)"); + else if (native_type == GRIB_TYPE_DOUBLE) + strcpy(type_name, "(double)"); + else if (native_type == GRIB_TYPE_STRING) + strcpy(type_name, "(str)"); + fprintf(self->dumper.out, "%s %s ", a->creator->op, type_name); + } fprintf(self->dumper.out, "%s = (%ld,%ld)", a->name, (long)size, a->length); aliases(d, a); @@ -631,7 +640,7 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm if ((d->option_flags & GRIB_DUMP_FLAG_TYPE) != 0) { fprintf(self->dumper.out, " "); - fprintf(self->dumper.out, "# type %s \n", a->creator->op); + fprintf(self->dumper.out, "# type %s (str) \n", a->creator->op); } aliases(d, a);