aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2010-10-01 12:20:11 +0200
committerThomas White <taw@physics.org>2012-02-22 15:27:00 +0100
commitce045961f4d1cee94b98cbb8580141b20bb0a00f (patch)
tree9310c120031ad2e924dda45e5f33e5cd9fe4990d
parentc5dc4b204fab4dfd4a33ff4e2e299f407e9561f9 (diff)
indexamajig: Take output stream as a command line parameter
-rw-r--r--src/indexamajig.c31
-rw-r--r--src/pattern_sim.c3
-rw-r--r--src/peaks.c25
-rw-r--r--src/peaks.h2
-rw-r--r--src/reintegrate.c2
5 files changed, 45 insertions, 18 deletions
diff --git a/src/indexamajig.c b/src/indexamajig.c
index 0fa1e8a1..2f25d58a 100644
--- a/src/indexamajig.c
+++ b/src/indexamajig.c
@@ -44,7 +44,6 @@ struct process_args
/* Input */
char *filename;
int id;
- pthread_mutex_t *output_mutex; /* Protects stdout */
pthread_mutex_t *gpu_mutex; /* Protects "gctx" */
UnitCell *cell;
int config_cmfilter;
@@ -76,6 +75,10 @@ struct process_args
int done;
int indexable;
int sane;
+
+ /* Output stream */
+ pthread_mutex_t *output_mutex; /* Protects the output stream */
+ FILE *ofh;
};
@@ -365,7 +368,7 @@ static void process_image(struct process_args *pargs)
output_intensities(&image, image.indexed_cell,
pargs->output_mutex, config_polar,
pargs->config_sa, pargs->config_closer,
- 0, 0.1);
+ pargs->ofh, 0, 0.1);
}
simage = get_simage(&image, config_alternate);
@@ -439,7 +442,9 @@ int main(int argc, char *argv[])
int c;
struct gpu_context *gctx = NULL;
char *filename = NULL;
+ char *outfile = NULL;
FILE *fh;
+ FILE *ofh;
char *rval = NULL;
int n_images;
int n_indexable;
@@ -486,6 +491,7 @@ int main(int argc, char *argv[])
const struct option longopts[] = {
{"help", 0, NULL, 'h'},
{"input", 1, NULL, 'i'},
+ {"output", 1, NULL, 'o'},
{"gpu", 0, &config_gpu, 1},
{"no-index", 0, &config_noindex, 1},
{"dump-peaks", 0, &config_dumpfound, 1},
@@ -514,7 +520,7 @@ int main(int argc, char *argv[])
};
/* Short options */
- while ((c = getopt_long(argc, argv, "hi:wp:j:x:g:t:",
+ while ((c = getopt_long(argc, argv, "hi:wp:j:x:g:t:o:",
longopts, NULL)) != -1) {
switch (c) {
@@ -526,6 +532,10 @@ int main(int argc, char *argv[])
filename = strdup(optarg);
break;
+ case 'o' :
+ outfile = strdup(optarg);
+ break;
+
case 'z' :
indm_str = strdup(optarg);
break;
@@ -584,6 +594,20 @@ int main(int argc, char *argv[])
}
free(filename);
+ if ( outfile == NULL ) {
+ outfile = strdup("-");
+ }
+ if ( strcmp(outfile, "-") == 0 ) {
+ ofh = stdout;
+ } else {
+ ofh = fopen(outfile, "w");
+ }
+ if ( ofh == NULL ) {
+ ERROR("Failed to open output file '%s'\n", outfile);
+ return 1;
+ }
+ free(outfile);
+
if ( intfile != NULL ) {
ReflItemList *items;
items = read_reflections(intfile, intensities,
@@ -674,6 +698,7 @@ int main(int argc, char *argv[])
for ( i=0; i<nthreads; i++ ) {
worker_args[i] = malloc(sizeof(struct process_args));
worker_args[i]->filename = malloc(1024);
+ worker_args[i]->ofh = ofh;
worker_active[i] = 0;
}
diff --git a/src/pattern_sim.c b/src/pattern_sim.c
index ea3722a7..5fd7e7ea 100644
--- a/src/pattern_sim.c
+++ b/src/pattern_sim.c
@@ -419,7 +419,8 @@ int main(int argc, char *argv[])
if ( config_nearbragg ) {
find_projected_peaks(&image, cell, 0, 0.1);
- output_intensities(&image, cell, NULL, 0, 1, 0, 0, 0.1);
+ output_intensities(&image, cell, NULL, 0, 1, 0, stdout,
+ 0, 0.1);
}
if ( powder_fn != NULL ) {
diff --git a/src/peaks.c b/src/peaks.c
index 0d35c930..05de8fee 100644
--- a/src/peaks.c
+++ b/src/peaks.c
@@ -618,7 +618,8 @@ int peak_sanity_check(struct image *image, UnitCell *cell,
void output_intensities(struct image *image, UnitCell *cell,
pthread_mutex_t *mutex, int polar, int sa,
- int use_closer, int circular_domain, double domain_r)
+ int use_closer, FILE *ofh,
+ int circular_domain, double domain_r)
{
int i;
int n_found;
@@ -641,22 +642,22 @@ void output_intensities(struct image *image, UnitCell *cell,
/* Explicit printf() used here (not normally allowed) because
* we really want to output to stdout */
- printf("Reflections from indexing in %s\n", image->filename);
- printf("Orientation (wxyz): %7.5f %7.5f %7.5f %7.5f\n",
+ fprintf(ofh, "Reflections from indexing in %s\n", image->filename);
+ fprintf(ofh, "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(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",
+ fprintf(ofh, "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));
cell_get_reciprocal(cell, &asx, &asy, &asz,
&bsx, &bsy, &bsz,
&csx, &csy, &csz);
- printf("astar = %+9.7f %+9.7f %+9.7f nm^-1\n",
+ fprintf(ofh, "astar = %+9.7f %+9.7f %+9.7f nm^-1\n",
asx/1e9, asy/1e9, asz/1e9);
- printf("bstar = %+9.7f %+9.7f %+9.7f nm^-1\n",
+ fprintf(ofh, "bstar = %+9.7f %+9.7f %+9.7f nm^-1\n",
bsx/1e9, bsy/1e9, bsz/1e9);
- printf("cstar = %+9.7f %+9.7f %+9.7f nm^-1\n",
+ fprintf(ofh, "cstar = %+9.7f %+9.7f %+9.7f nm^-1\n",
csx/1e9, csy/1e9, csz/1e9);
if ( image->f0_available ) {
@@ -747,7 +748,7 @@ void output_intensities(struct image *image, UnitCell *cell,
}
/* Write h,k,l, integrated intensity and centroid coordinates */
- printf("%3i %3i %3i %6f (at %5.2f,%5.2f)\n",
+ fprintf(ofh, "%3i %3i %3i %6f (at %5.2f,%5.2f)\n",
image->hits[i].h, image->hits[i].k, image->hits[i].l,
intensity, x, y);
@@ -779,16 +780,16 @@ void output_intensities(struct image *image, UnitCell *cell,
}
- printf("Peak statistics: %i peaks found by the peak search out of "
+ fprintf(ofh, "Peak statistics: %i peaks found by the peak search out of "
"%i were close to indexed positions. "
"%i indexed positions out of %i were close to detected peaks.\n",
n_foundclose, n_found, n_indclose, image->n_hits);
- printf("%i integrations using indexed locations were aborted because "
+ fprintf(ofh, "%i integrations using indexed locations were aborted because "
"they hit one or more bad pixels.\n", n_veto);
- printf("%i integrations using peak search locations were aborted "
+ fprintf(ofh, "%i integrations using peak search locations were aborted "
"because they hit one or more bad pixels.\n", n_veto_second);
/* Blank line at end */
- printf("\n");
+ fprintf(ofh, "\n");
if ( mutex != NULL ) pthread_mutex_unlock(mutex);
}
diff --git a/src/peaks.h b/src/peaks.h
index 2d8c1db5..55cd9ded 100644
--- a/src/peaks.h
+++ b/src/peaks.h
@@ -23,7 +23,7 @@ extern void search_peaks(struct image *image, float threshold);
extern void dump_peaks(struct image *image, pthread_mutex_t *mutex);
extern void output_intensities(struct image *image, UnitCell *cell,
pthread_mutex_t *mutex, int polar, int sa,
- int use_closer, int circular_domain,
+ int use_closer, FILE *ofh, int circular_domain,
double domain_r);
extern int peak_sanity_check(struct image *image, UnitCell *cell,
int circular_domain, double domain_r);
diff --git a/src/reintegrate.c b/src/reintegrate.c
index 673f3bc2..ceb1974e 100644
--- a/src/reintegrate.c
+++ b/src/reintegrate.c
@@ -135,7 +135,7 @@ static void process_image(struct process_args *pargs)
output_intensities(&image, pargs->cell,
pargs->output_mutex, pargs->config_polar,
pargs->config_sa, pargs->config_closer,
- 0, 0.1);
+ stdout, 0, 0.1);
}
free(image.data);