Indexing: allow dump on index file

This commit is contained in:
Shahram Najm 2020-07-17 15:15:32 +01:00
parent e1d4c60c37
commit 2c0f6bc9da
2 changed files with 43 additions and 18 deletions

View File

@ -186,6 +186,32 @@ int grib_tool_new_file_action(grib_runtime_options* options, grib_tools_file* fi
{
if (!options->current_infile->name)
return 0;
Assert(file);
exit_if_input_is_directory(grib_tool_name, file->name);
/*
* Dumping of index files
*/
if (is_index_file(options->current_infile->name)) {
int err = 0;
grib_context* c = grib_context_get_default();
const char* filename = options->current_infile->name;
err = grib_index_dump_file(stdout, filename);
if (err) {
grib_context_log(c, GRIB_LOG_ERROR, "%s: Could not dump index file \"%s\".\n%s\n",
grib_tool_name,
filename,
grib_get_error_message(err));
exit(1);
}
/* Since there are no BUFR messages, we have to stop tool exiting in case there
* are more index files */
options->fail = 0;
return 0;
}
if (json)
return 0;

View File

@ -129,6 +129,7 @@ int grib_tool_new_file_action(grib_runtime_options* options, grib_tools_file* fi
if (json)
return 0;
Assert(file);
exit_if_input_is_directory(grib_tool_name, file->name);
sprintf(tmp, "FILE: %s ", options->current_infile->name);
@ -136,28 +137,26 @@ int grib_tool_new_file_action(grib_runtime_options* options, grib_tools_file* fi
fprintf(stdout, "***** %s\n", tmp);
/*
* In debug dump mode, allow dumping of GRIB index files
* Dumping of index files
*/
if (strcmp(options->dump_mode, "debug") == 0) {
if (is_index_file(options->current_infile->name)) {
int err = 0;
grib_context* c = grib_context_get_default();
const char* filename = options->current_infile->name;
if (is_index_file(options->current_infile->name)) {
int err = 0;
grib_context* c = grib_context_get_default();
const char* filename = options->current_infile->name;
err = grib_index_dump_file(stdout, filename);
if (err) {
grib_context_log(c, GRIB_LOG_ERROR, "%s: Could not dump index file \"%s\".\n%s\n",
grib_tool_name,
filename,
grib_get_error_message(err));
exit(1);
}
/* Since there are no GRIB messages, we have to stop tool exiting in case there
* are more index files
*/
options->fail = 0;
err = grib_index_dump_file(stdout, filename);
if (err) {
grib_context_log(c, GRIB_LOG_ERROR, "%s: Could not dump index file \"%s\".\n%s\n",
grib_tool_name,
filename,
grib_get_error_message(err));
exit(1);
}
/* Since there are no GRIB messages, we have to stop tool exiting in case there
* are more index files */
options->fail = 0;
}
return 0;
}