aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libcrystfel/src/beam-parameters.c14
-rw-r--r--libcrystfel/src/beam-parameters.h6
-rw-r--r--libcrystfel/src/detector.c2
-rw-r--r--src/im-sandbox.c59
-rw-r--r--src/pattern_sim.c10
5 files changed, 35 insertions, 56 deletions
diff --git a/libcrystfel/src/beam-parameters.c b/libcrystfel/src/beam-parameters.c
index 2236fddb..617f9061 100644
--- a/libcrystfel/src/beam-parameters.c
+++ b/libcrystfel/src/beam-parameters.c
@@ -149,11 +149,17 @@ struct beam_params *get_beam_parameters(const char *filename)
return b;
}
-void fill_in_beamParam(struct beam_params *beam, struct hdfile *f)
+
+void free_beam_parameters(struct beam_params *beam)
+{
+ free(beam->photon_energy_from);
+ free(beam);
+}
+
+
+void fill_in_beam_parameters(struct beam_params *beam, struct hdfile *f)
{
if ( beam->photon_energy_from != NULL ) {
- beam->photon_energy = get_value(f, beam->photon_energy_from );
- free(beam->photon_energy_from);
- beam->photon_energy_from = NULL;
+ beam->photon_energy = get_value(f, beam->photon_energy_from);
}
}
diff --git a/libcrystfel/src/beam-parameters.h b/libcrystfel/src/beam-parameters.h
index e0b16895..8212811b 100644
--- a/libcrystfel/src/beam-parameters.h
+++ b/libcrystfel/src/beam-parameters.h
@@ -41,6 +41,7 @@ struct beam_params
double fluence; /* photons per pulse */
double beam_radius; /* metres */
double photon_energy; /* eV per photon */
+ char *photon_energy_from; /* HDF5 dataset name */
double bandwidth; /* FWHM(wavelength) over wavelength.
* Note: current simulation code just uses
* a rectangular distribution with this as
@@ -48,13 +49,12 @@ struct beam_params
double divergence; /* divergence (radians) */
double profile_radius; /* Reciprocal space size of a reflection */
-
- char *photon_energy_from; /* hdf5 group name */
};
extern struct beam_params *get_beam_parameters(const char *filename);
+extern void free_beam_parameters(struct beam_params *beam);
-extern void fill_in_beamParam(struct beam_params *beam, struct hdfile *f);
+extern void fill_in_beam_parameters(struct beam_params *beam, struct hdfile *f);
#endif /* BEAM_PARAMETERS_H */
diff --git a/libcrystfel/src/detector.c b/libcrystfel/src/detector.c
index 4216838d..41ebcc9a 100644
--- a/libcrystfel/src/detector.c
+++ b/libcrystfel/src/detector.c
@@ -462,8 +462,6 @@ void fill_in_values(struct detector *det, struct hdfile *f)
if ( p->clen_from != NULL ) {
p->clen = get_value(f, p->clen_from) * 1.0e-3;
- free(p->clen_from);
- p->clen_from = NULL;
}
p->clen += p->coffset;
diff --git a/src/im-sandbox.c b/src/im-sandbox.c
index d1696969..32bcba15 100644
--- a/src/im-sandbox.c
+++ b/src/im-sandbox.c
@@ -174,7 +174,6 @@ static void process_image(const struct index_args *iargs,
int config_noisefilter = iargs->config_noisefilter;
int config_verbose = iargs->config_verbose;
IndexingMethod *indm = iargs->indm;
- struct beam_params *beam = iargs->beam;
int check;
struct hdfile *hdfile;
struct image image;
@@ -183,13 +182,13 @@ static void process_image(const struct index_args *iargs,
image.data = NULL;
image.flags = NULL;
image.indexed_cell = NULL;
- image.det = copy_geom(iargs->det);
image.copyme = iargs->copyme;
image.reflections = NULL;
image.n_saturated = 0;
image.id = cookie;
image.filename = pargs->filename;
- image.beam = beam;
+ image.beam = iargs->beam;
+ image.det = iargs->det;
hdfile = hdfile_open(image.filename);
if ( hdfile == NULL ) return;
@@ -231,48 +230,23 @@ static void process_image(const struct index_args *iargs,
image.width, image.height,
image.det->max_fs + 1, image.det->max_ss + 1);
hdfile_close(hdfile);
- free_detector_geometry(image.det);
return;
}
- if (beam->photon_energy == 0) { // read from existing hdf5
- fill_in_beamParam(beam, hdfile);
- }
- image.lambda = ph_en_to_lambda(eV_to_J(beam->photon_energy));
+ fill_in_values(image.det, hdfile);
+ fill_in_beam_parameters(image.beam, hdfile);
- if ( image.lambda < 0.0 ) {
- if ( beam != NULL ) {
- ERROR("Using nominal photon energy of %.2f eV\n",
- beam->photon_energy);
- image.lambda = ph_en_to_lambda(
- eV_to_J(beam->photon_energy));
- } else {
- ERROR("No wavelength in file, so you need to give "
- "a beam parameters file with -b.\n");
- hdfile_close(hdfile);
- free_detector_geometry(image.det);
- return;
- }
- }
+ image.lambda = ph_en_to_lambda(eV_to_J(image.beam->photon_energy));
- if ( image.lambda > 1000 ) {
- if ( beam != NULL ) {
- ERROR("Nonsensical wavelength in HDF5."
- "Using nominal photon energy of %.2f eV\n",
- beam->photon_energy);
- image.lambda = ph_en_to_lambda(
- eV_to_J(beam->photon_energy));
- } else {
- ERROR("Nonsensical wavelength in file, so you need to "
- "give a beam parameters file with -b.\n");
- hdfile_close(hdfile);
- free_detector_geometry(image.det);
- return;
- }
+ if ( (image.beam->photon_energy < 0.0) || (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);
+ hdfile_close(hdfile);
+ return;
}
- fill_in_values(image.det, hdfile);
-
if ( config_cmfilter ) {
filter_cm(&image);
}
@@ -318,9 +292,9 @@ static void process_image(const struct index_args *iargs,
image.data = data_for_measurement;
/* Calculate orientation matrix (by magic) */
- image.div = beam->divergence;
- image.bw = beam->bandwidth;
- image.profile_radius = beam->profile_radius;
+ image.div = image.beam->divergence;
+ image.bw = image.beam->bandwidth;
+ image.profile_radius = image.beam->profile_radius;
index_pattern(&image, cell, indm, iargs->cellr,
config_verbose, iargs->ipriv,
@@ -356,7 +330,6 @@ static void process_image(const struct index_args *iargs,
if ( image.flags != NULL ) free(image.flags);
image_feature_list_free(image.features);
hdfile_close(hdfile);
- free_detector_geometry(image.det);
}
@@ -428,7 +401,7 @@ static void run_work(const struct index_args *iargs,
free(iargs->indm);
free(iargs->ipriv);
free_detector_geometry(iargs->det);
- free(iargs->beam);
+ free_beam_parameters(iargs->beam);
free(iargs->element);
free(iargs->hdf5_peak_path);
free_copy_hdf5_field_list(iargs->copyme);
diff --git a/src/pattern_sim.c b/src/pattern_sim.c
index 17aa8030..89413a07 100644
--- a/src/pattern_sim.c
+++ b/src/pattern_sim.c
@@ -493,19 +493,21 @@ int main(int argc, char *argv[])
ERROR("Failed to read beam parameters from '%s'\n", beamfile);
return 1;
}
- free(beamfile);
/* Define image parameters */
image.width = image.det->max_fs + 1;
image.height = image.det->max_ss + 1;
- if (image.beam->photon_energy == 0) {
- ERROR("Invalid photon_energy format in beam file\n")
+ if ( image.beam->photon_energy_from != NULL ) {
+ ERROR("Photon energy must be specified, not taken from the"
+ " HDF5 file. Please alter %s accordingly.\n", beamfile)
return 1;
} else {
- image.lambda = ph_en_to_lambda(eV_to_J(image.beam->photon_energy));
+ double wl = ph_en_to_lambda(eV_to_J(image.beam->photon_energy));
+ image.lambda = wl;
}
image.bw = image.beam->bandwidth;
image.div = image.beam->divergence;
+ free(beamfile);
/* Load unit cell */
input_cell = load_cell_from_pdb(filename);