aboutsummaryrefslogtreecommitdiff
path: root/src/hdf5-file.c
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2009-12-16 22:37:19 -0800
committerThomas White <taw@bitwiz.org.uk>2009-12-16 22:37:19 -0800
commit5dc417886b5bb36b43d9354672cfc9e2a2b29512 (patch)
tree2e980b98cd9c3506ab279a2d22680fc9463774f4 /src/hdf5-file.c
parenta372a83f4d1abb6ad6cca90f6ceb108cb4d7664a (diff)
Walk HDF groups to display a menu and switch image
Diffstat (limited to 'src/hdf5-file.c')
-rw-r--r--src/hdf5-file.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/hdf5-file.c b/src/hdf5-file.c
index ea3b91f7..0d211998 100644
--- a/src/hdf5-file.c
+++ b/src/hdf5-file.c
@@ -248,3 +248,57 @@ int hdf5_read(struct hdfile *f, struct image *image)
return 0;
}
+
+
+char **hdfile_walk_tree(struct hdfile *f, int *n, const char *parent,
+ int **p_is_group, int **p_is_image)
+{
+ hid_t gh;
+ hsize_t num;
+ char **res;
+ int i;
+ int *is_group;
+ int *is_image;
+
+ gh = H5Gopen(f->fh, parent, H5P_DEFAULT);
+ if ( gh < 0 ) {
+ *n = 0;
+ return NULL;
+ }
+
+ if ( H5Gget_num_objs(gh, &num) < 0 ) {
+ /* Whoopsie */
+ *n = 0;
+ return NULL;
+ }
+ *n = num;
+ if ( num == 0 ) return NULL; /* Bail out now */
+
+ res = malloc(num*sizeof(char *));
+ is_image = malloc(num*sizeof(int));
+ is_group = malloc(num*sizeof(int));
+ *p_is_image = is_image;
+ *p_is_group = is_group;
+
+ for ( i=0; i<num; i++ ) {
+
+ char buf[256];
+ int type;
+
+ H5Gget_objname_by_idx(gh, i, buf, 255);
+ res[i] = strdup(buf);
+
+ type = H5Gget_objtype_by_idx(gh, i);
+ is_image[i] = 0;
+ is_group[i] = 0;
+ if ( type == H5G_GROUP ) {
+ is_group[i] = 1;
+ } else if ( type == H5G_DATASET ) {
+ /* FIXME: Check better */
+ is_image[i] = 1;
+ }
+
+ }
+
+ return res;
+}