Testing: dumping actions

This commit is contained in:
shahramn 2024-09-01 16:42:00 +01:00
parent 695627b5b1
commit fbe2d513b0
4 changed files with 54 additions and 11 deletions

View File

@ -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)

View File

@ -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)

View File

@ -12,17 +12,29 @@
#include <assert.h>
#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);

View File

@ -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