aboutsummaryrefslogtreecommitdiff
path: root/src/index.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/index.c')
-rw-r--r--src/index.c245
1 files changed, 160 insertions, 85 deletions
diff --git a/src/index.c b/src/index.c
index edfa33e5..4d2a158f 100644
--- a/src/index.c
+++ b/src/index.c
@@ -43,39 +43,67 @@ static IndexingPrivate *indexing_private(IndexingMethod indm)
}
-IndexingPrivate *prepare_indexing(IndexingMethod indm, UnitCell *cell,
+IndexingPrivate **prepare_indexing(IndexingMethod *indm, UnitCell *cell,
const char *filename, struct detector *det,
double nominal_photon_energy)
{
- switch ( indm ) {
- case INDEXING_NONE :
- return indexing_private(indm);
- case INDEXING_DIRAX :
- return indexing_private(indm);
- case INDEXING_MOSFLM :
- return indexing_private(indm);
- case INDEXING_TEMPLATE :
- return generate_templates(cell, filename, det,
- nominal_photon_energy);
+ int n;
+ int nm = 0;
+ IndexingPrivate **iprivs;
+
+ while ( indm[nm] != INDEXING_NONE ) nm++;
+ STATUS("Preparing %i indexing methods.\n", nm);
+ iprivs = malloc((nm+1) * sizeof(IndexingPrivate *));
+
+ for ( n=0; n<nm; n++ ) {
+
+ switch ( indm[n] ) {
+ case INDEXING_NONE :
+ ERROR("Tried to prepare INDEXING_NONE!\n");
+ break;
+ case INDEXING_DIRAX :
+ iprivs[n] = indexing_private(indm[n]);
+ break;
+ case INDEXING_MOSFLM :
+ iprivs[n] = indexing_private(indm[n]);
+ break;
+ case INDEXING_TEMPLATE :
+ iprivs[n] = generate_templates(cell, filename, det,
+ nominal_photon_energy);
+ break;
+ }
+
+ n++;
+
}
- return 0;
+ iprivs[n] = NULL;
+
+ return iprivs;
}
-void cleanup_indexing(IndexingPrivate *priv)
+void cleanup_indexing(IndexingPrivate **priv)
{
- switch ( priv->indm ) {
- case INDEXING_NONE :
- free(priv);
- break;
- case INDEXING_DIRAX :
- free(priv);
- break;
- case INDEXING_MOSFLM :
- free(priv);
- break;
- case INDEXING_TEMPLATE :
- free_templates(priv);
+ int n = 0;
+
+ while ( priv[n] != NULL ) {
+
+ switch ( priv[n]->indm ) {
+ case INDEXING_NONE :
+ free(priv[n]);
+ break;
+ case INDEXING_DIRAX :
+ free(priv[n]);
+ break;
+ case INDEXING_MOSFLM :
+ free(priv[n]);
+ break;
+ case INDEXING_TEMPLATE :
+ free_templates(priv[n]);
+ }
+
+ n++;
+
}
}
@@ -246,81 +274,93 @@ void map_all_peaks(struct image *image)
}
-void index_pattern(struct image *image, UnitCell *cell, IndexingMethod indm,
- int cellr, int verbose, IndexingPrivate *ipriv)
+void index_pattern(struct image *image, UnitCell *cell, IndexingMethod *indm,
+ int cellr, int verbose, IndexingPrivate **ipriv)
{
int i;
+ int n = 0;
map_all_peaks(image);
- write_drx(image);
- image->ncells = 0;
+ while ( indm[n] != INDEXING_NONE ) {
- /* Index (or not) as appropriate */
- switch ( indm ) {
- case INDEXING_NONE :
- return;
- case INDEXING_DIRAX :
- run_dirax(image);
- break;
- case INDEXING_MOSFLM :
- write_spt(image);
- write_img(image); /* dummy image. not needed for each frame.*/
- run_mosflm(image,cell);
- break;
- case INDEXING_TEMPLATE :
- match_templates(image, ipriv);
- break;
- }
-
- if ( image->ncells == 0 ) {
- STATUS("No candidate cells found.\n");
- return;
- }
+ image->ncells = 0;
- if ( (cellr == CELLR_NONE) || (indm == INDEXING_TEMPLATE) ) {
- image->indexed_cell = image->candidate_cells[0];
- if ( verbose ) {
- STATUS("--------------------\n");
- STATUS("The indexed cell (matching not performed):\n");
- cell_print(image->indexed_cell);
- STATUS("--------------------\n");
+ /* Index as appropriate */
+ switch ( indm[n] ) {
+ case INDEXING_NONE :
+ return;
+ case INDEXING_DIRAX :
+ STATUS("Running DirAx...\n");
+ write_drx(image);
+ run_dirax(image);
+ break;
+ case INDEXING_MOSFLM :
+ STATUS("Running MOSFLM...\n");
+ write_spt(image);
+ write_img(image); /* dummy image */
+ run_mosflm(image, cell);
+ break;
+ case INDEXING_TEMPLATE :
+ match_templates(image, ipriv[n]);
+ break;
}
- return;
- }
- for ( i=0; i<image->ncells; i++ ) {
-
- UnitCell *new_cell = NULL;
-
- if ( verbose ) {
- STATUS("--------------------\n");
- STATUS("Candidate cell %i (before matching):\n", i);
- cell_print(image->candidate_cells[i]);
- STATUS("--------------------\n");
+ if ( image->ncells == 0 ) {
+ STATUS("No candidate cells found.\n");
+ return;
}
- /* Match or reduce the cell as appropriate */
- switch ( cellr ) {
- case CELLR_NONE :
- /* Never happens */
- break;
- case CELLR_REDUCE :
- new_cell = match_cell(image->candidate_cells[i],
- cell, verbose, 1);
- break;
- case CELLR_COMPARE :
- new_cell = match_cell(image->candidate_cells[i],
- cell, verbose, 0);
- break;
+ if ( (cellr == CELLR_NONE) || (indm[n] == INDEXING_TEMPLATE) ) {
+ image->indexed_cell = image->candidate_cells[0];
+ if ( verbose ) {
+ STATUS("--------------------\n");
+ STATUS("The indexed cell (matching not"
+ " performed):\n");
+ cell_print(image->indexed_cell);
+ STATUS("--------------------\n");
+ }
+ return;
}
- image->indexed_cell = new_cell;
- if ( new_cell != NULL ) {
- STATUS("Matched on attempt %i.\n", i);
- goto done;
+ for ( i=0; i<image->ncells; i++ ) {
+
+ UnitCell *new_cell = NULL;
+
+ if ( verbose ) {
+ STATUS("--------------------\n");
+ STATUS("Candidate cell %i (before matching):\n",
+ i);
+ cell_print(image->candidate_cells[i]);
+ STATUS("--------------------\n");
+ }
+
+ /* Match or reduce the cell as appropriate */
+ switch ( cellr ) {
+ case CELLR_NONE :
+ /* Never happens */
+ break;
+ case CELLR_REDUCE :
+ new_cell = match_cell(image->candidate_cells[i],
+ cell, verbose, 1);
+ break;
+ case CELLR_COMPARE :
+ new_cell = match_cell(image->candidate_cells[i],
+ cell, verbose, 0);
+ break;
+ }
+
+ image->indexed_cell = new_cell;
+ if ( new_cell != NULL ) {
+ STATUS("Matched on attempt %i.\n", i);
+ goto done;
+ }
+
}
+ /* Move on to the next indexing method */
+ n++;
+
}
done:
@@ -328,3 +368,38 @@ done:
cell_free(image->candidate_cells[i]);
}
}
+
+
+IndexingMethod *build_indexer_list(const char *str, int *need_cell)
+{
+ int n, i;
+ char **methods;
+ IndexingMethod *list;
+ *need_cell = 0;
+
+ n = assplode(str, ",", &methods, ASSPLODE_NONE);
+ list = malloc((n+1)*sizeof(IndexingMethod));
+
+ for ( i=0; i<n; i++ ) {
+
+ if ( strcmp(methods[i], "dirax") == 0) {
+ list[i] = INDEXING_DIRAX;
+ } else if ( strcmp(methods[i], "mosflm") == 0) {
+ list[i] = INDEXING_MOSFLM;
+ } else if ( strcmp(methods[i], "template") == 0) {
+ list[i] = INDEXING_TEMPLATE;
+ *need_cell = 1;
+ } else {
+ ERROR("Unrecognised indexing method '%s'\n",
+ methods[i]);
+ return NULL;
+ }
+
+ free(methods[i]);
+
+ }
+ free(methods);
+ list[i] = INDEXING_NONE;
+
+ return list;
+}