aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel/src/datatemplate.c
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2021-03-11 17:06:59 +0100
committerThomas White <taw@physics.org>2021-03-11 17:06:59 +0100
commite21cc1f84a8cb2b0627e99383c882e59efda4920 (patch)
tree7d8c56a259b8b4b9e030f22e26871e3cbe1942b5 /libcrystfel/src/datatemplate.c
parent0722b797e25ba3bf95d5eec56198460be0eb6aa8 (diff)
indexamajig: Use static wavelength from DataTemplate as estimate
If the geometry file contains a literal wavelength, then let's use it. That's better than nagging the user for a --wavelength-estimate.
Diffstat (limited to 'libcrystfel/src/datatemplate.c')
-rw-r--r--libcrystfel/src/datatemplate.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/libcrystfel/src/datatemplate.c b/libcrystfel/src/datatemplate.c
index 4326aa33..290b9227 100644
--- a/libcrystfel/src/datatemplate.c
+++ b/libcrystfel/src/datatemplate.c
@@ -1628,3 +1628,56 @@ int data_template_get_slab_extents(const DataTemplate *dt,
*ph = h + 1;
return 0;
}
+
+
+double convert_to_m(double val, int units)
+{
+ switch ( units ) {
+
+ case WAVELENGTH_M :
+ return val;
+
+ case WAVELENGTH_A :
+ return val * 1e-10;
+
+ case WAVELENGTH_PHOTON_EV :
+ return ph_eV_to_lambda(val);
+
+ case WAVELENGTH_PHOTON_KEV :
+ return ph_eV_to_lambda(val*1e3);
+
+ case WAVELENGTH_ELECTRON_V :
+ return el_V_to_lambda(val);
+
+ case WAVELENGTH_ELECTRON_KV :
+ return el_V_to_lambda(val*1e3);
+
+ }
+
+ return NAN;
+}
+
+
+/**
+ * Get the wavelength from a DataTemplate, if possible.
+ *
+ * WARNING: This is probably not the routine you are looking for!
+ * See the disclaimer for image_create_for_simulation(), which applies
+ * equally to this routine.
+ *
+ * \returns the wavelength, in metres, or NAN if impossible.
+ */
+double data_template_get_wavelength_if_possible(const DataTemplate *dt)
+{
+ float val;
+ char *rval;
+
+ if ( dt->wavelength_from == NULL ) return NAN;
+
+ val = strtod(dt->wavelength_from, &rval);
+ if ( (*rval == '\0') && (rval != dt->wavelength_from) ) {
+ return convert_to_m(val, dt->wavelength_unit);
+ } else {
+ return NAN;
+ }
+}