aboutsummaryrefslogtreecommitdiff
path: root/src/diffraction.c
diff options
context:
space:
mode:
authorAlexandra Tolstikova <alexandra.tolstikova@desy.de>2017-11-16 13:46:23 +0100
committerThomas White <taw@physics.org>2018-09-10 15:01:10 +0200
commit17aec9c77e9b75510e43b0fb073df75f66849761 (patch)
tree0a9e0252b5c81ad6ad451f513a9a3834b582e10a /src/diffraction.c
parentec9f2c41c1f21968412eb4b7f57fda69ed6e37b1 (diff)
pattern_sim: read spectrum from file
Diffstat (limited to 'src/diffraction.c')
-rw-r--r--src/diffraction.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/diffraction.c b/src/diffraction.c
index 4cceba0e..97750f58 100644
--- a/src/diffraction.c
+++ b/src/diffraction.c
@@ -608,6 +608,40 @@ struct sample *generate_tophat(struct image *image)
}
+struct sample *generate_spectrum_fromfile(struct image *image,
+ char *spectrum_fn)
+{
+ struct sample *spectrum;
+ int i;
+ double k, w;
+ double w_sum = 0;
+
+ spectrum = malloc(image->nsamples * sizeof(struct sample));
+ if ( spectrum == NULL ) return NULL;
+
+ FILE *f;
+ f = fopen(spectrum_fn, "r");
+
+ int nsamples = 0;
+ for ( i=0; i<image->nsamples; i++ ) {
+ if (fscanf(f, "%lf %lf", &k, &w) != EOF) {
+ spectrum[i].k = ph_eV_to_k(k);
+ spectrum[i].weight = w;
+ w_sum += w;
+ nsamples += 1;
+ } else break;
+ }
+
+ for ( i=0; i<nsamples; i++ ) {
+ spectrum[i].weight /= w_sum;
+ }
+
+ image->spectrum_size = nsamples;
+
+ return spectrum;
+}
+
+
struct sample *generate_SASE(struct image *image, gsl_rng *rng)
{
struct sample *spectrum;