diff options
author | Thomas White <taw@physics.org> | 2009-12-04 16:48:05 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2009-12-04 16:48:05 +0100 |
commit | b7741b3c35045c1d1d4b0cab3aa2c2b9157247e4 (patch) | |
tree | 68e0503237a8fe0415428df0226051e94e5a93e0 | |
parent | 550acac3992f5b5aa2d162ed215ddd3359588450 (diff) |
Add -o option, fix noise option
-rw-r--r-- | src/get_hkl.c | 28 | ||||
-rw-r--r-- | src/reflections.c | 11 |
2 files changed, 31 insertions, 8 deletions
diff --git a/src/get_hkl.c b/src/get_hkl.c index 477a2631..2a73f855 100644 --- a/src/get_hkl.c +++ b/src/get_hkl.c @@ -34,7 +34,9 @@ static void show_help(const char *s) "\n" " -h, --help Display this help message.\n" "\n" -" -t, --template=<filename> Only include reflections mentioned in file.\n"); +" -t, --template=<filename> Only include reflections mentioned in file.\n" +" --poisson Simulate Poisson samples.\n" +" -o --output=<filename> Output filename (default: stdout).\n"); } @@ -84,13 +86,15 @@ static void noisify_reflections(double *ref) for ( l=-INDMAX; l<INDMAX; l++ ) { double val; + int c; val = lookup_intensity(ref, h, k, l); - val = poisson_noise(val); - set_intensity(ref, h, k, l, val); + c = poisson_noise(val); + set_intensity(ref, h, k, l, c); } } + progress_bar(h+INDMAX, 2*INDMAX, "Simulating noise"); } } @@ -98,21 +102,23 @@ static void noisify_reflections(double *ref) int main(int argc, char *argv[]) { int c; - double *ref, *tref; + double *ref; struct molecule *mol; char *template = NULL; int config_noisify = 0; + char *output = NULL; /* Long options */ const struct option longopts[] = { {"help", 0, NULL, 'h'}, {"template", 1, NULL, 't'}, {"poisson", 0, &config_noisify, 1}, + {"output", 1, NULL, 'o'}, {0, 0, NULL, 0} }; /* Short options */ - while ((c = getopt_long(argc, argv, "ht:", longopts, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "ht:o:", longopts, NULL)) != -1) { switch (c) { case 'h' : { @@ -125,6 +131,11 @@ int main(int argc, char *argv[]) break; } + case 'o' : { + output = strdup(optarg); + break; + } + case 0 : { break; } @@ -141,6 +152,9 @@ int main(int argc, char *argv[]) ref = ideal_intensities(mol->reflections); if ( template != NULL ) { + + double *tref; + tref = template_reflections(ref, template); if ( tref == NULL ) { ERROR("Couldn't read template file!\n"); @@ -148,12 +162,12 @@ int main(int argc, char *argv[]) } free(ref); ref = tref; + } if ( config_noisify ) noisify_reflections(ref); - write_reflections("results/ideal-reflections.hkl", NULL, tref, 1, - mol->cell); + write_reflections(output, NULL, ref, 1, mol->cell); return 0; } diff --git a/src/reflections.c b/src/reflections.c index 5790b543..26a5d2b8 100644 --- a/src/reflections.c +++ b/src/reflections.c @@ -27,7 +27,16 @@ void write_reflections(const char *filename, unsigned int *counts, FILE *fh; signed int h, k, l; - fh = fopen(filename, "w"); + if ( filename == NULL ) { + fh = stdout; + } else { + fh = fopen(filename, "w"); + } + + if ( fh == NULL ) { + ERROR("Couldn't open output file!\n"); + return; + } /* Write spacings and angle if zone axis pattern */ if ( zone_axis ) { |