ECC-1748: Tools: grib_dump on index file should print the key types

This commit is contained in:
Shahram Najm 2024-01-17 13:49:36 +00:00
parent c9fd7006d5
commit 77a71acf11
5 changed files with 21 additions and 12 deletions

View File

@ -652,8 +652,8 @@ int grib_index_select_long(grib_index* index, const char* skey, long value);
int grib_index_select_double(grib_index* index, const char* skey, double value);
int grib_index_select_string(grib_index* index, const char* skey, const char* value);
grib_handle* codes_index_get_handle(grib_field* field, int message_type, int* err);
int grib_index_dump_file(FILE* fout, const char* filename);
void grib_index_dump(FILE* fout, grib_index* index);
int grib_index_dump_file(FILE* fout, const char* filename, unsigned long flags);
void grib_index_dump(FILE* fout, grib_index* index, unsigned long flags);
char* grib_get_field_file(grib_index* index, off_t* offset);
grib_handle* grib_handle_new_from_index(grib_index* index, int* err);
grib_handle* codes_new_from_index(grib_index* index, int message_type, int* err);

View File

@ -1739,16 +1739,19 @@ static void grib_dump_key_values(FILE* fout, grib_string_list* values)
}
fprintf(fout, "\n");
}
static void grib_dump_index_keys(FILE* fout, grib_index_key* keys)
static void grib_dump_index_keys(FILE* fout, grib_index_key* keys, unsigned long flags)
{
if (!keys)
return;
fprintf(fout, "key name = %s\n", keys->name);
/* fprintf(fout, "key type = %d\n", keys->type); */
if ((flags & GRIB_DUMP_FLAG_TYPE) != 0) {
fprintf(fout, "key type = %s\n", grib_get_type_name(keys->type));
}
grib_dump_key_values(fout, keys->values);
grib_dump_index_keys(fout, keys->next);
grib_dump_index_keys(fout, keys->next, flags);
}
#ifdef INDEX_DUMPS
static void grib_dump_files(FILE* fout, grib_file* files)
{
@ -1780,7 +1783,7 @@ static void grib_dump_field_tree(FILE* fout, grib_field_tree* tree)
}
#endif
int grib_index_dump_file(FILE* fout, const char* filename)
int grib_index_dump_file(FILE* fout, const char* filename, unsigned long flags)
{
int err = 0;
grib_index* index = NULL;
@ -1821,13 +1824,13 @@ int grib_index_dump_file(FILE* fout, const char* filename)
fclose(fh);
}
grib_index_dump(fout, index);
grib_index_dump(fout, index, flags);
grib_index_delete(index);
return GRIB_SUCCESS;
}
void grib_index_dump(FILE* fout, grib_index* index)
void grib_index_dump(FILE* fout, grib_index* index, unsigned long flags)
{
if (!index)
return;
@ -1838,7 +1841,7 @@ void grib_index_dump(FILE* fout, grib_index* index)
/* grib_dump_files(fout, index->files); */
fprintf(fout, "Index keys:\n");
grib_dump_index_keys(fout, index->keys);
grib_dump_index_keys(fout, index->keys, flags);
/*
* fprintf(fout, "Index field tree:\n");

View File

@ -91,6 +91,12 @@ EOF
diff $tempRef $tempOut
# ECC-1748
${tools_dir}/grib_dump -t ${tempIndex} > $tempOut
grep -q "key type = string" $tempOut
grep -q "key type = long" $tempOut
${tools_dir}/grib_index_build -N -k mars.levtype -o $tempIndex ${data_dir}/tigge_cf_ecmwf.grib2 |\
grep -q "mars.levtype = { sfc, pl, pv, pt }"

View File

@ -189,7 +189,7 @@ int grib_tool_new_file_action(grib_runtime_options* options, grib_tools_file* fi
const char* filename = options->current_infile->name;
json = 0;
err = grib_index_dump_file(stdout, filename);
err = grib_index_dump_file(stdout, filename, options->dump_flags);
if (err) {
grib_context_log(c, GRIB_LOG_ERROR, "%s: Could not dump index file \"%s\".\n%s\n",
tool_name,

View File

@ -141,7 +141,7 @@ int grib_tool_new_file_action(grib_runtime_options* options, grib_tools_file* fi
grib_context* c = grib_context_get_default();
const char* filename = options->current_infile->name;
err = grib_index_dump_file(stdout, filename);
err = grib_index_dump_file(stdout, filename, options->dump_flags);
if (err) {
grib_context_log(c, GRIB_LOG_ERROR, "%s: Could not dump index file \"%s\".\n%s\n",
tool_name,