diff options
author | Thomas White <taw@physics.org> | 2010-04-16 19:18:41 +0200 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2010-04-16 19:20:47 +0200 |
commit | ca7215bc0355d78d6a5f3ff4fcb629c614f5b201 (patch) | |
tree | 4e0ffb7a88ffb802e00a8c18ead87469fd51de42 /src | |
parent | d0ef10cc38b8abda688d3024c6f60a8e9074cb7e (diff) |
Push output stream mutex down, and improve output of --near-bragg and --dump-peaks
Diffstat (limited to 'src')
-rw-r--r-- | src/indexamajig.c | 8 | ||||
-rw-r--r-- | src/pattern_sim.c | 2 | ||||
-rw-r--r-- | src/peaks.c | 32 | ||||
-rw-r--r-- | src/peaks.h | 7 |
4 files changed, 37 insertions, 12 deletions
diff --git a/src/indexamajig.c b/src/indexamajig.c index 47d9a971..d61e6af5 100644 --- a/src/indexamajig.c +++ b/src/indexamajig.c @@ -189,6 +189,7 @@ static struct image *get_simage(struct image *template, int alternate) image->lambda = ph_en_to_lambda(eV_to_J(1.8e3)); image->features = template->features; image->filename = template->filename; + image->indexed_cell = template->indexed_cell; return image; } @@ -296,7 +297,7 @@ static void *process_image(void *pargsv) search_peaks(&image); if ( image_feature_count(image.features) < 5 ) goto done; - if ( config_dumpfound ) dump_peaks(&image); + if ( config_dumpfound ) dump_peaks(&image, pargs->output_mutex); /* Not indexing nor writing xfel.drx? * Then there's nothing left to do. */ @@ -319,9 +320,8 @@ static void *process_image(void *pargsv) if ( config_nearbragg ) { /* Use original data (temporarily) */ simage->data = data_for_measurement; - pthread_mutex_lock(pargs->output_mutex); - output_intensities(simage, image.indexed_cell); - pthread_mutex_unlock(pargs->output_mutex); + output_intensities(simage, image.indexed_cell, + pargs->output_mutex); simage->data = NULL; } diff --git a/src/pattern_sim.c b/src/pattern_sim.c index 7bf9143c..ab223288 100644 --- a/src/pattern_sim.c +++ b/src/pattern_sim.c @@ -308,7 +308,7 @@ int main(int argc, char *argv[]) record_image(&image, !config_nonoise); if ( config_nearbragg ) { - output_intensities(&image, cell); + output_intensities(&image, cell, NULL); } if ( config_powder ) { diff --git a/src/peaks.c b/src/peaks.c index 104cf170..c0e9e270 100644 --- a/src/peaks.c +++ b/src/peaks.c @@ -20,6 +20,7 @@ #include <string.h> #include <assert.h> #include <gsl/gsl_statistics_int.h> +#include <pthread.h> #include "image.h" #include "utils.h" @@ -329,11 +330,15 @@ void search_peaks(struct image *image) } -void dump_peaks(struct image *image) +void dump_peaks(struct image *image, pthread_mutex_t *mutex) { int i; - printf("x/px\ty/px\t(1/d)/nm^-1\n"); + /* Get exclusive access to the output stream if necessary */ + if ( mutex != NULL ) pthread_mutex_lock(mutex); + + printf("Peaks from peak search in %s\n", image->filename); + printf(" x/px y/px (1/d)/nm^-1 Intensity\n"); for ( i=0; i<image_feature_count(image->features); i++ ) { @@ -346,18 +351,25 @@ void dump_peaks(struct image *image) map_position(image, f->x, f->y, &rx, &ry, &rz); q = modulus(rx, ry, rz); - printf("%7.3f\t%7.3f\t%7.3f\t%7.3f\n", f->x, f->y, q/1.0e9, 1.0); + printf("%8.3f %8.3f %8.3f %12.3f\n", + f->x, f->y, q/1.0e9, f->intensity); } + + printf("\n"); + + if ( mutex != NULL ) pthread_mutex_unlock(mutex); } -void output_intensities(struct image *image, UnitCell *cell) +void output_intensities(struct image *image, UnitCell *cell, + pthread_mutex_t *mutex) { int x, y; double ax, ay, az; double bx, by, bz; double cx, cy, cz; + double a, b, c, al, be, ga; struct reflhit hits[MAX_HITS]; int n_hits = 0; int i; @@ -422,11 +434,19 @@ void output_intensities(struct image *image, UnitCell *cell) STATUS("Found %i reflections\n", n_hits); + /* Get exclusive access to the output stream if necessary */ + if ( mutex != NULL ) pthread_mutex_lock(mutex); + /* Explicit printf() used here (not normally allowed) because * we really want to output to stdout */ - printf("New pattern: %s %7.5f %7.5f %7.5f %7.5f\n", image->filename, + printf("Reflections from indexing in %s\n", image->filename); + printf("Orientation (wxyz): %7.5f %7.5f %7.5f %7.5f\n", image->orientation.w, image->orientation.x, image->orientation.y, image->orientation.z); + cell_get_parameters(image->indexed_cell, &a, &b, &c, &al, &be, &ga); + printf("Cell parameters %7.5f %7.5f %7.5f nm, %7.5f %7.5f %7.5f deg\n", + a*1.0e9, b*1.0e9, c*1.0e9, + rad2deg(al), rad2deg(be), rad2deg(ga)); for ( i=0; i<n_hits; i++ ) { float x, y, intensity; @@ -456,4 +476,6 @@ void output_intensities(struct image *image, UnitCell *cell) /* Blank line at end */ printf("\n"); + + if ( mutex != NULL ) pthread_mutex_unlock(mutex); } diff --git a/src/peaks.h b/src/peaks.h index 510282f8..a5c771b7 100644 --- a/src/peaks.h +++ b/src/peaks.h @@ -17,8 +17,11 @@ #include <config.h> #endif +#include <pthread.h> + extern void search_peaks(struct image *image); -extern void dump_peaks(struct image *image); -extern void output_intensities(struct image *image, UnitCell *cell); +extern void dump_peaks(struct image *image, pthread_mutex_t *mutex); +extern void output_intensities(struct image *image, UnitCell *cell, + pthread_mutex_t *mutex); #endif /* PEAKS_H */ |