diff options
author | Thomas White <taw@bitwiz.org.uk> | 2009-12-21 00:32:03 +0100 |
---|---|---|
committer | Thomas White <taw@bitwiz.org.uk> | 2009-12-21 00:32:03 +0100 |
commit | 2bb5a67454a3e5743b7571cae178553fb804e750 (patch) | |
tree | 2122b78b13f2b32a8484c3ae0afbfa2fa6bb0614 /src/hdf5-file.c | |
parent | 563b05331db465e0e5ef0434de79e2cc06674d63 (diff) |
Show the values of string datasets as well
Diffstat (limited to 'src/hdf5-file.c')
-rw-r--r-- | src/hdf5-file.c | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/src/hdf5-file.c b/src/hdf5-file.c index c1f4f70e..bd30ff7d 100644 --- a/src/hdf5-file.c +++ b/src/hdf5-file.c @@ -21,6 +21,7 @@ #include "image.h" #include "hdf5-file.h" +#include "utils.h" struct hdfile { @@ -283,23 +284,44 @@ char *hdfile_get_string_value(struct hdfile *f, const char *name) hid_t class; dh = H5Dopen(f->fh, name, H5P_DEFAULT); - if ( dh < 0 ) { - return NULL; + if ( dh < 0 ) return NULL; + + type = H5Dget_type(dh); + class = H5Tget_class(type); + + if ( class == H5T_STRING ) { + + herr_t r; + char *tmp; + hid_t th; + hsize_t size; + + size = H5Dget_storage_size(dh); + + tmp = malloc(size+1); + + th = H5Tcopy(H5T_C_S1); + H5Tset_size(th, size+1); + + r = H5Dread(dh, th, H5S_ALL, H5S_ALL, H5P_DEFAULT, tmp); + if ( r < 0 ) goto fail; + + tmp[size] = '\0'; + chomp(tmp); + + return tmp; + } sh = H5Dget_space(dh); - if ( H5Sget_simple_extent_ndims(sh) != 1 ) { - return NULL; - } + if ( H5Sget_simple_extent_ndims(sh) != 1 ) goto fail; H5Sget_simple_extent_dims(sh, &size, &max_size); if ( size != 1 ) { H5Dclose(dh); - return NULL; + goto fail; } - type = H5Dget_type(dh); - class = H5Tget_class(type); switch ( class ) { case H5T_FLOAT : { |