aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2014-09-24 13:39:28 +0200
committerThomas White <taw@physics.org>2014-09-24 13:39:28 +0200
commit10f77e1e2f11baae436bb149066625d295ae521a (patch)
treed5c7e382dce73695ced86d0af895877bf13b2086
parentf88f11adb68b7b11dbc653543c989108aeb96a8f (diff)
Move photon_energy to "geometry" file
-rw-r--r--libcrystfel/src/detector.c18
-rw-r--r--libcrystfel/src/events.c4
-rw-r--r--libcrystfel/src/hdf5-file.c61
-rw-r--r--src/im-sandbox.c6
4 files changed, 59 insertions, 30 deletions
diff --git a/libcrystfel/src/detector.c b/libcrystfel/src/detector.c
index e5319000..9972e2ba 100644
--- a/libcrystfel/src/detector.c
+++ b/libcrystfel/src/detector.c
@@ -820,6 +820,15 @@ static void parse_toplevel(struct detector *det, struct beam_params *beam,
beam->photon_energy_from = NULL;
}
+ } else if ( strcmp(key, "photon_energy_scale") == 0 ) {
+ if ( beam == NULL ) {
+ ERROR("Geometry file contains a reference to "
+ "photon_energy_scale, which is inappropriate in "
+ "this situation.\n");
+ } else {
+ beam->photon_energy_scale = atof(val);
+ }
+
} else if ( parse_field_for_panel(&det->defaults, key, val, det) ) {
ERROR("Unrecognised top level field '%s'\n", key);
}
@@ -908,6 +917,9 @@ struct detector *get_detector_geometry(const char *filename,
return NULL;
}
+ beam->photon_energy = -1.0;
+ beam->photon_energy_scale = 1.0;
+
det->n_panels = 0;
det->panels = NULL;
det->n_bad = 0;
@@ -1247,6 +1259,12 @@ struct detector *get_detector_geometry(const char *filename,
}
}
+ if ( beam->photon_energy < -0.5 ) {
+ STATUS("Photon energy must be specified (note: this is now "
+ "done in the 'geometry' file.\n");
+ reject = 1;
+ }
+
for ( x=0; x<=max_fs; x++ ) {
for ( y=0; y<=max_ss; y++ ) {
if ( find_panel(det, x, y) == NULL ) {
diff --git a/libcrystfel/src/events.c b/libcrystfel/src/events.c
index 633c9677..c9cc1ece 100644
--- a/libcrystfel/src/events.c
+++ b/libcrystfel/src/events.c
@@ -253,7 +253,9 @@ char *get_event_string(struct event *ev)
char *new_ret_string;
int ret_string_len;
- if ( ev->path_length != 0) {
+ if ( ev == NULL ) return "null event";
+
+ if ( ev->path_length != 0 ) {
int pi;
diff --git a/libcrystfel/src/hdf5-file.c b/libcrystfel/src/hdf5-file.c
index 3fe088d6..ce0824c6 100644
--- a/libcrystfel/src/hdf5-file.c
+++ b/libcrystfel/src/hdf5-file.c
@@ -901,22 +901,33 @@ static int unpack_panels(struct image *image, struct detector *det)
void fill_in_beam_parameters(struct beam_params *beam, struct hdfile *f,
- struct event* ev)
+ struct event *ev, struct image *image)
{
- if ( beam->photon_energy_from == NULL ) return;
+ double eV;
+
+ if ( beam->photon_energy_from == NULL ) {
+
+ /* Explicit value given */
+ eV = beam->photon_energy;
+
+ } else if ( ev != NULL ) {
+
+ /* Value from HDF5 file, event-based structure */
+ eV = get_ev_based_value(f, beam->photon_energy_from, ev);
- if ( ev != NULL ) {
- beam->photon_energy = get_ev_based_value(f,
- beam->photon_energy_from, ev);
} else {
- beam->photon_energy = get_value(f, beam->photon_energy_from);
+
+ /* Value from HDF5 file, single-event structure */
+ eV = get_value(f, beam->photon_energy_from);
+
}
- beam->photon_energy *= beam->photon_energy_scale;
+
+ image->lambda = ph_en_to_lambda(eV_to_J(eV)) * beam->photon_energy_scale;
}
-int hdf5_read(struct hdfile *f, struct image *image,
- const char *element, int satcorr)
+int hdf5_read(struct hdfile *f, struct image *image, const char *element,
+ int satcorr)
{
herr_t r;
float *buf;
@@ -953,17 +964,13 @@ int hdf5_read(struct hdfile *f, struct image *image,
if ( image->beam != NULL ) {
- fill_in_beam_parameters(image->beam, f, NULL);
- image->lambda = ph_en_to_lambda(eV_to_J(image->beam->photon_energy));
+ fill_in_beam_parameters(image->beam, f, NULL, image);
- if ( (image->beam->photon_energy < 0.0)
- || (image->lambda > 1000) ) {
+ if ( image->lambda > 1000 ) {
/* Error message covers a silly value in the beam file
* or in the HDF5 file. */
- ERROR("Nonsensical wavelength (%e m or %e eV) value "
- "for %s.\n",
- image->lambda, image->beam->photon_energy,
- image->filename);
+ ERROR("Nonsensical wavelength (%e m) for %s.\n",
+ image->lambda, image->filename);
return 1;
}
@@ -973,8 +980,8 @@ int hdf5_read(struct hdfile *f, struct image *image,
}
-int hdf5_read2(struct hdfile *f, struct image *image,
- struct event *ev, int satcorr)
+int hdf5_read2(struct hdfile *f, struct image *image, struct event *ev,
+ int satcorr)
{
herr_t r;
float *buf;
@@ -1272,18 +1279,20 @@ int hdf5_read2(struct hdfile *f, struct image *image,
if ( image->beam != NULL ) {
- fill_in_beam_parameters(image->beam, f, ev);
+ fill_in_beam_parameters(image->beam, f, ev, image);
- image->lambda = ph_en_to_lambda(eV_to_J(image->beam->photon_energy));
+ STATUS("Event: %s\n", get_event_string(image->event));
+ STATUS("Wavelength: %e m\n", image->lambda);
+ STATUS("Filename: %s\n", image->filename);
- if ( (image->beam->photon_energy < 0.0)
- || (image->lambda > 1000) ) {
+ if ( (image->lambda > 1.0) || (image->lambda < 1e-20) )
+ {
/* Error message covers a silly value in the beam file
* or in the HDF5 file. */
- ERROR("Nonsensical wavelength (%e m or %e eV) value "
+ ERROR("Nonsensical wavelength (%e m) value "
"for file: %s, event: %s.\n",
- image->lambda, image->beam->photon_energy,
- image->filename, get_event_string(image->event));
+ image->lambda, image->filename,
+ get_event_string(image->event));
hdfile_close(f);
return 1;
}
diff --git a/src/im-sandbox.c b/src/im-sandbox.c
index 75c2624e..6c712ba3 100644
--- a/src/im-sandbox.c
+++ b/src/im-sandbox.c
@@ -131,9 +131,9 @@ static void unlock_sandbox(struct sandbox *sb)
}
-static struct filename_plus_event *get_pattern
- (FILE *fh, int config_basename, struct detector *det,
- const char *prefix)
+static struct filename_plus_event *get_pattern(FILE *fh, int config_basename,
+ struct detector *det,
+ const char *prefix)
{
char *line = NULL;
size_t len;