aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2014-03-10 14:52:57 +0100
committerThomas White <taw@physics.org>2014-03-10 14:52:57 +0100
commit9a193a4b42a335a9367f8aefed7fa1029aff7f9a (patch)
tree912392400737332f87ecdd91e862cfb304b5a075 /src
parentafebe167c384a280412353d805b7c97a249e2a6d (diff)
Output the reindexed stream
Diffstat (limited to 'src')
-rw-r--r--src/ambigator.c89
1 files changed, 89 insertions, 0 deletions
diff --git a/src/ambigator.c b/src/ambigator.c
index 03561f6c..69439a24 100644
--- a/src/ambigator.c
+++ b/src/ambigator.c
@@ -605,6 +605,93 @@ static void detwin(struct cc_list *ccs, int n_crystals, int *assignments,
}
+static void reindex_reflections(FILE *fh, FILE *ofh, int assignment,
+ SymOpList *amb)
+{
+ int first = 1;
+
+ do {
+
+ char *rval;
+ char line[1024];
+ int n;
+ signed int h, k, l;
+ int r;
+
+ rval = fgets(line, 1023, fh);
+ if ( rval == NULL ) break;
+
+ if ( strcmp(line, REFLECTION_END_MARKER) == 0 ) {
+ fputs(line, ofh);
+ return;
+ }
+
+ if ( first ) {
+ fputs(line, ofh);
+ first = 0;
+ continue;
+ }
+
+ r = sscanf(line, "%i %i %i%n", &h, &k, &l, &n);
+
+ /* See scanf() manual page about %n to see why <3 is used */
+ if ( (r < 3) && !first ) return;
+
+ get_equiv(amb, NULL, assignment, h, k, l, &h, &k, &l);
+
+ fprintf(ofh, "%4i %4i %4i%s", h, k, l, line+n);
+
+ } while ( 1 );
+}
+
+
+/* This is nasty, but means the output includes absolutely everything in the
+ * input, even stuff ignored by read_chunk() */
+static void write_reindexed_stream(const char *infile, const char *outfile,
+ int *assignments, SymOpList *amb)
+{
+ FILE *fh;
+ FILE *ofh;
+ int i;
+
+ fh = fopen(infile, "r");
+ if ( fh == NULL ) {
+ ERROR("Failed to open '%s'\n", infile);
+ return;
+ }
+
+ ofh = fopen(outfile, "w");
+ if ( ofh == NULL ) {
+ ERROR("Failed to open '%s'\n", outfile);
+ return;
+ }
+
+ i = 0;
+ do {
+
+ char *rval;
+ char line[1024];
+
+ rval = fgets(line, 1023, fh);
+ if ( rval == NULL ) break;
+
+ if ( strcmp(line, REFLECTION_START_MARKER"\n") == 0 ) {
+ reindex_reflections(fh, ofh, assignments[i++], amb);
+ } else {
+ fputs(line, ofh);
+ }
+
+ } while ( 1 );
+
+ if ( !feof(fh) ) {
+ ERROR("Error reading stream.\n");
+ }
+
+ fclose(fh);
+ fclose(ofh);
+}
+
+
int main(int argc, char *argv[])
{
int c;
@@ -906,6 +993,8 @@ int main(int argc, char *argv[])
STATUS("%i assignments are different from their starting values.\n",
n_dif);
+ write_reindexed_stream(infile, outfile, assignments, amb);
+
free(assignments);
gsl_rng_free(rng);