aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am2
-rw-r--r--src/Makefile.am2
-rw-r--r--src/detector.c42
-rw-r--r--src/detector.h23
-rw-r--r--src/hdf5-file.c6
-rw-r--r--src/hdf5-file.h2
-rw-r--r--src/main.c4
7 files changed, 74 insertions, 7 deletions
diff --git a/Makefile.am b/Makefile.am
index f4a33f00..9087ee19 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,3 +1,3 @@
EXTRA_DIST = configure src/cell.h src/hdf5-file.h src/image.h src/relrod.h \
- src/utils.h src/diffraction.h
+ src/utils.h src/diffraction.h src/detector.h src/ewald.h
SUBDIRS = src
diff --git a/src/Makefile.am b/src/Makefile.am
index f5ce4e6c..c224a2b0 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -3,5 +3,5 @@ bin_PROGRAMS = pattern_sim
AM_CFLAGS = -Wall -g @CFLAGS@
pattern_sim_SOURCES = main.c diffraction.c utils.c image.c cell.c hdf5-file.c \
- ewald.c
+ ewald.c detector.c
pattern_sim_LDADD = @LIBS@
diff --git a/src/detector.c b/src/detector.c
new file mode 100644
index 00000000..ebcbb814
--- /dev/null
+++ b/src/detector.c
@@ -0,0 +1,42 @@
+/*
+ * detector.c
+ *
+ * Detector properties
+ *
+ * (c) 2007-2009 Thomas White <thomas.white@desy.de>
+ *
+ * pattern_sim - Simulate diffraction patterns from small crystals
+ *
+ */
+
+
+#include <stdlib.h>
+#include <math.h>
+#include <stdio.h>
+
+#include "image.h"
+
+
+void record_image(struct image *image)
+{
+ int x, y;
+
+ image->data = malloc(image->width * image->height * sizeof(uint16_t));
+
+ for ( x=0; x<image->width; x++ ) {
+ for ( y=0; y<image->height; y++ ) {
+
+ uint16_t counts;
+ double val;
+ double intensity;
+
+ val = image->sfacs[x + image->width*y];
+
+ intensity = pow(val, 2.0);
+ counts = intensity*16;
+
+ image->data[x + image->width*y] = counts;
+
+ }
+ }
+}
diff --git a/src/detector.h b/src/detector.h
new file mode 100644
index 00000000..2f6680c4
--- /dev/null
+++ b/src/detector.h
@@ -0,0 +1,23 @@
+/*
+ * detector.h
+ *
+ * Detector properties
+ *
+ * (c) 2007-2009 Thomas White <thomas.white@desy.de>
+ *
+ * pattern_sim - Simulate diffraction patterns from small crystals
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifndef DETECTOR_H
+#define DETECTOR_H
+
+#include "image.h"
+
+extern void record_image(struct image *image);
+
+#endif /* DETECTOR_H */
diff --git a/src/hdf5-file.c b/src/hdf5-file.c
index 6eb84aeb..459f285c 100644
--- a/src/hdf5-file.c
+++ b/src/hdf5-file.c
@@ -22,7 +22,7 @@
#include "image.h"
-int hdf5_write(const char *filename, const double *data,
+int hdf5_write(const char *filename, const uint16_t *data,
int width, int height)
{
hid_t fh, gh, sh, dh; /* File, group, dataspace and data handles */
@@ -49,7 +49,7 @@ int hdf5_write(const char *filename, const double *data,
max_size[1] = height;
sh = H5Screate_simple(2, size, max_size);
- dh = H5Dcreate(gh, "data", H5T_NATIVE_FLOAT, sh,
+ dh = H5Dcreate(gh, "data", H5T_NATIVE_UINT16, sh,
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
if ( dh < 0 ) {
fprintf(stderr, "Couldn't create dataset\n");
@@ -63,7 +63,7 @@ int hdf5_write(const char *filename, const double *data,
(int)size[1], (int)size[0],
(int)max_size[1], (int)max_size[0]);
- r = H5Dwrite(dh, H5T_NATIVE_DOUBLE, H5S_ALL,
+ r = H5Dwrite(dh, H5T_NATIVE_UINT16, H5S_ALL,
H5S_ALL, H5P_DEFAULT, data);
if ( r < 0 ) {
fprintf(stderr, "Couldn't write data\n");
diff --git a/src/hdf5-file.h b/src/hdf5-file.h
index 7f74efa3..a263368a 100644
--- a/src/hdf5-file.h
+++ b/src/hdf5-file.h
@@ -18,7 +18,7 @@
#include <stdint.h>
-extern int hdf5_write(const char *filename, const double *data,
+extern int hdf5_write(const char *filename, const uint16_t *data,
int width, int height);
extern int hdf5_read(struct image *image, const char *filename);
diff --git a/src/main.c b/src/main.c
index ee02d340..c101fc87 100644
--- a/src/main.c
+++ b/src/main.c
@@ -23,6 +23,7 @@
#include "cell.h"
#include "utils.h"
#include "hdf5-file.h"
+#include "detector.h"
/* Crystal size in metres */
@@ -80,9 +81,10 @@ int main(int argc, char *argv[])
image.data = NULL;
get_diffraction(&image, cell);
+ record_image(&image);
/* Write the output file */
- hdf5_write("results/sim.h5", image.sfacs, image.width, image.height);
+ hdf5_write("results/sim.h5", image.data, image.width, image.height);
return 0;
}