mirror of https://github.com/ecmwf/eccodes.git
Index dump: print out filenames
This commit is contained in:
parent
06233f2ebd
commit
84c1c085fb
|
@ -587,6 +587,7 @@ int grib_index_select_string(grib_index *index, const char *skey, char *value);
|
|||
grib_handle *grib_index_get_handle(grib_field *field, int *err);
|
||||
grib_handle *codes_index_get_handle(grib_field *field, int message_type, int *err);
|
||||
void grib_index_dump(FILE *fout, grib_index *index);
|
||||
int grib_index_dump_file(FILE* fout, const char* filename);
|
||||
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);
|
||||
|
|
|
@ -1504,13 +1504,6 @@ static int grib_index_execute(grib_index* index)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void grib_dump_files(FILE* fout, grib_file* files)
|
||||
{
|
||||
if (!files) return;
|
||||
fprintf(fout, "file = %s\n", files->name);
|
||||
fprintf(fout, "ID = %d\n", files->id);
|
||||
grib_dump_files(fout, files->next);
|
||||
}
|
||||
static void grib_dump_key_values(FILE* fout, grib_string_list* values)
|
||||
{
|
||||
grib_string_list* sl = values;
|
||||
|
@ -1536,6 +1529,13 @@ static void grib_dump_index_keys(FILE* fout, grib_index_key* keys)
|
|||
grib_dump_index_keys(fout, keys->next);
|
||||
}
|
||||
#if 0
|
||||
static void grib_dump_files(FILE* fout, grib_file* files)
|
||||
{
|
||||
if (!files) return;
|
||||
fprintf(fout, "file = %s\n", files->name);
|
||||
fprintf(fout, "ID = %d\n", files->id);
|
||||
grib_dump_files(fout, files->next);
|
||||
}
|
||||
static void grib_dump_field(FILE* fout, grib_field* field)
|
||||
{
|
||||
if (!field) return;
|
||||
|
@ -1559,32 +1559,62 @@ static void grib_dump_field_tree(FILE* fout, grib_field_tree* tree)
|
|||
}
|
||||
#endif
|
||||
|
||||
int grib_index_dump_file(FILE* fout, const char* filename)
|
||||
{
|
||||
int err = 0;
|
||||
grib_index* index = NULL;
|
||||
grib_context* c = grib_context_get_default();
|
||||
FILE* fh = NULL;
|
||||
|
||||
Assert(fout);
|
||||
Assert(filename);
|
||||
index = grib_index_read(c, filename, &err);
|
||||
if (err) return err;
|
||||
|
||||
/* To get the GRIB files referenced we have */
|
||||
/* to resort to low level reading of the index file! */
|
||||
fh=fopen(filename,"r");
|
||||
if (fh) {
|
||||
grib_file *file,*f;
|
||||
char* identifier=NULL;
|
||||
unsigned char marker=0;
|
||||
|
||||
identifier = grib_read_string(c,fh,&err);
|
||||
if (err) return err;
|
||||
grib_context_free(c,identifier);
|
||||
err = grib_read_uchar(fh,&marker);
|
||||
if (err) return err;
|
||||
file = grib_read_files(c,fh,&err);
|
||||
if (err) return err;
|
||||
f=file;
|
||||
while (f) {
|
||||
fprintf(fout, "GRIB File: %s\n", f->name);
|
||||
f=f->next;
|
||||
}
|
||||
fclose(fh);
|
||||
}
|
||||
|
||||
grib_index_dump(fout, index);
|
||||
grib_index_delete(index);
|
||||
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
void grib_index_dump(FILE* fout, grib_index* index)
|
||||
{
|
||||
char* field_file = NULL;
|
||||
grib_field_tree* ftree = NULL;
|
||||
|
||||
if (!index) return;
|
||||
Assert(fout);
|
||||
|
||||
grib_dump_files(fout, index->files);
|
||||
|
||||
ftree = index->fields;
|
||||
if (ftree) {
|
||||
grib_field* fld = ftree->field;
|
||||
if (fld) {
|
||||
grib_file* file = fld->file;
|
||||
field_file = file->name;
|
||||
}
|
||||
}
|
||||
if (field_file) fprintf(fout, "Field file: %s\n", field_file);
|
||||
/* The grib_dump_files does not print anything as */
|
||||
/* the index object does not store the file names! */
|
||||
/* grib_dump_files(fout, index->files); */
|
||||
|
||||
fprintf(fout, "Index keys:\n");
|
||||
grib_dump_index_keys(fout, index->keys);
|
||||
|
||||
/*
|
||||
fprintf(fout, "Index field tree:\n");
|
||||
grib_dump_field_tree(fout, index->fields);
|
||||
* fprintf(fout, "Index field tree:\n");
|
||||
* grib_dump_field_tree(fout, index->fields);
|
||||
*/
|
||||
|
||||
fprintf(fout, "Index count = %d\n", index->count);
|
||||
|
@ -1664,7 +1694,6 @@ grib_handle* codes_new_from_index(grib_index* index,int message_type,int *err)
|
|||
h=codes_index_get_handle(index->current->field,message_type,err);
|
||||
}
|
||||
return h;
|
||||
|
||||
}
|
||||
|
||||
void grib_index_rewind(grib_index* index)
|
||||
|
|
|
@ -129,7 +129,7 @@ int grib_tool_new_file_action(grib_runtime_options* options,grib_tools_file* fil
|
|||
fprintf(stdout,"***** %s\n",tmp);
|
||||
|
||||
/*
|
||||
* In debug dump mode, allow dumping of GRIB INDEX files
|
||||
* In debug dump mode, allow dumping of GRIB index files
|
||||
*/
|
||||
if (strcmp(options->dump_mode, "debug")==0)
|
||||
{
|
||||
|
@ -138,15 +138,15 @@ int grib_tool_new_file_action(grib_runtime_options* options,grib_tools_file* fil
|
|||
int err = 0;
|
||||
grib_context* c = grib_context_get_default();
|
||||
const char* filename = options->current_infile->name;
|
||||
grib_index* index = grib_index_read(c, filename, &err);
|
||||
if (err || index == NULL) {
|
||||
grib_context_log(c, GRIB_LOG_ERROR, "%s: Could not read index file. %s\n",
|
||||
grib_tool_name, grib_get_error_message(err));
|
||||
|
||||
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);
|
||||
}
|
||||
grib_index_dump(stdout, index);
|
||||
grib_index_delete(index);
|
||||
index = NULL;
|
||||
/* Since there are no GRIB messages, we have to stop tool exiting in case there
|
||||
* are more index files
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue