aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2020-05-28 14:34:10 +0200
committerThomas White <taw@physics.org>2020-07-29 18:42:57 +0200
commitc5424abc8fccfa6b205db45f0ae2d64a362f01f5 (patch)
tree98b6a331c27481b8648faa62733f26a50919897e
parentab352f28b1c9d2691e4f39730b0ad5adf056426b (diff)
Convert stream to DataTemplate
-rw-r--r--libcrystfel/src/datatemplate.c49
-rw-r--r--libcrystfel/src/datatemplate.h19
-rw-r--r--libcrystfel/src/image.c38
-rw-r--r--libcrystfel/src/predict-refine.c53
-rw-r--r--libcrystfel/src/stream.c280
-rw-r--r--libcrystfel/src/stream.h12
-rw-r--r--src/ambigator.c5
-rw-r--r--src/cell_explorer.c2
-rw-r--r--src/im-zmq.c14
-rw-r--r--src/partialator.c5
-rw-r--r--src/process_hkl.c4
-rw-r--r--src/process_image.c4
-rw-r--r--src/whirligig.c5
13 files changed, 151 insertions, 339 deletions
diff --git a/libcrystfel/src/datatemplate.c b/libcrystfel/src/datatemplate.c
index 60c36358..6cc57d2d 100644
--- a/libcrystfel/src/datatemplate.c
+++ b/libcrystfel/src/datatemplate.c
@@ -3,11 +3,11 @@
*
* Data template structure
*
- * Copyright © 2019 Deutsches Elektronen-Synchrotron DESY,
- * a research centre of the Helmholtz Association.
+ * Copyright © 2019-2020 Deutsches Elektronen-Synchrotron DESY,
+ * a research centre of the Helmholtz Association.
*
* Authors:
- * 2019 Thomas White <taw@physics.org>
+ * 2019-2020 Thomas White <taw@physics.org>
*
* This file is part of CrystFEL.
*
@@ -1242,8 +1242,8 @@ void data_template_free(DataTemplate *dt)
}
-signed int data_template_find_panel(const DataTemplate *dt,
- int fs, int ss)
+static int data_template_find_panel(const DataTemplate *dt,
+ int fs, int ss, int *ppn)
{
int p;
@@ -1251,24 +1251,47 @@ signed int data_template_find_panel(const DataTemplate *dt,
if ( (fs >= dt->panels[p].orig_min_fs)
&& (fs < dt->panels[p].orig_max_fs+1)
&& (ss >= dt->panels[p].orig_min_ss)
- && (ss < dt->panels[p].orig_max_ss+1) ) return p;
+ && (ss < dt->panels[p].orig_max_ss+1) ) {
+ *ppn = p;
+ return 0;
+ }
}
- return -1;
+ return 1;
}
-void data_template_file_to_panel_coords(const DataTemplate *dt,
- float *pfs, float *pss)
+int data_template_file_to_panel_coords(const DataTemplate *dt,
+ float *pfs, float *pss,
+ int *ppn)
{
- signed int pn = data_template_find_panel(dt, *pfs, *pss);
- if ( pn == -1 ) {
- ERROR("Can't convert coordinates - no panel found\n");
- return;
+ int pn;
+
+ if ( data_template_find_panel(dt, *pfs, *pss, &pn) ) {
+ return 1;
}
+ *ppn = pn;
*pfs = *pfs - dt->panels[pn].orig_min_fs;
*pss = *pss - dt->panels[pn].orig_min_ss;
+ return 0;
+}
+
+
+int data_template_panel_to_file_coords(const DataTemplate *dt,
+ int pn, float *pfs, float *pss)
+{
+ if ( pn >= dt->n_panels ) return 1;
+ *pfs = *pfs + dt->panels[pn].orig_min_fs;
+ *pss = *pss + dt->panels[pn].orig_min_ss;
+ return 0;
+}
+
+
+const char *data_template_panel_name(const DataTemplate *dt, int pn)
+{
+ if ( pn >= dt->n_panels ) return NULL;
+ return dt->panels[pn].name;
}
diff --git a/libcrystfel/src/datatemplate.h b/libcrystfel/src/datatemplate.h
index ac76c578..fd99d5f0 100644
--- a/libcrystfel/src/datatemplate.h
+++ b/libcrystfel/src/datatemplate.h
@@ -3,11 +3,11 @@
*
* Template for loading data
*
- * Copyright © 2019 Deutsches Elektronen-Synchrotron DESY,
- * a research centre of the Helmholtz Association.
+ * Copyright © 2019-2020 Deutsches Elektronen-Synchrotron DESY,
+ * a research centre of the Helmholtz Association.
*
* Authors:
- * 2019 Thomas White <taw@physics.org>
+ * 2019-2020 Thomas White <taw@physics.org>
*
* This file is part of CrystFEL.
*
@@ -53,11 +53,16 @@ extern "C" {
extern DataTemplate *data_template_new_from_file(const char *filename);
extern void data_template_free(DataTemplate *dt);
-extern signed int data_template_find_panel(const DataTemplate *dt,
- int fs, int ss);
+extern const char *data_template_panel_name(const DataTemplate *dt,
+ int pn);
-extern void data_template_file_to_panel_coords(const DataTemplate *dt,
- float *pfs, float *pss);
+extern int data_template_file_to_panel_coords(const DataTemplate *dt,
+ float *pfs, float *pss,
+ int *pn);
+
+extern int data_template_panel_to_file_coords(const DataTemplate *dt,
+ int pn,
+ float *pfs, float *pss);
extern void data_template_add_copy_header(DataTemplate *dt,
const char *header);
diff --git a/libcrystfel/src/image.c b/libcrystfel/src/image.c
index 8cfe3473..9474d266 100644
--- a/libcrystfel/src/image.c
+++ b/libcrystfel/src/image.c
@@ -1882,18 +1882,17 @@ ImageFeatureList *get_peaks_cxi_dtempl(const DataTemplate *dtempl,
ss = buf_y[pk] + peak_offset;
val = buf_i[pk];
- pn = data_template_find_panel(dtempl, fs, ss);
- if ( pn < -1 ) {
- ERROR("Peak not in panel!\n");
- continue;
+ if ( data_template_file_to_panel_coords(dtempl,
+ &fs, &ss,
+ &pn) )
+ {
+ ERROR("Failed to convert %i,%i to "
+ "panel-relative coordinates\n", fs, ss);
+ } else {
+ image_add_feature(features, fs, ss, pn,
+ NULL, val, NULL);
}
- /* Convert coordinates to panel-relative */
- data_template_file_to_panel_coords(dtempl, &fs, &ss);
-
- image_add_feature(features, fs, ss, pn,
- NULL, val, NULL);
-
}
return features;
@@ -2022,18 +2021,17 @@ ImageFeatureList *get_peaks_hdf5_dtempl(const DataTemplate *dtempl,
ss = buf[tw*i+1] + peak_offset;
val = buf[tw*i+2];
- pn = data_template_find_panel(dtempl, fs, ss);
- if ( pn < -1 ) {
- ERROR("Peak not in panel!\n");
- continue;
+ if ( data_template_file_to_panel_coords(dtempl,
+ &fs, &ss,
+ &pn) )
+ {
+ ERROR("Failed to convert %i,%i to "
+ "panel-relative coordinates\n", fs, ss);
+ } else {
+ image_add_feature(features, fs, ss, pn,
+ NULL, val, NULL);
}
- /* Convert coordinates to panel-relative */
- data_template_file_to_panel_coords(dtempl, &fs, &ss);
-
- image_add_feature(features, fs, ss, pn,
- NULL, val, NULL);
-
}
free(buf);
diff --git a/libcrystfel/src/predict-refine.c b/libcrystfel/src/predict-refine.c
index bb8c5c35..a3841e8c 100644
--- a/libcrystfel/src/predict-refine.c
+++ b/libcrystfel/src/predict-refine.c
@@ -73,8 +73,8 @@ struct reflpeak {
Reflection *refl;
struct imagefeature *peak;
double Ih; /* normalised */
- struct panel *panel; /* panel the reflection appears on
- * (we assume this never changes) */
+ struct detgeom_panel *panel; /* panel the reflection appears on
+ * (we assume this never changes) */
};
@@ -122,50 +122,6 @@ static double y_dev(struct reflpeak *rp, struct detector *det)
}
-static void UNUSED write_pairs(const char *filename, struct reflpeak *rps,
- int n, struct detector *det)
-{
- int i;
- FILE *fh;
-
- fh = fopen(filename, "w");
- if ( fh == NULL ) {
- ERROR("Failed to open '%s'\n", filename);
- return;
- }
-
- for ( i=0; i<n; i++ ) {
-
- double write_fs, write_ss;
- double fs, ss;
- struct panel *p;
- signed int h, k, l;
-
- fs = rps[i].peak->fs;
- ss = rps[i].peak->ss;
- p = rps[i].panel;
- get_indices(rps[i].refl, &h, &k, &l);
-
- write_fs = fs + p->orig_min_fs;
- write_ss = ss + p->orig_min_ss;
-
- fprintf(fh, "%7.2f %7.2f dev r,x,y: %9f %9f %9f %9f\n",
- write_fs, write_ss,
- r_dev(&rps[i])/1e9, fabs(r_dev(&rps[i])/1e9),
- x_dev(&rps[i], det),
- y_dev(&rps[i], det));
-
- //fprintf(fh, "%4i %4i %4i 0.0 - 0.0 1 %7.2f %7.2f %s\n",
- // h, k, l, write_fs, write_ss, p->name);
-
- }
-
- fclose(fh);
-
- STATUS("Wrote %i pairs to %s\n", n, filename);
-}
-
-
static int cmpd2(const void *av, const void *bv)
{
struct reflpeak *a, *b;
@@ -186,7 +142,6 @@ static int check_outlier_transition(struct reflpeak *rps, int n,
if ( n < 3 ) return n;
qsort(rps, n, sizeof(struct reflpeak), cmpd2);
- //write_pairs("pairs-before-outlier.lst", rps, n, det);
for ( i=1; i<n-1; i++ ) {
@@ -267,11 +222,11 @@ static int pair_peaks(struct image *image, Crystal *cr,
* in how far away it is from the peak location.
* The predicted position and excitation errors will be
* filled in by update_predictions(). */
- set_panel(refl, &image->det->panels[f->pn]);
+ set_panel_number(refl, f->pn);
rps[n].refl = refl;
rps[n].peak = f;
- rps[n].panel = &image->det->panels[f->pn];
+ rps[n].panel = &image->detgeom->panels[f->pn];
n++;
}
diff --git a/libcrystfel/src/stream.c b/libcrystfel/src/stream.c
index 419acd36..3343750c 100644
--- a/libcrystfel/src/stream.c
+++ b/libcrystfel/src/stream.c
@@ -51,6 +51,7 @@
#include "stream.h"
#include "reflist.h"
#include "reflist-utils.h"
+#include "datatemplate.h"
/** \file stream.h */
@@ -301,7 +302,8 @@ static int write_peaks_2_3(struct image *image, FILE *ofh)
}
-static RefList *read_stream_reflections_2_3(Stream *st, struct detector *det)
+static RefList *read_stream_reflections_2_3(Stream *st,
+ const DataTemplate *dtempl)
{
char *rval = NULL;
int first = 1;
@@ -342,24 +344,19 @@ static RefList *read_stream_reflections_2_3(Stream *st, struct detector *det)
if ( r == 10 ) {
- struct panel *p;
-
refl = add_refl(out, h, k, l);
if ( refl == NULL ) {
ERROR("Failed to add reflection\n");
return NULL;
}
set_intensity(refl, intensity);
- if ( det != NULL ) {
- double write_fs, write_ss;
- p = find_panel_by_name(det,pn);
- if ( p == NULL ) {
- ERROR("Couldn't find panel '%s'\n", pn);
+ if ( dtempl != NULL ) {
+ int pn;
+ if ( data_template_file_to_panel_coords(dtempl, &fs, &ss, &pn) ) {
+ ERROR("Failed to convert\n");
} else {
- write_fs = fs - p->orig_min_fs;
- write_ss = ss - p->orig_min_ss;
- set_detector_pos(refl, write_fs, write_ss);
- set_panel(refl, p);
+ set_detector_pos(refl, fs, ss);
+ set_panel_number(refl, pn);
}
}
set_esd_intensity(refl, sigma);
@@ -376,7 +373,8 @@ static RefList *read_stream_reflections_2_3(Stream *st, struct detector *det)
}
-static RefList *read_stream_reflections_2_1(Stream *st, struct detector *det)
+static RefList *read_stream_reflections_2_1(Stream *st,
+ const DataTemplate *dtempl)
{
char *rval = NULL;
int first = 1;
@@ -426,19 +424,14 @@ static RefList *read_stream_reflections_2_1(Stream *st, struct detector *det)
}
set_intensity(refl, intensity);
- if ( det != NULL ) {
+ if ( dtempl != NULL ) {
- double write_fs, write_ss;
- struct panel *p;
-
- p = find_orig_panel(det, fs, ss);
- if ( p == NULL ) {
- ERROR("No panel at %.2f,%.2f\n",
- fs, ss);
+ int pn;
+ if ( data_template_file_to_panel_coords(dtempl, &fs, &ss, &pn) ) {
+ ERROR("Failed to convert\n");
} else {
- write_fs = fs - p->orig_min_fs;
- write_ss = ss - p->orig_min_ss;
- set_detector_pos(refl, write_fs, write_ss);
+ set_detector_pos(refl, fs, ss);
+ set_panel_number(refl, pn);
}
} else {
@@ -462,7 +455,8 @@ static RefList *read_stream_reflections_2_1(Stream *st, struct detector *det)
}
-static RefList *read_stream_reflections_2_2(Stream *st, struct detector *det)
+static RefList *read_stream_reflections_2_2(Stream *st,
+ const DataTemplate *dtempl)
{
char *rval = NULL;
int first = 1;
@@ -502,19 +496,17 @@ static RefList *read_stream_reflections_2_2(Stream *st, struct detector *det)
}
set_intensity(refl, intensity);
- if ( det != NULL ) {
+ if ( dtempl != NULL ) {
- double write_fs, write_ss;
- struct panel *p;
+ int pn;
- p = find_orig_panel(det, fs, ss);
- if ( p == NULL ) {
- ERROR("No panel at %.2f,%.2f\n",
- fs, ss);
+ if ( data_template_file_to_panel_coords(dtempl, &fs, &ss, &pn) ) {
+ ERROR("Failed to convert to "
+ "panel-relative coordinates: "
+ "%i,%i\n", fs, ss);
} else {
- write_fs = fs - p->orig_min_fs;
- write_ss = ss - p->orig_min_ss;
- set_detector_pos(refl, write_fs, write_ss);
+ set_detector_pos(refl, fs, ss);
+ set_panel_number(refl, pn);
}
} else {
@@ -538,139 +530,8 @@ static RefList *read_stream_reflections_2_2(Stream *st, struct detector *det)
}
-static int write_stream_reflections_2_1(FILE *fh, RefList *list,
- struct image *image)
-{
- Reflection *refl;
- RefListIterator *iter;
-
- fprintf(fh, " h k l I phase sigma(I) "
- " counts fs/px ss/px\n");
-
- for ( refl = first_refl(list, &iter);
- refl != NULL;
- refl = next_refl(refl, iter) )
- {
-
- signed int h, k, l;
- double intensity, esd_i, ph;
- int red;
- double fs, ss;
- char phs[16];
- int have_phase;
-
- get_indices(refl, &h, &k, &l);
- get_detector_pos(refl, &fs, &ss);
- intensity = get_intensity(refl);
- esd_i = get_esd_intensity(refl);
- red = get_redundancy(refl);
- ph = get_phase(refl, &have_phase);
-
- /* Reflections with redundancy = 0 are not written */
- if ( red == 0 ) continue;
-
- if ( have_phase ) {
- snprintf(phs, 16, "%8.2f", rad2deg(ph));
- } else {
- strncpy(phs, " -", 15);
- }
-
- if ( image->det != NULL ) {
-
- struct panel *p;
- double write_fs, write_ss;
-
- p = find_orig_panel(image->det, fs, ss);
- if ( p == NULL ) {
- ERROR("Panel not found\n");
- return 1;
- }
-
- /* Convert coordinates to match arrangement of panels
- * in HDF5 file */
- write_fs = fs + p->orig_min_fs;
- write_ss = ss + p->orig_min_ss;
-
- fprintf(fh, "%3i %3i %3i %10.2f %s %10.2f %7i "
- "%6.1f %6.1f\n",
- h, k, l, intensity, phs, esd_i, red,
- write_fs, write_ss);
-
- } else {
-
- fprintf(fh, "%3i %3i %3i %10.2f %s %10.2f %7i "
- "%6.1f %6.1f\n",
- h, k, l, intensity, phs, esd_i, red,
- fs, ss);
-
- }
- }
- return 0;
-}
-
-
-static int write_stream_reflections_2_2(FILE *fh, RefList *list,
- struct image *image)
-{
- Reflection *refl;
- RefListIterator *iter;
-
- fprintf(fh, " h k l I sigma(I) "
- "peak background fs/px ss/px\n");
-
- for ( refl = first_refl(list, &iter);
- refl != NULL;
- refl = next_refl(refl, iter) )
- {
-
- signed int h, k, l;
- double intensity, esd_i, bg, pk;
- double fs, ss;
-
- get_indices(refl, &h, &k, &l);
- get_detector_pos(refl, &fs, &ss);
- intensity = get_intensity(refl);
- esd_i = get_esd_intensity(refl);
- pk = get_peak(refl);
- bg = get_mean_bg(refl);
-
- /* Reflections with redundancy = 0 are not written */
- if ( get_redundancy(refl) == 0 ) continue;
-
- if ( image->det != NULL ) {
-
- struct panel *p;
- double write_fs, write_ss;
-
- p = find_orig_panel(image->det, fs, ss);
- if ( p == NULL ) {
- ERROR("Panel not found\n");
- return 1;
- }
-
- /* Convert coordinates to match arrangement of panels in HDF5
- * file */
- write_fs = fs + p->orig_min_fs;
- write_ss = ss + p->orig_min_ss;
-
- fprintf(fh, "%4i %4i %4i %10.2f %10.2f %10.2f %10.2f"
- " %6.1f %6.1f\n",
- h, k, l, intensity, esd_i, pk, bg, write_fs,
- write_ss);
-
- } else {
-
- fprintf(fh, "%4i %4i %4i %10.2f %10.2f %10.2f %10.2f"
- " %6.1f %6.1f\n",
- h, k, l, intensity, esd_i, pk, bg, fs, ss);
- }
- }
- return 0;
-}
-
-
-static int write_stream_reflections_2_3(FILE *fh, RefList *list,
- struct image *image)
+static int write_stream_reflections(FILE *fh, RefList *list,
+ const DataTemplate *dtempl)
{
Reflection *refl;
RefListIterator *iter;
@@ -685,13 +546,14 @@ static int write_stream_reflections_2_3(FILE *fh, RefList *list,
signed int h, k, l;
double intensity, esd_i, pk, bg;
- double fs, ss;
- double write_fs, write_ss;
- struct panel *p;
+ double dfs, dss;
+ float fs, ss;
+ int pn;
get_indices(refl, &h, &k, &l);
- get_detector_pos(refl, &fs, &ss);
- p = get_panel(refl);
+ get_detector_pos(refl, &dfs, &dss);
+ fs = dfs; ss = dss;
+ pn = get_panel_number(refl);
intensity = get_intensity(refl);
esd_i = get_esd_intensity(refl);
pk = get_peak(refl);
@@ -700,14 +562,13 @@ static int write_stream_reflections_2_3(FILE *fh, RefList *list,
/* Reflections with redundancy = 0 are not written */
if ( get_redundancy(refl) == 0 ) continue;
- write_fs = fs+p->orig_min_fs;
- write_ss = ss+p->orig_min_ss;
+ data_template_panel_to_file_coords(dtempl, pn,
+ &fs, &ss);
- fprintf(fh,
- "%4i %4i %4i %10.2f %10.2f %10.2f %10.2f "
- "%6.1f %6.1f %s\n",
- h, k, l, intensity, esd_i, pk, bg,
- write_fs, write_ss, p->name);
+ fprintf(fh, "%4i %4i %4i %10.2f %10.2f %10.2f %10.2f "
+ "%6.1f %6.1f %s\n",
+ h, k, l, intensity, esd_i, pk, bg,
+ fs, ss, data_template_panel_name(dtempl, pn));
}
return 0;
@@ -731,7 +592,9 @@ static int num_integrated_reflections(RefList *list)
}
-static int write_crystal(Stream *st, Crystal *cr, int include_reflections)
+static int write_crystal(Stream *st, Crystal *cr,
+ const DataTemplate *dtempl,
+ int include_reflections)
{
UnitCell *cell;
RefList *reflist;
@@ -802,26 +665,9 @@ static int write_crystal(Stream *st, Crystal *cr, int include_reflections)
if ( reflist != NULL ) {
- struct image *image;
-
- image = crystal_get_image(cr);
-
fprintf(st->fh, REFLECTION_START_MARKER"\n");
- if ( AT_LEAST_VERSION(st, 2, 3) ) {
- ret = write_stream_reflections_2_3(st->fh,
- reflist,
- image);
- } else if ( AT_LEAST_VERSION(st, 2, 2) ) {
- ret = write_stream_reflections_2_2(st->fh,
- reflist,
- image);
- } else {
- /* This function writes like a normal reflection
- * list was written in stream 2.1 */
- ret = write_stream_reflections_2_1(st->fh,
- reflist,
- image);
- }
+ ret = write_stream_reflections(st->fh, reflist,
+ dtempl);
fprintf(st->fh, REFLECTION_END_MARKER"\n");
} else {
@@ -848,6 +694,7 @@ static int write_crystal(Stream *st, Crystal *cr, int include_reflections)
* \returns non-zero on error.
*/
int write_chunk(Stream *st, struct image *i,
+ const DataTemplate *dtempl,
int include_peaks, int include_reflections)
{
int j;
@@ -903,7 +750,7 @@ int write_chunk(Stream *st, struct image *i,
for ( j=0; j<i->n_crystals; j++ ) {
if ( crystal_get_user_flag(i->crystals[j]) == 0 ) {
- ret = write_crystal(st, i->crystals[j],
+ ret = write_crystal(st, i->crystals[j], dtempl,
include_reflections);
}
}
@@ -945,7 +792,8 @@ static int find_start_of_chunk(Stream *st)
}
-static void read_crystal(Stream *st, struct image *image, StreamReadFlags srf)
+static void read_crystal(Stream *st, struct image *image,
+ const DataTemplate *dtempl, StreamReadFlags srf)
{
char line[1024];
char *rval = NULL;
@@ -1073,13 +921,13 @@ static void read_crystal(Stream *st, struct image *image, StreamReadFlags srf)
* after 2.2 */
if ( AT_LEAST_VERSION(st, 2, 3) ) {
reflist = read_stream_reflections_2_3(st,
- image->det);
+ dtempl);
} else if ( AT_LEAST_VERSION(st, 2, 2) ) {
reflist = read_stream_reflections_2_2(st,
- image->det);
+ dtempl);
} else {
reflist = read_stream_reflections_2_1(st,
- image->det);
+ dtempl);
}
if ( reflist == NULL ) {
ERROR("Failed while reading reflections\n");
@@ -1147,7 +995,8 @@ static void read_crystal(Stream *st, struct image *image, StreamReadFlags srf)
/**
* Read the next chunk from a stream and fill in 'image'
*/
-int read_chunk_2(Stream *st, struct image *image, StreamReadFlags srf)
+int read_chunk(Stream *st, struct image *image,
+ const DataTemplate *dtempl, StreamReadFlags srf)
{
char line[1024];
char *rval = NULL;
@@ -1260,7 +1109,7 @@ int read_chunk_2(Stream *st, struct image *image, StreamReadFlags srf)
if ( (srf & STREAM_READ_CRYSTALS)
&& (strcmp(line, CRYSTAL_START_MARKER) == 0) ) {
- read_crystal(st, image, srf);
+ read_crystal(st, image, dtempl, srf);
}
/* A chunk must have at least a filename and a wavelength,
@@ -1282,23 +1131,6 @@ int read_chunk_2(Stream *st, struct image *image, StreamReadFlags srf)
}
-
-/**
- * \param st A \ref Stream
- * \param image An \ref image structure to be filled
- *
- * Reads a chunk from \p st, placing the information in \p image.
- *
- * \returns non-zero on error.
- */
-int read_chunk(Stream *st, struct image *image)
-{
- return read_chunk_2(st, image, STREAM_READ_UNITCELL
- | STREAM_READ_REFLECTIONS
- | STREAM_READ_PEAKS);
-}
-
-
void write_stream_header(FILE *ofh, int argc, char *argv[])
{
int i;
diff --git a/libcrystfel/src/stream.h b/libcrystfel/src/stream.h
index 18a983c9..0a726bfb 100644
--- a/libcrystfel/src/stream.h
+++ b/libcrystfel/src/stream.h
@@ -41,9 +41,8 @@
*/
struct image;
-struct hdfile;
-struct event;
-struct imagefile;
+
+#include "datatemplate.h"
#include "cell.h"
#define GEOM_START_MARKER "----- Begin geometry file -----"
@@ -116,12 +115,13 @@ extern void close_stream(Stream *st);
extern void free_stuff_from_stream(struct stuff_from_stream *sfs);
-extern int read_chunk(Stream *st, struct image *image);
-extern int read_chunk_2(Stream *st, struct image *image,
- StreamReadFlags srf);
+extern int read_chunk(Stream *st, struct image *image,
+ const DataTemplate *dtempl,
+ StreamReadFlags srf);
extern int stream_has_old_indexers(Stream *st);
extern int write_chunk(Stream *st, struct image *image,
+ const DataTemplate *dtempl,
int include_peaks, int include_reflections);
extern void write_command(Stream *st, int argc, char *argv[]);
diff --git a/src/ambigator.c b/src/ambigator.c
index 800c05de..b4e4b8f8 100644
--- a/src/ambigator.c
+++ b/src/ambigator.c
@@ -1256,8 +1256,9 @@ int main(int argc, char *argv[])
cur.det = NULL;
- if ( read_chunk_2(st, &cur, STREAM_READ_UNITCELL
- | STREAM_READ_REFLECTIONS) != 0 ) {
+ if ( read_chunk(st, &cur, NULL,
+ STREAM_READ_UNITCELL | STREAM_READ_REFLECTIONS) != 0 )
+ {
break;
}
diff --git a/src/cell_explorer.c b/src/cell_explorer.c
index 4ae406ce..5648ac3c 100644
--- a/src/cell_explorer.c
+++ b/src/cell_explorer.c
@@ -2001,7 +2001,7 @@ int main(int argc, char *argv[])
cur.det = NULL;
- if ( read_chunk_2(st, &cur, STREAM_READ_UNITCELL) != 0 ) {
+ if ( read_chunk(st, &cur, NULL, STREAM_READ_UNITCELL) != 0 ) {
break;
}
diff --git a/src/im-zmq.c b/src/im-zmq.c
index 39f1d207..09230938 100644
--- a/src/im-zmq.c
+++ b/src/im-zmq.c
@@ -228,17 +228,13 @@ ImageFeatureList *get_peaks_msgpack(msgpack_object *obj,
ss = peak_y->via.array.ptr[pk].via.f64 + peak_offset;
val = peak_i->via.array.ptr[pk].via.f64;
- pn = data_template_find_panel(dtempl, fs, ss);
- if ( pn < -1 ) {
+ /* Convert coordinates to panel-relative */
+ if ( data_template_file_to_panel_coords(dtempl, &fs, &ss, &pn) ) {
ERROR("Peak not in panel!\n");
- continue;
+ } else {
+ image_add_feature(features, fs, ss, pn,
+ NULL, val, NULL);
}
-
- /* Convert coordinates to panel-relative */
- data_template_file_to_panel_coords(dtempl, &fs, &ss);
-
- image_add_feature(features, fs, ss, pn,
- NULL, val, NULL);
}
return features;
diff --git a/src/partialator.c b/src/partialator.c
index 032eb0d9..b7641d08 100644
--- a/src/partialator.c
+++ b/src/partialator.c
@@ -1379,8 +1379,9 @@ int main(int argc, char *argv[])
cur.div = NAN;
cur.bw = NAN;
cur.det = NULL;
- if ( read_chunk_2(st, &cur, STREAM_READ_REFLECTIONS
- | STREAM_READ_UNITCELL) != 0 ) {
+ if ( read_chunk(st, &cur, NULL,
+ STREAM_READ_REFLECTIONS | STREAM_READ_UNITCELL) != 0 )
+ {
break;
}
diff --git a/src/process_hkl.c b/src/process_hkl.c
index 5aadda47..ec980db1 100644
--- a/src/process_hkl.c
+++ b/src/process_hkl.c
@@ -429,8 +429,8 @@ static int merge_all(Stream *st, RefList *model, RefList *reference,
image.det = NULL;
/* Get data from next chunk */
- rval = read_chunk_2(st, &image, STREAM_READ_REFLECTIONS |
- STREAM_READ_UNITCELL);
+ rval = read_chunk(st, &image, NULL,
+ STREAM_READ_REFLECTIONS | STREAM_READ_UNITCELL);
if ( rval ) break;
n_images++;
diff --git a/src/process_image.c b/src/process_image.c
index 5fdafdbe..34483f46 100644
--- a/src/process_image.c
+++ b/src/process_image.c
@@ -407,8 +407,8 @@ streamwrite:
time_accounts_set(taccs, TACC_WRITESTREAM);
set_last_task(last_task, "stream write");
sb_shared->pings[cookie]++;
- ret = write_chunk(st, image, iargs->stream_peaks,
- iargs->stream_refls);
+ ret = write_chunk(st, image, iargs->dtempl,
+ iargs->stream_peaks, iargs->stream_refls);
if ( ret != 0 ) {
ERROR("Error writing stream file.\n");
}
diff --git a/src/whirligig.c b/src/whirligig.c
index ee74a25e..843403ec 100644
--- a/src/whirligig.c
+++ b/src/whirligig.c
@@ -719,8 +719,9 @@ int main(int argc, char *argv[])
cur.div = NAN;
cur.bw = NAN;
cur.det = NULL;
- if ( read_chunk_2(st, &cur, STREAM_READ_REFLECTIONS
- | STREAM_READ_UNITCELL) != 0 ) {
+ if ( read_chunk(st, &cur, NULL,
+ STREAM_READ_REFLECTIONS | STREAM_READ_UNITCELL) != 0 )
+ {
break;
}