aboutsummaryrefslogtreecommitdiff
path: root/src/hdf5-file.c
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2009-12-20 20:13:00 +0100
committerThomas White <taw@bitwiz.org.uk>2009-12-20 20:13:00 +0100
commit563b05331db465e0e5ef0434de79e2cc06674d63 (patch)
tree51b38dc6958a152e9206c68a322d01316eab26de /src/hdf5-file.c
parent24ce4a9e2becccb6f7e9a15ae29ba57042ce4e2e (diff)
Show values of simple fields in menu
Diffstat (limited to 'src/hdf5-file.c')
-rw-r--r--src/hdf5-file.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/hdf5-file.c b/src/hdf5-file.c
index 9368ca0e..c1f4f70e 100644
--- a/src/hdf5-file.c
+++ b/src/hdf5-file.c
@@ -273,6 +273,77 @@ static int looks_like_image(hid_t h)
}
+char *hdfile_get_string_value(struct hdfile *f, const char *name)
+{
+ hid_t dh;
+ hid_t sh;
+ hsize_t size;
+ hsize_t max_size;
+ hid_t type;
+ hid_t class;
+
+ dh = H5Dopen(f->fh, name, H5P_DEFAULT);
+ if ( dh < 0 ) {
+ return NULL;
+ }
+
+ sh = H5Dget_space(dh);
+ if ( H5Sget_simple_extent_ndims(sh) != 1 ) {
+ return NULL;
+ }
+
+ H5Sget_simple_extent_dims(sh, &size, &max_size);
+ if ( size != 1 ) {
+ H5Dclose(dh);
+ return NULL;
+ }
+
+ type = H5Dget_type(dh);
+ class = H5Tget_class(type);
+ switch ( class ) {
+ case H5T_FLOAT : {
+
+ herr_t r;
+ double buf;
+ char *tmp;
+
+ r = H5Dread(dh, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL,
+ H5P_DEFAULT, &buf);
+ if ( r < 0 ) goto fail;
+
+ tmp = malloc(256);
+ snprintf(tmp, 255, "%f", buf);
+
+ return tmp;
+
+ }
+ case H5T_INTEGER : {
+
+ herr_t r;
+ int buf;
+ char *tmp;
+
+ r = H5Dread(dh, H5T_NATIVE_INT, H5S_ALL, H5S_ALL,
+ H5P_DEFAULT, &buf);
+ if ( r < 0 ) goto fail;
+
+ tmp = malloc(256);
+ snprintf(tmp, 255, "%d", buf);
+
+ return tmp;
+ }
+ default : {
+ goto fail;
+ }
+ }
+
+fail:
+ H5Tclose(type);
+ H5Dclose(dh);
+ return NULL;
+}
+
+
char **hdfile_read_group(struct hdfile *f, int *n, const char *parent,
int **p_is_group, int **p_is_image)
{