diff --git a/src/grib_dumper_class_debug.cc b/src/grib_dumper_class_debug.cc index 79c1ea29c..97496b43c 100644 --- a/src/grib_dumper_class_debug.cc +++ b/src/grib_dumper_class_debug.cc @@ -100,6 +100,57 @@ static int destroy(grib_dumper* d) return GRIB_SUCCESS; } +static void default_long_value(grib_dumper* d, grib_accessor* a, long actualValue) +{ + grib_dumper_debug* self = (grib_dumper_debug*)d; + grib_action* act = a->creator; + if (act->default_value == NULL) + return; + + grib_handle* h = grib_handle_of_accessor(a); + grib_expression* expression = grib_arguments_get_expression(h, act->default_value, 0); + if (!expression) + return; + + const int type = grib_expression_native_type(h, expression); + DEBUG_ASSERT(type == GRIB_TYPE_LONG); + + if (type == GRIB_TYPE_LONG) { + long defaultValue = 0; + if (grib_expression_evaluate_long(h, expression, &defaultValue) == GRIB_SUCCESS && defaultValue != actualValue) { + if (defaultValue == GRIB_MISSING_LONG) + fprintf(self->dumper.out, " (default=MISSING)"); + else + fprintf(self->dumper.out, " (default=%ld)",defaultValue); + } + } +} + +// static void default_string_value(grib_dumper* d, grib_accessor* a, const char* actualValue) +// { +// grib_dumper_debug* self = (grib_dumper_debug*)d; +// grib_action* act = a->creator; +// if (act->default_value == NULL) +// return; + +// grib_handle* h = grib_handle_of_accessor(a); +// grib_expression* expression = grib_arguments_get_expression(h, act->default_value, 0); +// if (!expression) +// return; + +// const int type = grib_expression_native_type(h, expression); +// DEBUG_ASSERT(type == GRIB_TYPE_STRING); +// if (type == GRIB_TYPE_STRING) { +// char tmp[1024] = {0,}; +// size_t s_len = sizeof(tmp); +// int err = 0; +// const char* p = grib_expression_evaluate_string(h, expression, tmp, &s_len, &err); +// if (!err && !STR_EQUAL(p, actualValue)) { +// fprintf(self->dumper.out, " (default=%s)", p); +// } +// } +// } + static void aliases(grib_dumper* d, grib_accessor* a) { int i; @@ -202,6 +253,7 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) fprintf(self->dumper.out, " *** ERR=%d (%s) [grib_dumper_debug::dump_long]", err, grib_get_error_message(err)); aliases(d, a); + default_long_value(d, a, value); fprintf(self->dumper.out, "\n"); }