aboutsummaryrefslogtreecommitdiff
path: root/src/stream.c
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2011-03-14 15:10:16 +0100
committerThomas White <taw@physics.org>2012-02-22 15:27:19 +0100
commitd004d970fc2f83e0bfd81af810fdcea35e47a4ac (patch)
tree2c47e0d84e3ca9665576b85caa4d309b594d519d /src/stream.c
parentf27607b8f51779e5bf4b344294122c65e49f008b (diff)
New stream writing
Diffstat (limited to 'src/stream.c')
-rw-r--r--src/stream.c152
1 files changed, 123 insertions, 29 deletions
diff --git a/src/stream.c b/src/stream.c
index fbe0abad..4e34a48c 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -21,6 +21,63 @@
#include "cell.h"
#include "utils.h"
#include "image.h"
+#include "stream.h"
+
+
+static void exclusive(const char *a, const char *b)
+{
+ ERROR("The stream options '%s' and '%s' are mutually exclusive.\n",
+ a, b);
+}
+
+
+int parse_stream_flags(const char *a)
+{
+ int n, i;
+ int ret = STREAM_NONE;
+ char **flags;
+
+ n = assplode(a, ",", &flags, ASSPLODE_NONE);
+
+ for ( i=0; i<n; i++ ) {
+
+ if ( strcmp(flags[i], "pixels") == 0) {
+ if ( ret & STREAM_INTEGRATED ) {
+ exclusive("pixels", "integrated");
+ return -1;
+ }
+ ret |= STREAM_PIXELS;
+ } else if ( strcmp(flags[i], "integrated") == 0) {
+ if ( ret & STREAM_PIXELS ) {
+ exclusive("pixels", "integrated");
+ return -1;
+ }
+ ret |= STREAM_INTEGRATED;
+ } else if ( strcmp(flags[i], "peaks") == 0) {
+ if ( ret & STREAM_PEAKS_IF_INDEXED ) {
+ exclusive("peaks", "peaksifindexed");
+ return -1;
+ }
+ ret |= STREAM_PEAKS;
+ } else if ( strcmp(flags[i], "peaksifindexed") == 0) {
+ if ( ret & STREAM_PEAKS ) {
+ exclusive("peaks", "peaksifindexed");
+ return -1;
+ }
+ ret |= STREAM_PEAKS_IF_INDEXED;
+ } else {
+ ERROR("Unrecognised stream flag '%s'\n", flags[i]);
+ return 0;
+ }
+
+ free(flags[i]);
+
+ }
+ free(flags);
+
+ return ret;
+
+}
int count_patterns(FILE *fh)
@@ -76,6 +133,31 @@ static UnitCell *read_orientation_matrix(FILE *fh)
static void write_reflections(struct image *image, FILE *ofh)
{
+ Reflection *refl;
+ RefListIterator *iter;
+
+ fprintf(ofh, "Reflections measured after indexing\n");
+ /* FIXME: Unify this with write_reflections() over in reflections.c */
+ fprintf(ofh, " h k l I phase sigma(I) "
+ " 1/d(nm^-1) counts\n");
+
+ for ( refl = first_refl(image->reflections, &iter);
+ refl != NULL;
+ refl = next_refl(refl, iter) ) {
+
+ signed int h, k, l;
+ double intensity, esd_i, s;
+
+ get_indices(refl, &h, &k, &l);
+ intensity = get_intensity(refl);
+ esd_i = 0.0; /* FIXME! */
+ s = 0.0; /* FIXME! */
+
+ /* h, k, l, I, sigma(I), s */
+ fprintf(ofh, "%3i %3i %3i %10.2f %s %10.2f %10.2f %7i\n",
+ h, k, l, intensity, " -", esd_i, s/1.0e9, 1);
+
+ }
}
@@ -83,7 +165,7 @@ static void write_peaks(struct image *image, FILE *ofh)
{
int i;
- fprintf(ofh, "Peaks from peak search in %s\n", image->filename);
+ fprintf(ofh, "Peaks from peak search\n");
fprintf(ofh, " x/px y/px (1/d)/nm^-1 Intensity\n");
for ( i=0; i<image_feature_count(image->features); i++ ) {
@@ -102,13 +184,10 @@ static void write_peaks(struct image *image, FILE *ofh)
f->x, f->y, q/1.0e9, f->intensity);
}
-
- fprintf(ofh, "\n");
}
-
-void write_chunk(FILE *ofh, struct image *image, int flags)
+void write_chunk(FILE *ofh, struct image *i, int f)
{
double asx, asy, asz;
double bsx, bsy, bsz;
@@ -117,36 +196,51 @@ void write_chunk(FILE *ofh, struct image *image, int flags)
fprintf(ofh, "----- Begin chunk -----\n");
- fprintf(ofh, "Image filename: %s\n", image->filename);
-
- cell_get_parameters(image->indexed_cell, &a, &b, &c, &al, &be, &ga);
- 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(image->indexed_cell, &asx, &asy, &asz,
- &bsx, &bsy, &bsz,
- &csx, &csy, &csz);
- fprintf(ofh, "astar = %+9.7f %+9.7f %+9.7f nm^-1\n",
- asx/1e9, asy/1e9, asz/1e9);
- fprintf(ofh, "bstar = %+9.7f %+9.7f %+9.7f nm^-1\n",
- bsx/1e9, bsy/1e9, bsz/1e9);
- fprintf(ofh, "cstar = %+9.7f %+9.7f %+9.7f nm^-1\n",
- csx/1e9, csy/1e9, csz/1e9);
-
- if ( image->f0_available ) {
- fprintf(ofh, "I0 = %7.5f (arbitrary gas detector units)\n",
- image->f0);
+ fprintf(ofh, "Image filename: %s\n", i->filename);
+
+ if ( i->indexed_cell != NULL ) {
+ cell_get_parameters(i->indexed_cell, &a, &b, &c,
+ &al, &be, &ga);
+ 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(i->indexed_cell, &asx, &asy, &asz,
+ &bsx, &bsy, &bsz,
+ &csx, &csy, &csz);
+ fprintf(ofh, "astar = %+9.7f %+9.7f %+9.7f nm^-1\n",
+ asx/1e9, asy/1e9, asz/1e9);
+ fprintf(ofh, "bstar = %+9.7f %+9.7f %+9.7f nm^-1\n",
+ bsx/1e9, bsy/1e9, bsz/1e9);
+ fprintf(ofh, "cstar = %+9.7f %+9.7f %+9.7f nm^-1\n",
+ csx/1e9, csy/1e9, csz/1e9);
+
+ } else {
+
+ fprintf(ofh, "No unit cell from indexing.\n");
+
+ }
+
+ if ( i->i0_available ) {
+ fprintf(ofh, "I0 = %7.5f (arbitrary units)\n", i->i0);
} else {
fprintf(ofh, "I0 = invalid\n");
}
fprintf(ofh, "photon_energy_eV = %f\n",
- J_to_eV(ph_lambda_to_en(image->lambda)));
+ J_to_eV(ph_lambda_to_en(i->lambda)));
+
+ if ( (f & STREAM_PEAKS)
+ || ((f & STREAM_PEAKS_IF_INDEXED) && (i->indexed_cell != NULL)) ) {
+ fprintf(ofh, "\n");
+ write_peaks(i, ofh);
+ }
- write_peaks(image, ofh);
- write_reflections(image, ofh);
+ if ( (f & STREAM_PIXELS) || (f & STREAM_INTEGRATED) ) {
+ fprintf(ofh, "\n");
+ write_reflections(i, ofh);
+ }
fprintf(ofh, "----- End chunk -----\n\n");
}