Dumper: add default value info (Debug mode)

This commit is contained in:
Shahram Najm 2023-12-06 17:11:33 +00:00
parent 937d2fa737
commit 8b2d4c45f5
1 changed files with 52 additions and 0 deletions

View File

@ -100,6 +100,57 @@ static int destroy(grib_dumper* d)
return GRIB_SUCCESS; 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) static void aliases(grib_dumper* d, grib_accessor* a)
{ {
int i; 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)); fprintf(self->dumper.out, " *** ERR=%d (%s) [grib_dumper_debug::dump_long]", err, grib_get_error_message(err));
aliases(d, a); aliases(d, a);
default_long_value(d, a, value);
fprintf(self->dumper.out, "\n"); fprintf(self->dumper.out, "\n");
} }