From fbe2d513b0a3f39a7d9135820a53ce4ab0b58d14 Mon Sep 17 00:00:00 2001 From: shahramn Date: Sun, 1 Sep 2024 16:42:00 +0100 Subject: [PATCH] Testing: dumping actions --- src/action.cc | 22 +++++++++++++++++++++- src/action_class_rename.cc | 10 +++++----- tests/codes_dump_action_tree.cc | 18 +++++++++++++++--- tests/codes_dump_action_tree.sh | 15 +++++++++++++-- 4 files changed, 54 insertions(+), 11 deletions(-) diff --git a/src/action.cc b/src/action.cc index 026bca74e..770c0b310 100644 --- a/src/action.cc +++ b/src/action.cc @@ -210,7 +210,27 @@ void grib_dump_action_tree(grib_context* ctx, FILE* out) Assert(ctx->grib_reader); Assert(ctx->grib_reader->first); Assert(out); - grib_dump_action_branch(out, ctx->grib_reader->first->root, 0); + + // grib_dump_action_branch(out, ctx->grib_reader->first->root, 0); + // grib_action* next = ctx->grib_reader->first->root; + // while (next) { + // fprintf(out, "Dump %s\n", next->name); + // grib_dump_action_branch(out, next, 0); + // next = next->next; + // } + + grib_action_file* fr = ctx->grib_reader->first; + grib_action_file* fn = fr; + while (fn) { + fr = fn; + fn = fn->next; + grib_action* a = fr->root; + while (a) { + grib_action* na = a->next; + grib_dump_action_branch(out, a, 0); + a = na; + } + } } // void grib_xref_action_branch(FILE* out, grib_action* a, const char* path) diff --git a/src/action_class_rename.cc b/src/action_class_rename.cc index 49a734bd2..631a72181 100644 --- a/src/action_class_rename.cc +++ b/src/action_class_rename.cc @@ -124,12 +124,12 @@ static int create_accessor(grib_section* p, grib_action* act, grib_loader* h) static void dump(grib_action* act, FILE* f, int lvl) { - // grib_action_rename* a = (grib_action_rename*)act; - // int i = 0; - // for (i = 0; i < lvl; i++) - // grib_context_print(act->context, f, " "); + grib_action_rename* a = (grib_action_rename*)act; + int i = 0; + for (i = 0; i < lvl; i++) + grib_context_print(act->context, f, " "); - // grib_context_print(act->context, f, "rename %s as %s in %s\n", a->the_old, act->name, a->the_new); + grib_context_print(act->context, f, "rename %s as %s in %s\n", a->the_old, act->name, a->the_new); } static void destroy(grib_context* context, grib_action* act) diff --git a/tests/codes_dump_action_tree.cc b/tests/codes_dump_action_tree.cc index fa895ea97..724b957e2 100644 --- a/tests/codes_dump_action_tree.cc +++ b/tests/codes_dump_action_tree.cc @@ -12,17 +12,29 @@ #include #include "eccodes.h" +static ProductKind get_product_kind(const char* p) +{ + if (strcmp(p, "GRIB") == 0) return PRODUCT_GRIB; + if (strcmp(p, "BUFR") == 0) return PRODUCT_BUFR; + if (strcmp(p, "METAR") == 0) return PRODUCT_METAR; + if (strcmp(p, "GTS") == 0) return PRODUCT_GTS; + return PRODUCT_ANY; +} + int main(int argc, char** argv) { int err = 0; codes_context* c = codes_context_get_default(); - assert(argc == 2); + assert(argc == 3); + + const ProductKind mode = get_product_kind( argv[1] ); + const char* filename = argv[2]; - char* filename = argv[1]; FILE* fp = fopen(filename, "rb"); assert(fp); - codes_handle* h = codes_handle_new_from_file(c, fp, PRODUCT_ANY, &err); + + codes_handle* h = codes_handle_new_from_file(c, fp, mode, &err); assert(h); assert(!err); diff --git a/tests/codes_dump_action_tree.sh b/tests/codes_dump_action_tree.sh index ad562c9e5..fbc2bbf24 100755 --- a/tests/codes_dump_action_tree.sh +++ b/tests/codes_dump_action_tree.sh @@ -10,5 +10,16 @@ . ./include.ctest.sh -input=$ECCODES_SAMPLES_PATH/GRIB2.tmpl -$EXEC ${test_dir}/codes_dump_action_tree "$input" +for f in GRIB1.tmpl GRIB2.tmpl sh_sfc_grib1.tmpl sh_sfc_grib2.tmpl; do + input=$ECCODES_SAMPLES_PATH/$f + $EXEC ${test_dir}/codes_dump_action_tree GRIB "$input" > /dev/null +done + +input=$ECCODES_SAMPLES_PATH/BUFR4.tmpl +$EXEC ${test_dir}/codes_dump_action_tree BUFR "$input" > /dev/null + +input=$data_dir/metar/metar.txt +$EXEC ${test_dir}/codes_dump_action_tree METAR "$input" > /dev/null + +input=$data_dir/gts/EGRR20150317121020_00493212.DAT +$EXEC ${test_dir}/codes_dump_action_tree GTS "$input" > /dev/null