Commit 857cc8c9 authored by Thomas White's avatar Thomas White
Browse files

Add 'detector' module

parent c9a551b8
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
......@@ -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@
/*
* 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;
}
}
}
/*
* 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 */
......@@ -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");
......
......@@ -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);
......
......@@ -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;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment