From 6563de76906d6a8562a4b25c4c0582f8b7c2d5bd Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 10 Feb 2010 14:25:42 +0100 Subject: Add --powder option for generating powder patterns directly --- src/hdf5-file.c | 8 ++++---- src/hdf5-file.h | 5 +++-- src/indexamajig.c | 3 ++- src/pattern_sim.c | 29 +++++++++++++++++++++++++++-- 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/hdf5-file.c b/src/hdf5-file.c index d8aee21d..130be3a0 100644 --- a/src/hdf5-file.c +++ b/src/hdf5-file.c @@ -100,8 +100,8 @@ void hdfile_close(struct hdfile *f) } -int hdf5_write(const char *filename, const int16_t *data, - int width, int height) +int hdf5_write(const char *filename, const void *data, + int width, int height, int type) { hid_t fh, gh, sh, dh; /* File, group, dataspace and data handles */ herr_t r; @@ -127,7 +127,7 @@ int hdf5_write(const char *filename, const int16_t *data, max_size[1] = height; sh = H5Screate_simple(2, size, max_size); - dh = H5Dcreate(gh, "data", H5T_NATIVE_INT16, sh, + dh = H5Dcreate(gh, "data", type, sh, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); if ( dh < 0 ) { ERROR("Couldn't create dataset\n"); @@ -138,7 +138,7 @@ int hdf5_write(const char *filename, const int16_t *data, /* Muppet check */ H5Sget_simple_extent_dims(sh, size, max_size); - r = H5Dwrite(dh, H5T_NATIVE_UINT16, H5S_ALL, + r = H5Dwrite(dh, type, H5S_ALL, H5S_ALL, H5P_DEFAULT, data); if ( r < 0 ) { ERROR("Couldn't write data\n"); diff --git a/src/hdf5-file.h b/src/hdf5-file.h index e1e9d2a1..455628bd 100644 --- a/src/hdf5-file.h +++ b/src/hdf5-file.h @@ -17,14 +17,15 @@ #define HDF5_H #include +#include #include "image.h" struct hdfile; -extern int hdf5_write(const char *filename, const int16_t *data, - int width, int height); +extern int hdf5_write(const char *filename, const void *data, + int width, int height, int type); extern int hdf5_read(struct hdfile *f, struct image *image); diff --git a/src/indexamajig.c b/src/indexamajig.c index 43127e66..daf37fc9 100644 --- a/src/indexamajig.c +++ b/src/indexamajig.c @@ -264,7 +264,8 @@ int main(int argc, char *argv[]) record_image(&image, 0, 0, 0); hdf5_write("simulated.h5", image.data, - image.width, image.height); + image.width, image.height, + H5T_NATIVE_INT16); } diff --git a/src/pattern_sim.c b/src/pattern_sim.c index e3d675d2..eb626f32 100644 --- a/src/pattern_sim.c +++ b/src/pattern_sim.c @@ -42,6 +42,7 @@ static void show_help(const char *s) " --gpu Use the GPU to speed up the calculation.\n" "\n" " --near-bragg Output h,k,l,I near Bragg conditions.\n" +" --powder Output a powder pattern as results/powder.h5.\n" " -n, --number= Generate N images. Default 1.\n" " --no-images Do not output any HDF5 files.\n" " -r, --random-orientation Use a randomly generated orientation\n" @@ -151,6 +152,7 @@ int main(int argc, char *argv[]) { int c; struct image image; + long long int *powder; int config_simdetails = 0; int config_nearbragg = 0; int config_randomquat = 0; @@ -160,6 +162,7 @@ int main(int argc, char *argv[]) int config_nobloom = 0; int config_nosfac = 0; int config_gpu = 0; + int config_powder = 0; int ndone = 0; /* Number of simulations done (images or not) */ int number = 1; /* Number used for filename of image */ int n_images = 1; /* Generate one image by default */ @@ -177,7 +180,8 @@ int main(int argc, char *argv[]) {"no-water", 0, &config_nowater, 1}, {"no-noise", 0, &config_nonoise, 1}, {"no-bloom", 0, &config_nobloom, 1}, - {"no-sfac", 0, &config_nosfac, 1}, + {"no-sfac", 0, &config_nosfac, 1}, + {"powder", 0, &config_powder, 1}, {0, 0, NULL, 0} }; @@ -245,6 +249,8 @@ int main(int argc, char *argv[]) image.det.panels[1].cx = 492.0; image.det.panels[1].cy = 779.7; + powder = calloc(image.width*image.height, sizeof(*powder)); + /* Splurge a few useful numbers */ STATUS("Wavelength is %f nm\n", image.lambda/1.0e-9); @@ -299,6 +305,25 @@ int main(int argc, char *argv[]) output_intensities(&image, image.molecule->cell); } + if ( config_powder ) { + + int x, y, w; + + w = image.width; + + for ( x=0; x