aboutsummaryrefslogtreecommitdiff
path: root/src/hdf5-file.c
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2009-12-16 23:40:50 -0800
committerThomas White <taw@bitwiz.org.uk>2009-12-16 23:40:50 -0800
commitdf11539ba7f709f4fe71181c09f993b916167e32 (patch)
tree3c4a5f0cc5b9e723dd8a69995688f08afa61cbdd /src/hdf5-file.c
parenta543ce3927194906b4d7b14c3dc36edfe717fdba (diff)
Walk the HDF group tree to find the first image
Diffstat (limited to 'src/hdf5-file.c')
-rw-r--r--src/hdf5-file.c32
1 files changed, 31 insertions, 1 deletions
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<n; i++ ) {
+
+ if ( is_image[i] ) {
+ hdfile_set_image(f, names[i]);
+ return 0;
+ } else if ( is_group[i] ) {
+ return hdfile_set_first_image(f, names[i]);
+ }
+
+ }
+
+ return 1;
+}