aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/detector.c35
-rw-r--r--src/detector.h19
-rw-r--r--src/displaywindow.c1
-rw-r--r--src/hdf5-file.c56
-rw-r--r--src/hdf5-file.h1
5 files changed, 105 insertions, 7 deletions
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 */