aboutsummaryrefslogtreecommitdiff
path: root/src/hdf5-file.c
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2011-02-28 10:42:35 +0100
committerThomas White <taw@physics.org>2012-02-22 15:27:16 +0100
commite5ff1c404c096d97d665b7c6e897d4d8be5617f6 (patch)
treef50f96aad6eee1db51a11eee06153507d076665a /src/hdf5-file.c
parente5709dd5d7269730fca2776785675e2deea1045b (diff)
Get camera length from HDF5 if required
Diffstat (limited to 'src/hdf5-file.c')
-rw-r--r--src/hdf5-file.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/hdf5-file.c b/src/hdf5-file.c
index 33d3f95a..313489e4 100644
--- a/src/hdf5-file.c
+++ b/src/hdf5-file.c
@@ -475,6 +475,62 @@ static int looks_like_image(hid_t h)
}
+double get_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;
+ herr_t r;
+ double buf;
+
+ dh = H5Dopen2(f->fh, name, H5P_DEFAULT);
+ if ( dh < 0 ) {
+ ERROR("Couldn't open data\n");
+ return 0.0;
+ }
+
+ type = H5Dget_type(dh);
+ class = H5Tget_class(type);
+
+ if ( class != H5T_FLOAT ) {
+ ERROR("Not a floating point value.\n");
+ H5Tclose(type);
+ H5Dclose(dh);
+ return 0.0;
+ }
+
+ sh = H5Dget_space(dh);
+ if ( H5Sget_simple_extent_ndims(sh) != 1 ) {
+ ERROR("Not a scalar value.\n");
+ H5Tclose(type);
+ H5Dclose(dh);
+ return 0.0;
+ }
+
+ H5Sget_simple_extent_dims(sh, &size, &max_size);
+ if ( size != 1 ) {
+ ERROR("Not a scalar value.\n");
+ H5Tclose(type);
+ H5Dclose(dh);
+ return 0.0;
+ }
+
+ r = H5Dread(dh, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL,
+ H5P_DEFAULT, &buf);
+ if ( r < 0 ) {
+ ERROR("Couldn't read value.\n");
+ H5Tclose(type);
+ H5Dclose(dh);
+ return 0.0;
+ }
+
+ return buf;
+}
+
+
char *hdfile_get_string_value(struct hdfile *f, const char *name)
{
hid_t dh;