diff options
author | Thomas White <taw@physics.org> | 2011-02-28 10:42:35 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2012-02-22 15:27:16 +0100 |
commit | e5ff1c404c096d97d665b7c6e897d4d8be5617f6 (patch) | |
tree | f50f96aad6eee1db51a11eee06153507d076665a | |
parent | e5709dd5d7269730fca2776785675e2deea1045b (diff) |
Get camera length from HDF5 if required
-rw-r--r-- | doc/examples/cspad-feb2011.geom | 129 | ||||
-rw-r--r-- | src/detector.c | 35 | ||||
-rw-r--r-- | src/detector.h | 19 | ||||
-rw-r--r-- | src/displaywindow.c | 1 | ||||
-rw-r--r-- | src/hdf5-file.c | 56 | ||||
-rw-r--r-- | src/hdf5-file.h | 1 |
6 files changed, 169 insertions, 72 deletions
diff --git a/doc/examples/cspad-feb2011.geom b/doc/examples/cspad-feb2011.geom index e6448293..94bf94fe 100644 --- a/doc/examples/cspad-feb2011.geom +++ b/doc/examples/cspad-feb2011.geom @@ -8,7 +8,7 @@ n_panels = 64 0/badrow_direction = - 0/res = 9090.91 0/peak_sep = 6.0 -0/clen = 77.0e-3 +0/clen = /LCLS/detectorPosition 0/fs = +y 0/ss = -x 0/corner_x = 429.39 @@ -23,7 +23,7 @@ n_panels = 64 1/badrow_direction = - 1/res = 9090.91 1/peak_sep = 6.0 -1/clen = 77.0e-3 +1/clen = /LCLS/detectorPosition 1/fs = +y 1/ss = -x 1/corner_x = 429.39 @@ -38,7 +38,7 @@ n_panels = 64 2/badrow_direction = - 2/res = 9090.91 2/peak_sep = 6.0 -2/clen = 77.0e-3 +2/clen = /LCLS/detectorPosition 2/fs = -x 2/ss = -y 2/corner_x = 17.36 @@ -53,7 +53,7 @@ n_panels = 64 3/badrow_direction = - 3/res = 9090.91 3/peak_sep = 6.0 -3/clen = 77.0e-3 +3/clen = /LCLS/detectorPosition 3/fs = -x 3/ss = -y 3/corner_x = -181.64 @@ -68,7 +68,7 @@ n_panels = 64 4/badrow_direction = - 4/res = 9090.91 4/peak_sep = 6.0 -4/clen = 77.0e-3 +4/clen = /LCLS/detectorPosition 4/fs = -y 4/ss = +x 4/corner_x = -428.12 @@ -83,7 +83,7 @@ n_panels = 64 5/badrow_direction = - 5/res = 9090.91 5/peak_sep = 6.0 -5/clen = 77.0e-3 +5/clen = /LCLS/detectorPosition 5/fs = -y 5/ss = +x 5/corner_x = -428.12 @@ -98,7 +98,7 @@ n_panels = 64 6/badrow_direction = - 6/res = 9090.91 6/peak_sep = 6.0 -6/clen = 77.0e-3 +6/clen = /LCLS/detectorPosition 6/fs = +x 6/ss = +y 6/corner_x = -14.95 @@ -113,7 +113,7 @@ n_panels = 64 7/badrow_direction = - 7/res = 9090.91 7/peak_sep = 6.0 -7/clen = 77.0e-3 +7/clen = /LCLS/detectorPosition 7/fs = +x 7/ss = +y 7/corner_x = 184.05 @@ -128,7 +128,7 @@ n_panels = 64 8/badrow_direction = - 8/res = 9090.91 8/peak_sep = 6.0 -8/clen = 77.0e-3 +8/clen = /LCLS/detectorPosition 8/fs = +y 8/ss = -x 8/corner_x = 214.99 @@ -143,7 +143,7 @@ n_panels = 64 9/badrow_direction = - 9/res = 9090.91 9/peak_sep = 6.0 -9/clen = 77.0e-3 +9/clen = /LCLS/detectorPosition 9/fs = +y 9/ss = -x 9/corner_x = 214.99 @@ -158,7 +158,7 @@ n_panels = 64 10/badrow_direction = - 10/res = 9090.91 10/peak_sep = 6.0 -10/clen = 77.0e-3 +10/clen = /LCLS/detectorPosition 10/fs = -x 10/ss = -y 10/corner_x = 16.59 @@ -173,7 +173,7 @@ n_panels = 64 11/badrow_direction = - 11/res = 9090.91 11/peak_sep = 6.0 -11/clen = 77.0e-3 +11/clen = /LCLS/detectorPosition 11/fs = -x 11/ss = -y 11/corner_x = -182.41 @@ -188,7 +188,7 @@ n_panels = 64 12/badrow_direction = - 12/res = 9090.91 12/peak_sep = 6.0 -12/clen = 77.0e-3 +12/clen = /LCLS/detectorPosition 12/fs = -y 12/ss = +x 12/corner_x = -212.64 @@ -203,7 +203,7 @@ n_panels = 64 13/badrow_direction = - 13/res = 9090.91 13/peak_sep = 6.0 -13/clen = 77.0e-3 +13/clen = /LCLS/detectorPosition 13/fs = -y 13/ss = +x 13/corner_x = -212.64 @@ -218,7 +218,7 @@ n_panels = 64 14/badrow_direction = - 14/res = 9090.91 14/peak_sep = 6.0 -14/clen = 77.0e-3 +14/clen = /LCLS/detectorPosition 14/fs = +x 14/ss = +y 14/corner_x = -11.44 @@ -233,7 +233,7 @@ n_panels = 64 15/badrow_direction = - 15/res = 9090.91 15/peak_sep = 6.0 -15/clen = 77.0e-3 +15/clen = /LCLS/detectorPosition 15/fs = +x 15/ss = +y 15/corner_x = 187.56 @@ -248,7 +248,7 @@ n_panels = 64 16/badrow_direction = - 16/res = 9090.91 16/peak_sep = 6.0 -16/clen = 77.0e-3 +16/clen = /LCLS/detectorPosition 16/fs = -x 16/ss = -y 16/corner_x = 851.64 @@ -263,7 +263,7 @@ n_panels = 64 17/badrow_direction = - 17/res = 9090.91 17/peak_sep = 6.0 -17/clen = 77.0e-3 +17/clen = /LCLS/detectorPosition 17/fs = -x 17/ss = -y 17/corner_x = 652.64 @@ -278,7 +278,7 @@ n_panels = 64 18/badrow_direction = - 18/res = 9090.91 18/peak_sep = 6.0 -18/clen = 77.0e-3 +18/clen = /LCLS/detectorPosition 18/fs = -y 18/ss = +x 18/corner_x = -381.23 @@ -293,7 +293,7 @@ n_panels = 64 19/badrow_direction = - 19/res = 9090.91 19/peak_sep = 6.0 -19/clen = 77.0e-3 +19/clen = /LCLS/detectorPosition 19/fs = -y 19/ss = +x 19/corner_x = -381.23 @@ -308,7 +308,7 @@ n_panels = 64 20/badrow_direction = - 20/res = 9090.91 20/peak_sep = 6.0 -20/clen = 77.0e-3 +20/clen = /LCLS/detectorPosition 20/fs = +x 20/ss = +y 20/corner_x = -849.25 @@ -323,7 +323,7 @@ n_panels = 64 21/badrow_direction = - 21/res = 9090.91 21/peak_sep = 6.0 -21/clen = 77.0e-3 +21/clen = /LCLS/detectorPosition 21/fs = +x 21/ss = +y 21/corner_x = -650.25 @@ -338,7 +338,7 @@ n_panels = 64 22/badrow_direction = - 22/res = 9090.91 22/peak_sep = 6.0 -22/clen = 77.0e-3 +22/clen = /LCLS/detectorPosition 22/fs = +y 22/ss = -x 22/corner_x = 389.50 @@ -353,7 +353,7 @@ n_panels = 64 23/badrow_direction = - 23/res = 9090.91 23/peak_sep = 6.0 -23/clen = 77.0e-3 +23/clen = /LCLS/detectorPosition 23/fs = +y 23/ss = -x 23/corner_x = 389.50 @@ -368,7 +368,7 @@ n_panels = 64 24/badrow_direction = - 24/res = 9090.91 24/peak_sep = 6.0 -24/clen = 77.0e-3 +24/clen = /LCLS/detectorPosition 24/fs = -x 24/ss = -y 24/corner_x = 855.29 @@ -383,7 +383,7 @@ n_panels = 64 25/badrow_direction = - 25/res = 9090.91 25/peak_sep = 6.0 -25/clen = 77.0e-3 +25/clen = /LCLS/detectorPosition 25/fs = -x 25/ss = -y 25/corner_x = 656.29 @@ -398,7 +398,7 @@ n_panels = 64 26/badrow_direction = - 26/res = 9090.91 26/peak_sep = 6.0 -26/clen = 77.0e-3 +26/clen = /LCLS/detectorPosition 26/fs = -y 26/ss = +x 26/corner_x = -167.72 @@ -413,7 +413,7 @@ n_panels = 64 27/badrow_direction = - 27/res = 9090.91 27/peak_sep = 6.0 -27/clen = 77.0e-3 +27/clen = /LCLS/detectorPosition 27/fs = -y 27/ss = +x 27/corner_x = -167.72 @@ -428,7 +428,7 @@ n_panels = 64 28/badrow_direction = - 28/res = 9090.91 28/peak_sep = 6.0 -28/clen = 77.0e-3 +28/clen = /LCLS/detectorPosition 28/fs = +x 28/ss = +y 28/corner_x = -847.07 @@ -443,7 +443,7 @@ n_panels = 64 29/badrow_direction = - 29/res = 9090.91 29/peak_sep = 6.0 -29/clen = 77.0e-3 +29/clen = /LCLS/detectorPosition 29/fs = +x 29/ss = +y 29/corner_x = -648.07 @@ -458,7 +458,7 @@ n_panels = 64 30/badrow_direction = - 30/res = 9090.91 30/peak_sep = 6.0 -30/clen = 77.0e-3 +30/clen = /LCLS/detectorPosition 30/fs = +y 30/ss = -x 30/corner_x = 174.81 @@ -473,7 +473,7 @@ n_panels = 64 31/badrow_direction = - 31/res = 9090.91 31/peak_sep = 6.0 -31/clen = 77.0e-3 +31/clen = /LCLS/detectorPosition 31/fs = +y 31/ss = -x 31/corner_x = 174.81 @@ -488,7 +488,7 @@ n_panels = 64 32/badrow_direction = - 32/res = 9090.91 32/peak_sep = 6.0 -32/clen = 77.0e-3 +32/clen = /LCLS/detectorPosition 32/fs = -y 32/ss = +x 32/corner_x = 450.39 @@ -503,7 +503,7 @@ n_panels = 64 33/badrow_direction = - 33/res = 9090.91 33/peak_sep = 6.0 -33/clen = 77.0e-3 +33/clen = /LCLS/detectorPosition 33/fs = -y 33/ss = +x 33/corner_x = 450.39 @@ -518,7 +518,7 @@ n_panels = 64 34/badrow_direction = - 34/res = 9090.91 34/peak_sep = 6.0 -34/clen = 77.0e-3 +34/clen = /LCLS/detectorPosition 34/fs = +x 34/ss = +y 34/corner_x = -808.26 @@ -533,7 +533,7 @@ n_panels = 64 35/badrow_direction = - 35/res = 9090.91 35/peak_sep = 6.0 -35/clen = 77.0e-3 +35/clen = /LCLS/detectorPosition 35/fs = +x 35/ss = +y 35/corner_x = -609.26 @@ -548,7 +548,7 @@ n_panels = 64 36/badrow_direction = - 36/res = 9090.91 36/peak_sep = 6.0 -36/clen = 77.0e-3 +36/clen = /LCLS/detectorPosition 36/fs = +y 36/ss = -x 36/corner_x = -450.89 @@ -563,7 +563,7 @@ n_panels = 64 37/badrow_direction = - 37/res = 9090.91 37/peak_sep = 6.0 -37/clen = 77.0e-3 +37/clen = /LCLS/detectorPosition 37/fs = +y 37/ss = -x 37/corner_x = -450.89 @@ -578,7 +578,7 @@ n_panels = 64 38/badrow_direction = - 38/res = 9090.91 38/peak_sep = 6.0 -38/clen = 77.0e-3 +38/clen = /LCLS/detectorPosition 38/fs = -x 38/ss = -y 38/corner_x = 799.39 @@ -593,7 +593,7 @@ n_panels = 64 39/badrow_direction = - 39/res = 9090.91 39/peak_sep = 6.0 -39/clen = 77.0e-3 +39/clen = /LCLS/detectorPosition 39/fs = -x 39/ss = -y 39/corner_x = 600.39 @@ -608,7 +608,7 @@ n_panels = 64 40/badrow_direction = - 40/res = 9090.91 40/peak_sep = 6.0 -40/clen = 77.0e-3 +40/clen = /LCLS/detectorPosition 40/fs = -y 40/ss = +x 40/corner_x = 642.39 @@ -623,7 +623,7 @@ n_panels = 64 41/badrow_direction = - 41/res = 9090.91 41/peak_sep = 6.0 -41/clen = 77.0e-3 +41/clen = /LCLS/detectorPosition 41/fs = -y 41/ss = +x 41/corner_x = 642.39 @@ -638,7 +638,7 @@ n_panels = 64 42/badrow_direction = - 42/res = 9090.91 42/peak_sep = 6.0 -42/clen = 77.0e-3 +42/clen = /LCLS/detectorPosition 42/fs = +x 42/ss = +y 42/corner_x = -809.61 @@ -653,7 +653,7 @@ n_panels = 64 43/badrow_direction = - 43/res = 9090.91 43/peak_sep = 6.0 -43/clen = 77.0e-3 +43/clen = /LCLS/detectorPosition 43/fs = +x 43/ss = +y 43/corner_x = -610.61 @@ -668,7 +668,7 @@ n_panels = 64 44/badrow_direction = - 44/res = 9090.91 44/peak_sep = 6.0 -44/clen = 77.0e-3 +44/clen = /LCLS/detectorPosition 44/fs = +y 44/ss = -x 44/corner_x = -657.61 @@ -683,7 +683,7 @@ n_panels = 64 45/badrow_direction = - 45/res = 9090.91 45/peak_sep = 6.0 -45/clen = 77.0e-3 +45/clen = /LCLS/detectorPosition 45/fs = +y 45/ss = -x 45/corner_x = -657.61 @@ -698,7 +698,7 @@ n_panels = 64 46/badrow_direction = - 46/res = 9090.91 46/peak_sep = 6.0 -46/clen = 77.0e-3 +46/clen = /LCLS/detectorPosition 46/fs = -x 46/ss = -y 46/corner_x = 793.39 @@ -713,7 +713,7 @@ n_panels = 64 47/badrow_direction = - 47/res = 9090.91 47/peak_sep = 6.0 -47/clen = 77.0e-3 +47/clen = /LCLS/detectorPosition 47/fs = -x 47/ss = -y 47/corner_x = 594.39 @@ -728,7 +728,7 @@ n_panels = 64 48/badrow_direction = - 48/res = 9090.91 48/peak_sep = 6.0 -48/clen = 77.0e-3 +48/clen = /LCLS/detectorPosition 48/fs = -x 48/ss = -y 48/corner_x = 417.94 @@ -743,7 +743,7 @@ n_panels = 64 49/badrow_direction = - 49/res = 9090.91 49/peak_sep = 6.0 -49/clen = 77.0e-3 +49/clen = /LCLS/detectorPosition 49/fs = -x 49/ss = -y 49/corner_x = 218.94 @@ -758,7 +758,7 @@ n_panels = 64 50/badrow_direction = - 50/res = 9090.91 50/peak_sep = 6.0 -50/clen = 77.0e-3 +50/clen = /LCLS/detectorPosition 50/fs = -y 50/ss = +x 50/corner_x = -783.68 @@ -773,7 +773,7 @@ n_panels = 64 51/badrow_direction = - 51/res = 9090.91 51/peak_sep = 6.0 -51/clen = 77.0e-3 +51/clen = /LCLS/detectorPosition 51/fs = -y 51/ss = +x 51/corner_x = -783.68 @@ -788,7 +788,7 @@ n_panels = 64 52/badrow_direction = - 52/res = 9090.91 52/peak_sep = 6.0 -52/clen = 77.0e-3 +52/clen = /LCLS/detectorPosition 52/fs = +x 52/ss = +y 52/corner_x = -433.03 @@ -803,7 +803,7 @@ n_panels = 64 53/badrow_direction = - 53/res = 9090.91 53/peak_sep = 6.0 -53/clen = 77.0e-3 +53/clen = /LCLS/detectorPosition 53/fs = +x 53/ss = +y 53/corner_x = -234.03 @@ -818,7 +818,7 @@ n_panels = 64 54/badrow_direction = - 54/res = 9090.91 54/peak_sep = 6.0 -54/clen = 77.0e-3 +54/clen = /LCLS/detectorPosition 54/fs = +y 54/ss = -x 54/corner_x = 835.39 @@ -833,7 +833,7 @@ n_panels = 64 55/badrow_direction = - 55/res = 9090.91 55/peak_sep = 6.0 -55/clen = 77.0e-3 +55/clen = /LCLS/detectorPosition 55/fs = +y 55/ss = -x 55/corner_x = 835.39 @@ -848,7 +848,7 @@ n_panels = 64 56/badrow_direction = - 56/res = 9090.91 56/peak_sep = 6.0 -56/clen = 77.0e-3 +56/clen = /LCLS/detectorPosition 56/fs = -x 56/ss = -y 56/corner_x = 425.57 @@ -863,7 +863,7 @@ n_panels = 64 57/badrow_direction = - 57/res = 9090.91 57/peak_sep = 6.0 -57/clen = 77.0e-3 +57/clen = /LCLS/detectorPosition 57/fs = -x 57/ss = -y 57/corner_x = 226.57 @@ -878,7 +878,7 @@ n_panels = 64 58/badrow_direction = - 58/res = 9090.91 58/peak_sep = 6.0 -58/clen = 77.0e-3 +58/clen = /LCLS/detectorPosition 58/fs = -y 58/ss = +x 58/corner_x = -572.18 @@ -893,7 +893,7 @@ n_panels = 64 59/badrow_direction = - 59/res = 9090.91 59/peak_sep = 6.0 -59/clen = 77.0e-3 +59/clen = /LCLS/detectorPosition 59/fs = -y 59/ss = +x 59/corner_x = -572.18 @@ -908,7 +908,7 @@ n_panels = 64 60/badrow_direction = - 60/res = 9090.91 60/peak_sep = 6.0 -60/clen = 77.0e-3 +60/clen = /LCLS/detectorPosition 60/fs = +x 60/ss = +y 60/corner_x = -415.37 @@ -923,7 +923,7 @@ n_panels = 64 61/badrow_direction = - 61/res = 9090.91 61/peak_sep = 6.0 -61/clen = 77.0e-3 +61/clen = /LCLS/detectorPosition 61/fs = +x 61/ss = +y 61/corner_x = -216.37 @@ -938,7 +938,7 @@ n_panels = 64 62/badrow_direction = - 62/res = 9090.91 62/peak_sep = 6.0 -62/clen = 77.0e-3 +62/clen = /LCLS/detectorPosition 62/fs = +y 62/ss = -x 62/corner_x = 577.59 @@ -953,10 +953,9 @@ n_panels = 64 63/badrow_direction = - 63/res = 9090.91 63/peak_sep = 6.0 -63/clen = 77.0e-3 +63/clen = /LCLS/detectorPosition 63/fs = +y 63/ss = -x 63/corner_x = 577.59 63/corner_y = -227.89 63/no_index = 0 - diff --git a/src/detector.c b/src/detector.c index e4f15aff..7d2cb513 100644 --- a/src/detector.c +++ b/src/detector.c @@ -21,6 +21,7 @@ #include "diffraction.h" #include "detector.h" #include "beam-parameters.h" +#include "hdf5-file.h" static int atob(const char *a) @@ -240,6 +241,24 @@ struct panel *find_panel(struct detector *det, int x, int y) } +void fill_in_values(struct detector *det, struct hdfile *f) +{ + int i; + + for ( i=0; i<det->n_panels; i++ ) { + + struct panel *p = &det->panels[i]; + + if ( p->clen_from != NULL ) { + p->clen = get_value(f, p->clen_from) * 1.0e-3; + free(p->clen_from); + p->clen_from = NULL; + } + + } +} + + struct detector *get_detector_geometry(const char *filename) { FILE *fh; @@ -359,7 +378,18 @@ struct detector *get_detector_geometry(const char *filename) } else if ( strcmp(path[1], "corner_y") == 0 ) { det->panels[np].cy = atof(bits[2]); } else if ( strcmp(path[1], "clen") == 0 ) { - det->panels[np].clen = atof(bits[2]); + + char *end; + double v = strtod(bits[2], &end); + if ( end == bits[2] ) { + /* This means "fill in later" */ + det->panels[np].clen = -1.0; + det->panels[np].clen_from = strdup(bits[2]); + } else { + det->panels[np].clen = v; + det->panels[np].clen_from = NULL; + } + } else if ( strcmp(path[1], "res") == 0 ) { det->panels[np].res = atof(bits[2]); } else if ( strcmp(path[1], "peak_sep") == 0 ) { @@ -442,7 +472,8 @@ struct detector *get_detector_geometry(const char *filename) " panel %i\n", i); reject = 1; } - if ( det->panels[i].clen == -1 ) { + if ( (det->panels[i].clen < 0.0) + && (det->panels[i].clen_from == NULL) ) { ERROR("Please specify the camera length for" " panel %i\n", i); reject = 1; diff --git a/src/detector.h b/src/detector.h index 703c79ae..e9b2112f 100644 --- a/src/detector.h +++ b/src/detector.h @@ -17,22 +17,26 @@ #define DETECTOR_H struct image; +struct hdfile; +#include "hdf5-file.h" #include "image.h" + struct panel { int min_fs; /* Smallest FS value considered to be in the panel */ int max_fs; /* Largest FS value considered to be in this panel */ int min_ss; /* ... and so on */ int max_ss; - float cx; /* Location of corner (min_fs,min_ss) in pixels */ - float cy; - float clen; /* Camera length in metres */ - float res; /* Resolution in pixels per metre */ + double cx; /* Location of corner (min_fs,min_ss) in pixels */ + double cy; + double clen; /* Camera length in metres */ + char *clen_from; + double res; /* Resolution in pixels per metre */ char badrow; /* 'x' or 'y' */ int no_index; /* Don't index peaks in this panel if non-zero */ - float peak_sep; /* Characteristic peak separation */ + double peak_sep; /* Characteristic peak separation */ signed int fsx; signed int fsy; @@ -58,11 +62,16 @@ extern void record_image(struct image *image, int do_poisson); extern struct panel *find_panel(struct detector *det, int x, int y); extern struct detector *get_detector_geometry(const char *filename); + extern void free_detector_geometry(struct detector *det); extern struct detector *simple_geometry(const struct image *image); + extern void get_pixel_extents(struct detector *det, double *min_x, double *min_y, double *max_x, double *max_y); +extern void fill_in_values(struct detector *det, struct hdfile *f); + + #endif /* DETECTOR_H */ diff --git a/src/displaywindow.c b/src/displaywindow.c index 0af864fc..fe578266 100644 --- a/src/displaywindow.c +++ b/src/displaywindow.c @@ -656,6 +656,7 @@ static int load_geometry_file(DisplayWindow *dw, struct image *image, displaywindow_error(dw, "Failed to load geometry file"); return -1; } + fill_in_values(geom, dw->hdfile); if ( (1+geom->max_fs != dw->image->width) || (1+geom->max_ss != dw->image->height) ) { 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; diff --git a/src/hdf5-file.h b/src/hdf5-file.h index 342dfe72..7a0d4382 100644 --- a/src/hdf5-file.h +++ b/src/hdf5-file.h @@ -41,5 +41,6 @@ extern void hdfile_close(struct hdfile *f); extern char *hdfile_get_string_value(struct hdfile *f, const char *name); extern int get_peaks(struct image *image, struct hdfile *f); +extern double get_value(struct hdfile *f, const char *name); #endif /* HDF5_H */ |