From 6f53da8b06099d764763afd994e53c75aa162aee Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Tue, 29 Jan 2019 04:06:41 +0100 Subject: [PATCH] [file_hdf5] add list routine --- src/io/file_hdf5.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ src/io/file_hdf5.h | 2 ++ 2 files changed, 51 insertions(+) diff --git a/src/io/file_hdf5.c b/src/io/file_hdf5.c index cd5a26e2..e3d3c5f9 100644 --- a/src/io/file_hdf5.c +++ b/src/io/file_hdf5.c @@ -35,6 +35,8 @@ #define aubio_H5LTread_dataset_smpl H5LTread_dataset_double #endif +#define MAX_DEPTH 100 + struct _aubio_file_hdf5_t { const char_t *path; hid_t fid; @@ -48,7 +50,12 @@ aubio_file_hdf5_t *new_aubio_file_hdf5(const char_t *path) f->fid = H5Fopen(path, H5F_ACC_RDONLY, H5P_DEFAULT); if (f->fid <= 0) goto failure; + // TODO keep a copy f->path = path; + + //AUBIO_DBG("file_hdf5: opened %s\n", f->path); + //aubio_file_hdf5_list(f); + return f; failure: @@ -120,6 +127,48 @@ uint_t aubio_file_hdf5_load_dataset_into_vector(aubio_file_hdf5_t *f, return aubio_file_hdf5_load_dataset_into_tensor(f, key, &t); } +static herr_t aubio_file_hdf5_iterate(hid_t loc_id, const char *name, + const H5L_info_t *info UNUSED, void *opdata) +{ + H5O_info_t infobuf; + const char_t *type_name; + uint_t *depth = (uint_t *)opdata; + herr_t err = H5Oget_info_by_name(loc_id, name, &infobuf, H5P_DEFAULT); + if (err < 0) goto failure; + if (*depth > MAX_DEPTH) goto failure; + switch (infobuf.type) { + case H5O_TYPE_GROUP: + type_name = "group"; + break; + case H5O_TYPE_DATASET: + type_name = "dataset"; + break; + case H5O_TYPE_NAMED_DATATYPE: + type_name = "datatype"; + break; + default: + type_name = "unknown"; + break; + } + AUBIO_MSG("%*s %s (%s)\n", *depth, "-", name, type_name); + if (infobuf.type == H5O_TYPE_GROUP) { + uint_t d = *depth + 1; + err = H5Literate_by_name(loc_id, name, H5_INDEX_NAME, H5_ITER_NATIVE, + NULL, aubio_file_hdf5_iterate, &d, H5P_DEFAULT); + } +failure: + return err; +} + +void aubio_file_hdf5_list(aubio_file_hdf5_t *f) +{ + uint_t depth = 1; + herr_t err = H5Literate(f->fid, H5_INDEX_NAME, H5_ITER_NATIVE, + NULL, aubio_file_hdf5_iterate, &depth); + if (err < 0) + AUBIO_ERR("file_hdf5: failed iterating into %s\n", f->path); +} + void del_aubio_file_hdf5(aubio_file_hdf5_t *f) { AUBIO_ASSERT(f); diff --git a/src/io/file_hdf5.h b/src/io/file_hdf5.h index 333700a7..5c7edaee 100644 --- a/src/io/file_hdf5.h +++ b/src/io/file_hdf5.h @@ -27,6 +27,8 @@ aubio_file_hdf5_t *new_aubio_file_hdf5(const char_t *path); void del_aubio_file_hdf5(aubio_file_hdf5_t *f); +void aubio_file_hdf5_list(aubio_file_hdf5_t *f); + uint_t aubio_file_hdf5_load_dataset_into_tensor (aubio_file_hdf5_t *f, const char_t *key, aubio_tensor_t *tensor); -- 2.11.0