diff options
author | Thomas White <taw@bitwiz.org.uk> | 2009-12-16 23:40:50 -0800 |
---|---|---|
committer | Thomas White <taw@bitwiz.org.uk> | 2009-12-16 23:40:50 -0800 |
commit | df11539ba7f709f4fe71181c09f993b916167e32 (patch) | |
tree | 3c4a5f0cc5b9e723dd8a69995688f08afa61cbdd | |
parent | a543ce3927194906b4d7b14c3dc36edfe717fdba (diff) |
Walk the HDF group tree to find the first image
-rw-r--r-- | src/displaywindow.c | 11 | ||||
-rw-r--r-- | src/hdf5-file.c | 32 | ||||
-rw-r--r-- | src/hdf5-file.h | 1 |
3 files changed, 35 insertions, 9 deletions
diff --git a/src/displaywindow.c b/src/displaywindow.c index b27ca35f..26b2b66f 100644 --- a/src/displaywindow.c +++ b/src/displaywindow.c @@ -666,17 +666,13 @@ static GtkWidget *displaywindow_addhdfgroup(struct hdfile *hdfile, if ( names[i] != NULL ) { - char subgroup[1024]; - item = gtk_menu_item_new_with_label(names[i]); gtk_menu_shell_append(GTK_MENU_SHELL(ms), item); gtk_widget_show(item); if ( is_group[i] ) { - snprintf(subgroup, 1023, "%s/%s", - group, names[i]); sub = displaywindow_addhdfgroup(hdfile, - subgroup, dw); + names[i], dw); gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), sub); } else if ( is_image[i] ) { @@ -685,8 +681,7 @@ static GtkWidget *displaywindow_addhdfgroup(struct hdfile *hdfile, nh = malloc(sizeof(struct newhdf)); if ( nh != NULL ) { - snprintf(nh->name, 1023, "%s/%s", group, - names[i]); + strncpy(nh->name, names[i], 1023); nh->dw = dw; g_signal_connect(G_OBJECT(item), "activate", @@ -874,7 +869,7 @@ DisplayWindow *displaywindow_open(const char *filename) if ( dw->hdfile == NULL ) { fprintf(stderr, "Couldn't open file '%s'\n", filename); displaywindow_disable(dw); - } else if ( hdfile_set_image(dw->hdfile, "/data/data") ) { + } else if ( hdfile_set_first_image(dw->hdfile, "/") ) { fprintf(stderr, "Couldn't select path\n"); displaywindow_disable(dw); } 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; +} diff --git a/src/hdf5-file.h b/src/hdf5-file.h index a7e0f89e..1e00a8d1 100644 --- a/src/hdf5-file.h +++ b/src/hdf5-file.h @@ -38,6 +38,7 @@ extern int hdfile_get_unbinned_value(struct hdfile *f, int x, int y, int16_t *val); extern char **hdfile_walk_tree(struct hdfile *f, int *n, const char *parent, int **p_is_group, int **p_is_image); +extern int hdfile_set_first_image(struct hdfile *f, const char *group); extern void hdfile_close(struct hdfile *f); #endif /* HDF5_H */ |