aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2010-02-02 18:12:29 +0100
committerThomas White <taw@physics.org>2010-02-02 18:12:29 +0100
commit7df59f9bc7acedb5f8aa01ad12f2f22d271a0f58 (patch)
tree9bc98ff31e5f37068169cf82cd645877ce22ea5f /src
parent9fed7cd780eb4912602f76323a0430a48cfd0834 (diff)
Tidy up options
This also simplifies quite a lot of code
Diffstat (limited to 'src')
-rw-r--r--src/dirax.c26
-rw-r--r--src/dirax.h2
-rw-r--r--src/index.c52
-rw-r--r--src/index.h8
-rw-r--r--src/indexamajig.c54
5 files changed, 94 insertions, 48 deletions
diff --git a/src/dirax.c b/src/dirax.c
index 4161c79c..6b77d888 100644
--- a/src/dirax.c
+++ b/src/dirax.c
@@ -309,34 +309,10 @@ static gboolean dirax_readable(GIOChannel *dirax, GIOCondition condition,
}
-void run_dirax(struct image *image, int no_index)
+void run_dirax(struct image *image)
{
unsigned int opts;
int saved_stderr;
- FILE *fh;
- int i;
-
- fh = fopen("xfel.drx", "w");
- if ( !fh ) {
- ERROR("Couldn't open temporary file xfel.drx\n");
- return;
- }
- fprintf(fh, "%f\n", 0.5); /* Lie about the wavelength. */
-
- for ( i=0; i<image_feature_count(image->features); i++ ) {
-
- struct imagefeature *f;
-
- f = image_get_feature(image->features, i);
- if ( f == NULL ) continue;
-
- fprintf(fh, "%10f %10f %10f %8f\n",
- f->rx/1e10, f->ry/1e10, f->rz/1e10, 1.0);
-
- }
- fclose(fh);
-
- if ( no_index ) return;
saved_stderr = dup(STDERR_FILENO);
image->dirax_pid = forkpty(&image->dirax_pty, NULL, NULL, NULL);
diff --git a/src/dirax.h b/src/dirax.h
index b3bc0a36..b6b80488 100644
--- a/src/dirax.h
+++ b/src/dirax.h
@@ -18,7 +18,7 @@
#endif
-extern void run_dirax(struct image *image, int no_index);
+extern void run_dirax(struct image *image);
#endif /* DIRAX_H */
diff --git a/src/index.c b/src/index.c
index a20ad3a5..6d896820 100644
--- a/src/index.c
+++ b/src/index.c
@@ -72,10 +72,41 @@ int map_position(struct image *image, double x, double y,
}
-void index_pattern(struct image *image, int no_index, int use_dirax)
+static void write_drx(struct image *image)
{
+ FILE *fh;
int i;
+ STATUS("Writing xfel.drx file. Remember that it uses units of "
+ "reciprocal Angstroms!\n");
+
+ fh = fopen("xfel.drx", "w");
+ if ( !fh ) {
+ ERROR("Couldn't open temporary file xfel.drx\n");
+ return;
+ }
+ fprintf(fh, "%f\n", 0.5); /* Lie about the wavelength. */
+
+ for ( i=0; i<image_feature_count(image->features); i++ ) {
+
+ struct imagefeature *f;
+
+ f = image_get_feature(image->features, i);
+ if ( f == NULL ) continue;
+
+ fprintf(fh, "%10f %10f %10f %8f\n",
+ f->rx/1e10, f->ry/1e10, f->rz/1e10, 1.0);
+
+ }
+ fclose(fh);
+}
+
+
+void index_pattern(struct image *image, IndexingMethod indm)
+{
+ int i;
+ UnitCell *new_cell = NULL;
+
/* Map positions to 3D */
for ( i=0; i<image_feature_count(image->features); i++ ) {
@@ -95,17 +126,16 @@ void index_pattern(struct image *image, int no_index, int use_dirax)
}
}
- if ( use_dirax ) {
-
- UnitCell *new_cell;
-
- run_dirax(image, no_index);
+ write_drx(image);
- new_cell = match_cell(image->indexed_cell,
- image->molecule->cell);
+ /* Index (or not) as appropriate */
+ if ( indm == INDEXING_NONE ) return;
+ if ( indm == INDEXING_DIRAX ) run_dirax(image);
- if ( new_cell != NULL ) image->indexed_cell = new_cell;
-
- return;
+ new_cell = match_cell(image->indexed_cell,
+ image->molecule->cell);
+ if ( new_cell != NULL ) {
+ free(image->indexed_cell);
+ image->indexed_cell = new_cell;
}
}
diff --git a/src/index.h b/src/index.h
index 6f1fe98c..a3dae020 100644
--- a/src/index.h
+++ b/src/index.h
@@ -18,8 +18,14 @@
#endif
-extern void index_pattern(struct image *image, int no_index, int use_dirax);
+typedef enum {
+ INDEXING_NONE,
+ INDEXING_DIRAX,
+ INDEXING_MATCH
+} IndexingMethod;
+
+extern void index_pattern(struct image *image, IndexingMethod indm);
/* x,y in pixels relative to central beam */
extern int map_position(struct image *image, double x, double y,
double *rx, double *ry, double *rz);
diff --git a/src/indexamajig.c b/src/indexamajig.c
index 245d1a81..d59132c5 100644
--- a/src/indexamajig.c
+++ b/src/indexamajig.c
@@ -43,10 +43,12 @@ static void show_help(const char *s)
"\n"
" -i, --input=<filename> Specify file containing list of images to process.\n"
" '-' means stdin, which is the default.\n"
-" --no-index Do everything else (including fine peak search and\n"
-" writing 'xfel.drx' if DirAx is being used), but\n"
-" don't actually index.\n"
-" --dirax Use DirAx for indexing.\n"
+" --indexing=<method> Use 'method' for indexing. Choose from:\n"
+" none : no indexing\n"
+" dirax : invoke DirAx\n"
+" --write-drx Write 'xfel.drx' for visualisation of reciprocal\n"
+" space. Implied by any indexing method other than"
+" 'none'.\n"
" --dump-peaks Write the results of the peak search to stdout.\n"
" --near-bragg Output a list of reflection intensities to stdout.\n"
" --simulate Simulate the diffraction pattern using the indexed\n"
@@ -65,9 +67,11 @@ int main(int argc, char *argv[])
int n_hits;
int config_noindex = 0;
int config_dumpfound = 0;
- int config_dirax = 0;
int config_nearbragg = 0;
+ int config_writedrx = 0;
int config_simulate = 0;
+ IndexingMethod indm;
+ char *indm_str = NULL;
/* Long options */
const struct option longopts[] = {
@@ -76,7 +80,8 @@ int main(int argc, char *argv[])
{"no-index", 0, &config_noindex, 1},
{"dump-peaks", 0, &config_dumpfound, 1},
{"near-bragg", 0, &config_nearbragg, 1},
- {"dirax", 0, &config_dirax, 1},
+ {"write-drx", 0, &config_writedrx, 1},
+ {"indexing", 1, NULL, 'z'},
{"simulate", 0, &config_simulate, 1},
{0, 0, NULL, 0}
};
@@ -95,6 +100,11 @@ int main(int argc, char *argv[])
break;
}
+ case 'z' : {
+ indm_str = strdup(optarg);
+ break;
+ }
+
case 0 : {
break;
}
@@ -120,6 +130,20 @@ int main(int argc, char *argv[])
return 1;
}
+ if ( indm_str == NULL ) {
+ STATUS("You didn't specify an indexing method, so I won't"
+ " try to index anything. If that isn't what you\n"
+ " wanted, re-run with --indexing=<method>.\n");
+ indm = INDEXING_NONE;
+ } else if ( strcmp(indm_str, "none") == 0 ) {
+ indm = INDEXING_NONE;
+ } else if ( strcmp(indm_str, "dirax") == 0) {
+ indm = INDEXING_DIRAX;
+ } else {
+ ERROR("Unrecognised indexing method '%s'\n", indm_str);
+ return 1;
+ }
+
n_images = 0;
n_hits = 0;
do {
@@ -160,13 +184,22 @@ int main(int argc, char *argv[])
if ( config_dumpfound ) dump_peaks(&image);
- /* Not indexing? Then there's nothing left to do. */
- if ( config_noindex ) goto done;
+ /* Not indexing nor writing xfel.drx?
+ * Then there's nothing left to do. */
+ if ( (!config_writedrx) && (indm == INDEXING_NONE) ) {
+ goto done;
+ }
/* Calculate orientation matrix (by magic) */
- index_pattern(&image, config_noindex, config_dirax);
+ if ( config_writedrx || (indm != INDEXING_NONE) ) {
+ index_pattern(&image, indm);
+ }
+
+ /* No cell at this point? Then we're done. */
if ( image.indexed_cell == NULL ) goto done;
+ /* Simulation or intensity measurements both require
+ * Ewald sphere vectors */
if ( config_nearbragg || config_simulate ) {
/* Simulate a diffraction pattern */
@@ -184,11 +217,12 @@ int main(int argc, char *argv[])
}
+ /* Measure intensities if requested */
if ( config_nearbragg ) {
- /* Read h,k,l,I */
output_intensities(&image, image.indexed_cell);
}
+ /* Simulate pattern if requested */
if ( config_simulate ) {
image.data = NULL;