aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel
diff options
context:
space:
mode:
Diffstat (limited to 'libcrystfel')
-rw-r--r--libcrystfel/src/datatemplate.c53
-rw-r--r--libcrystfel/src/datatemplate.h2
-rw-r--r--libcrystfel/src/datatemplate_priv.h2
-rw-r--r--libcrystfel/src/image.c28
4 files changed, 57 insertions, 28 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;
+ }
+}
diff --git a/libcrystfel/src/datatemplate.h b/libcrystfel/src/datatemplate.h
index 22322b57..3d457f80 100644
--- a/libcrystfel/src/datatemplate.h
+++ b/libcrystfel/src/datatemplate.h
@@ -90,6 +90,8 @@ extern int data_template_get_slab_extents(const DataTemplate *dt, int *pw, int *
extern struct rg_collection *data_template_get_rigid_groups(const DataTemplate *dtempl,
const char *collection_name);
+extern double data_template_get_wavelength_if_possible(const DataTemplate *dt);
+
#ifdef __cplusplus
}
#endif
diff --git a/libcrystfel/src/datatemplate_priv.h b/libcrystfel/src/datatemplate_priv.h
index 62911748..71569273 100644
--- a/libcrystfel/src/datatemplate_priv.h
+++ b/libcrystfel/src/datatemplate_priv.h
@@ -234,4 +234,6 @@ struct _datatemplate
char *shift_y_from;
};
+extern double convert_to_m(double val, int units);
+
#endif /* DATATEMPLATE_PRIV_H */
diff --git a/libcrystfel/src/image.c b/libcrystfel/src/image.c
index 767689f8..db47f75d 100644
--- a/libcrystfel/src/image.c
+++ b/libcrystfel/src/image.c
@@ -400,34 +400,6 @@ static double im_get_length(struct image *image, const char *from,
}
-static 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;
-}
-
-
int create_detgeom(struct image *image, const DataTemplate *dtempl)
{
struct detgeom *detgeom;