aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2011-03-15 10:41:35 +0100
committerThomas White <taw@physics.org>2012-02-22 15:27:20 +0100
commitbe49b97c792edc33d908965823f73f33b830d557 (patch)
tree50a3a1eea924b6347e92ec46c6d67f2ba1c22787 /src
parent0f1a16a196ffed32eab9ede885de6d73928c718f (diff)
More work on new stream format
Diffstat (limited to 'src')
-rw-r--r--src/dw-hdfsee.c19
-rw-r--r--src/stream.c105
2 files changed, 111 insertions, 13 deletions
diff --git a/src/dw-hdfsee.c b/src/dw-hdfsee.c
index 55a06fef..4d8f586c 100644
--- a/src/dw-hdfsee.c
+++ b/src/dw-hdfsee.c
@@ -695,29 +695,32 @@ static void load_features_from_file(struct image *image, const char *filename)
do {
char line[1024];
- float x, y, df;
+ float intensity, sigma, res, fs, ss;
+ char phs[1024];
int r;
+ int cts;
signed int h, k, l;
rval = fgets(line, 1023, fh);
if ( rval == NULL ) continue;
chomp(line);
- /* Try long format (output of pattern_sim --near-bragg) */
- r = sscanf(line, "%i %i %i %f (at %f,%f)",
- &h, &k, &l, &df, &x, &y);
- if ( r == 6 ) {
+ /* Try long format (from stream) */
+ r = sscanf(line, "%i %i %i %f %s %f %f %i %f %f",
+ &h, &k, &l, &intensity, phs, &sigma, &res, &cts,
+ &fs, &ss);
+ if ( r == 10 ) {
char name[32];
snprintf(name, 31, "%i %i %i", h, k, l);
- image_add_feature(image->features, x, y, image, 1.0,
+ image_add_feature(image->features, fs, ss, image, 1.0,
strdup(name));
continue;
}
- r = sscanf(line, "%f %f", &x, &y);
+ r = sscanf(line, "%f %f", &fs, &ss);
if ( r != 2 ) continue;
- image_add_feature(image->features, x, y, image, 1.0, NULL);
+ image_add_feature(image->features, fs, ss, image, 1.0, NULL);
} while ( rval != NULL );
}
diff --git a/src/stream.c b/src/stream.c
index 9c2d0c7e..2a75216d 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -22,10 +22,15 @@
#include "utils.h"
#include "image.h"
#include "stream.h"
+#include "reflist.h"
#define CHUNK_START_MARKER "----- Begin chunk -----"
#define CHUNK_END_MARKER "----- End chunk -----"
+#define PEAK_LIST_START_MARKER "Peaks from peak search"
+#define PEAK_LIST_END_MARKER "End of peak list"
+#define REFLECTION_START_MARKER "Reflections measured after indexing"
+#define REFLECTION_END_MARKER "End of reflections"
static void exclusive(const char *a, const char *b)
@@ -139,15 +144,55 @@ static UnitCell *read_orientation_matrix(FILE *fh)
}
+static int read_reflections(FILE *fh, struct image *image)
+{
+ char *rval = NULL;
+
+ image->reflections = reflist_new();
+
+ do {
+
+ char line[1024];
+ signed int h, k, l;
+ float intensity, sigma, res, fs, ss;
+ char phs[1024];
+ int cts;
+ int r;
+ Reflection *refl;
+
+ rval = fgets(line, 1023, fh);
+ if ( rval == NULL ) continue;
+ chomp(line);
+
+ if ( strcmp(line, PEAK_LIST_END_MARKER) == 0 ) return 0;
+
+ r = sscanf(line, "%i %i %i %f %s %f %f %i %f %f",
+ &h, &k, &l, &intensity, phs, &sigma, &res, &cts,
+ &fs, &ss);
+ if ( r != 10 ) return 1;
+
+ refl = add_refl(image->reflections, h, k, l);
+ set_int(refl, intensity);
+ set_detector_pos(refl, fs, ss, 0.0);
+ /* FIXME: Set ESD */
+
+ } while ( rval != NULL );
+
+ /* Got read error of some kind before finding PEAK_LIST_END_MARKER */
+ return 1;
+
+}
+
+
static void write_reflections(struct image *image, FILE *ofh)
{
Reflection *refl;
RefListIterator *iter;
- fprintf(ofh, "Reflections measured after indexing\n");
+ fprintf(ofh, REFLECTION_START_MARKER"\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");
+ " 1/d(nm^-1) counts fs/px ss/px\n");
for ( refl = first_refl(image->reflections, &iter);
refl != NULL;
@@ -155,17 +200,53 @@ static void write_reflections(struct image *image, FILE *ofh)
signed int h, k, l;
double intensity, esd_i, s;
+ double fs, ss;
get_indices(refl, &h, &k, &l);
+ get_detector_pos(refl, &fs, &ss);
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);
+ fprintf(ofh,
+ "%3i %3i %3i %10.2f %s %10.2f %10.2f %7i %6.1f %6.1f\n",
+ h, k, l, intensity, " -", esd_i, s/1.0e9, 1,
+ fs, ss);
}
+
+ fprintf(ofh, REFLECTION_END_MARKER"\n");
+}
+
+
+static int read_peaks(FILE *fh, struct image *image)
+{
+ char *rval = NULL;
+
+ image->features = image_feature_list_new();
+
+ do {
+
+ char line[1024];
+ float x, y, d, intensity;
+ int r;
+
+ rval = fgets(line, 1023, fh);
+ if ( rval == NULL ) continue;
+ chomp(line);
+
+ if ( strcmp(line, PEAK_LIST_END_MARKER) == 0 ) return 0;
+
+ r = sscanf(line, "%f %f %f %f", &x, &y, &d, &intensity);
+ if ( r != 4 ) return 1;
+
+ image_add_feature(image->features, x, y, image, 1.0, NULL);
+
+ } while ( rval != NULL );
+
+ /* Got read error of some kind before finding PEAK_LIST_END_MARKER */
+ return 1;
}
@@ -173,7 +254,7 @@ static void write_peaks(struct image *image, FILE *ofh)
{
int i;
- fprintf(ofh, "Peaks from peak search\n");
+ fprintf(ofh, PEAK_LIST_START_MARKER"\n");
fprintf(ofh, " fs/px ss/px (1/d)/nm^-1 Intensity\n");
for ( i=0; i<image_feature_count(image->features); i++ ) {
@@ -192,6 +273,8 @@ static void write_peaks(struct image *image, FILE *ofh)
f->fs, f->ss, q/1.0e9, f->intensity);
}
+
+ fprintf(ofh, PEAK_LIST_END_MARKER"\n");
}
@@ -291,6 +374,10 @@ int read_chunk(FILE *fh, struct image *image)
if ( find_start_of_chunk(fh) ) return 1;
image->i0_available = 0;
+ if ( image->features != NULL ) {
+ image_feature_list_free(image->features);
+ image->features = NULL;
+ }
do {
@@ -338,6 +425,14 @@ int read_chunk(FILE *fh, struct image *image)
have_ev = 1;
}
+ if ( strcmp(line, PEAK_LIST_START_MARKER) == 0 ) {
+ if ( read_peaks(fh, image) ) return 1;
+ }
+
+ if ( strcmp(line, REFLECTION_START_MARKER) == 0 ) {
+ if ( read_reflections(fh, image) ) return 1;
+ }
+
} while ( strcmp(line, CHUNK_END_MARKER) != 0 );
if ( have_filename && have_cell && have_ev ) return 0;