From 27da7fc3b8c4ae479305d5de996bf8c729fabac3 Mon Sep 17 00:00:00 2001 From: Chun Hong Yoon Date: Thu, 13 Dec 2012 23:01:54 +0100 Subject: more user options for beam photon energy --- libcrystfel/src/beam-parameters.c | 20 ++++++++++++++++++-- libcrystfel/src/beam-parameters.h | 5 +++++ src/im-sandbox.c | 5 +++++ src/pattern_sim.c | 7 ++++++- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/libcrystfel/src/beam-parameters.c b/libcrystfel/src/beam-parameters.c index 4af25261..2e4f5302 100644 --- a/libcrystfel/src/beam-parameters.c +++ b/libcrystfel/src/beam-parameters.c @@ -8,6 +8,7 @@ * * Authors: * 2010,2012 Thomas White + * 2012 Chunhong Yoon * * This file is part of CrystFEL. * @@ -35,6 +36,7 @@ #include "beam-parameters.h" #include "utils.h" +#include "hdf5-file.h" struct beam_params *get_beam_parameters(const char *filename) @@ -86,7 +88,12 @@ struct beam_params *get_beam_parameters(const char *filename) } else if ( strcmp(bits[0], "beam/radius") == 0 ) { b->beam_radius = atof(bits[2]); } else if ( strcmp(bits[0], "beam/photon_energy") == 0 ) { - b->photon_energy = atof(bits[2]); + if ( strncmp(bits[2], "/", 1) == 0 ) { + b->photon_energy = 0; // 0 means special case + b->photon_energy_from = strdup(bits[2]); + } else { + b->photon_energy = atof(bits[2]); + } } else if ( strcmp(bits[0], "beam/bandwidth") == 0 ) { b->bandwidth = atof(bits[2]); } else if ( strcmp(bits[0], "beam/divergence") == 0 ) { @@ -113,7 +120,7 @@ struct beam_params *get_beam_parameters(const char *filename) ERROR("Invalid or unspecified value for 'beam/radius'.\n"); reject = 1; } - if ( b->photon_energy < 0.0 ) { + if ( b->photon_energy < 0.0 ) { // 0 is ok ERROR("Invalid or unspecified value for" " 'beam/photon_energy'.\n"); reject = 1; @@ -141,3 +148,12 @@ struct beam_params *get_beam_parameters(const char *filename) return b; } + +void fill_in_beamParam(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; + } +} diff --git a/libcrystfel/src/beam-parameters.h b/libcrystfel/src/beam-parameters.h index 133e041b..36cfaa55 100644 --- a/libcrystfel/src/beam-parameters.h +++ b/libcrystfel/src/beam-parameters.h @@ -8,6 +8,7 @@ * * Authors: * 2010,2012 Thomas White + * 2012 Chunhong Yoon * * This file is part of CrystFEL. * @@ -33,6 +34,7 @@ #include #endif +#include "hdf5-file.h" struct beam_params { @@ -46,10 +48,13 @@ 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 fill_in_beamParam(struct beam_params *beam, struct hdfile *f); #endif /* BEAM_PARAMETERS_H */ diff --git a/src/im-sandbox.c b/src/im-sandbox.c index 1b460d4e..706dfa7b 100644 --- a/src/im-sandbox.c +++ b/src/im-sandbox.c @@ -235,6 +235,11 @@ static void process_image(const struct index_args *iargs, 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)); + if ( image.lambda < 0.0 ) { if ( beam != NULL ) { ERROR("Using nominal photon energy of %.2f eV\n", diff --git a/src/pattern_sim.c b/src/pattern_sim.c index 06a1f5e5..17aa8030 100644 --- a/src/pattern_sim.c +++ b/src/pattern_sim.c @@ -498,7 +498,12 @@ int main(int argc, char *argv[]) /* Define image parameters */ image.width = image.det->max_fs + 1; image.height = image.det->max_ss + 1; - image.lambda = ph_en_to_lambda(eV_to_J(image.beam->photon_energy)); + if (image.beam->photon_energy == 0) { + ERROR("Invalid photon_energy format in beam file\n") + return 1; + } else { + image.lambda = ph_en_to_lambda(eV_to_J(image.beam->photon_energy)); + } image.bw = image.beam->bandwidth; image.div = image.beam->divergence; -- cgit v1.2.3