From df11539ba7f709f4fe71181c09f993b916167e32 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 16 Dec 2009 23:40:50 -0800 Subject: Walk the HDF group tree to find the first image --- src/hdf5-file.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'src/hdf5-file.c') diff --git a/src/hdf5-file.c b/src/hdf5-file.c index 0d211998..c6732e9b 100644 --- a/src/hdf5-file.c +++ b/src/hdf5-file.c @@ -286,7 +286,12 @@ char **hdfile_walk_tree(struct hdfile *f, int *n, const char *parent, int type; H5Gget_objname_by_idx(gh, i, buf, 255); - res[i] = strdup(buf); + res[i] = malloc(256); + if ( strlen(parent) > 1 ) { + snprintf(res[i], 255, "%s/%s", parent, buf); + } else { + snprintf(res[i], 255, "%s%s", parent, buf); + } /* ick */ type = H5Gget_objtype_by_idx(gh, i); is_image[i] = 0; @@ -302,3 +307,28 @@ char **hdfile_walk_tree(struct hdfile *f, int *n, const char *parent, return res; } + + +int hdfile_set_first_image(struct hdfile *f, const char *group) +{ + char **names; + int *is_group; + int *is_image; + int n, i; + + names = hdfile_walk_tree(f, &n, group, &is_group, &is_image); + if ( n == 0 ) return 1; + + for ( i=0; i