aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libcrystfel/src/stream.c74
-rw-r--r--libcrystfel/src/stream.h12
-rw-r--r--src/ambigator.c2
-rw-r--r--src/cell_explorer.c2
-rw-r--r--src/crystfel_gui.c1
-rw-r--r--src/im-sandbox.c2
-rw-r--r--src/indexamajig.c2
-rw-r--r--src/partial_sim.c5
-rw-r--r--src/partialator.c17
-rw-r--r--src/pattern_sim.c2
-rw-r--r--src/process_hkl.c23
-rw-r--r--src/process_image.c3
-rw-r--r--src/whirligig.c2
13 files changed, 55 insertions, 92 deletions
diff --git a/libcrystfel/src/stream.c b/libcrystfel/src/stream.c
index 6242071b..a79e006d 100644
--- a/libcrystfel/src/stream.c
+++ b/libcrystfel/src/stream.c
@@ -73,6 +73,8 @@ struct _stream
char *audit_info;
char *geometry_file;
+ const DataTemplate *dtempl;
+
long long int ln;
int old_indexers; /* True if the stream reader encountered a deprecated
@@ -95,7 +97,6 @@ int stream_has_old_indexers(Stream *st)
static ImageFeatureList *read_peaks(Stream *st,
- const DataTemplate *dtempl,
struct image *image)
{
char *rval = NULL;
@@ -145,11 +146,11 @@ static ImageFeatureList *read_peaks(Stream *st,
return NULL;
}
- if ( (panel_name[0] != '\0') && (dtempl != NULL) ) {
+ if ( (panel_name[0] != '\0') && (st->dtempl != NULL) ) {
int pn;
- if ( data_template_panel_name_to_number(dtempl,
+ if ( data_template_panel_name_to_number(st->dtempl,
panel_name,
&pn) )
{
@@ -157,7 +158,7 @@ static ImageFeatureList *read_peaks(Stream *st,
panel_name);
} else {
- data_template_file_to_panel_coords(dtempl,
+ data_template_file_to_panel_coords(st->dtempl,
&x, &y, &pn);
image_add_feature(features, x, y,
@@ -224,8 +225,7 @@ static int write_peaks(struct image *image,
}
-static RefList *read_stream_reflections_2_3(Stream *st,
- const DataTemplate *dtempl)
+static RefList *read_stream_reflections_2_3(Stream *st)
{
char *rval = NULL;
int first = 1;
@@ -272,9 +272,9 @@ static RefList *read_stream_reflections_2_3(Stream *st,
return NULL;
}
set_intensity(refl, intensity);
- if ( dtempl != NULL ) {
+ if ( st->dtempl != NULL ) {
int pn;
- if ( data_template_file_to_panel_coords(dtempl, &fs, &ss, &pn) ) {
+ if ( data_template_file_to_panel_coords(st->dtempl, &fs, &ss, &pn) ) {
ERROR("Failed to convert\n");
} else {
set_detector_pos(refl, fs, ss);
@@ -295,8 +295,7 @@ static RefList *read_stream_reflections_2_3(Stream *st,
}
-static RefList *read_stream_reflections_2_1(Stream *st,
- const DataTemplate *dtempl)
+static RefList *read_stream_reflections_2_1(Stream *st)
{
char *rval = NULL;
int first = 1;
@@ -346,10 +345,10 @@ static RefList *read_stream_reflections_2_1(Stream *st,
}
set_intensity(refl, intensity);
- if ( dtempl != NULL ) {
+ if ( st->dtempl != NULL ) {
int pn;
- if ( data_template_file_to_panel_coords(dtempl, &fs, &ss, &pn) ) {
+ if ( data_template_file_to_panel_coords(st->dtempl, &fs, &ss, &pn) ) {
ERROR("Failed to convert\n");
} else {
set_detector_pos(refl, fs, ss);
@@ -377,8 +376,7 @@ static RefList *read_stream_reflections_2_1(Stream *st,
}
-static RefList *read_stream_reflections_2_2(Stream *st,
- const DataTemplate *dtempl)
+static RefList *read_stream_reflections_2_2(Stream *st)
{
char *rval = NULL;
int first = 1;
@@ -418,11 +416,11 @@ static RefList *read_stream_reflections_2_2(Stream *st,
}
set_intensity(refl, intensity);
- if ( dtempl != NULL ) {
+ if ( st->dtempl != NULL ) {
int pn;
- if ( data_template_file_to_panel_coords(dtempl, &fs, &ss, &pn) ) {
+ if ( data_template_file_to_panel_coords(st->dtempl, &fs, &ss, &pn) ) {
ERROR("Failed to convert to "
"panel-relative coordinates: "
"%i,%i\n", fs, ss);
@@ -515,7 +513,6 @@ static int num_integrated_reflections(RefList *list)
static int write_crystal(Stream *st, Crystal *cr,
- const DataTemplate *dtempl,
int include_reflections)
{
UnitCell *cell;
@@ -589,7 +586,7 @@ static int write_crystal(Stream *st, Crystal *cr,
fprintf(st->fh, STREAM_REFLECTION_START_MARKER"\n");
ret = write_stream_reflections(st->fh, reflist,
- dtempl);
+ st->dtempl);
fprintf(st->fh, STREAM_REFLECTION_END_MARKER"\n");
} else {
@@ -616,7 +613,7 @@ static int write_crystal(Stream *st, Crystal *cr,
* \returns non-zero on error.
*/
int stream_write_chunk(Stream *st, struct image *i,
- const DataTemplate *dtempl, StreamFlags srf)
+ StreamFlags srf)
{
int j;
char *indexer;
@@ -666,7 +663,7 @@ int stream_write_chunk(Stream *st, struct image *i,
fprintf(st->fh, "peak_resolution = %f nm^-1 or %f A\n",
i->peak_resolution/1e9, 1e10/i->peak_resolution);
if ( srf & STREAM_PEAKS ) {
- ret = write_peaks(i, dtempl, st->fh);
+ ret = write_peaks(i, st->dtempl, st->fh);
}
if ( srf & STREAM_CRYSTALS ) {
@@ -674,7 +671,7 @@ int stream_write_chunk(Stream *st, struct image *i,
if ( crystal_get_user_flag(i->crystals[j]) ) {
continue;
}
- ret = write_crystal(st, i->crystals[j], dtempl,
+ ret = write_crystal(st, i->crystals[j],
srf & STREAM_REFLECTIONS);
}
}
@@ -717,7 +714,7 @@ static int find_start_of_chunk(Stream *st)
static void read_crystal(Stream *st, struct image *image,
- const DataTemplate *dtempl, StreamFlags srf)
+ StreamFlags srf)
{
char line[1024];
char *rval = NULL;
@@ -844,14 +841,11 @@ static void read_crystal(Stream *st, struct image *image,
/* The reflection list format in the stream diverges
* after 2.2 */
if ( AT_LEAST_VERSION(st, 2, 3) ) {
- reflist = read_stream_reflections_2_3(st,
- dtempl);
+ reflist = read_stream_reflections_2_3(st);
} else if ( AT_LEAST_VERSION(st, 2, 2) ) {
- reflist = read_stream_reflections_2_2(st,
- dtempl);
+ reflist = read_stream_reflections_2_2(st);
} else {
- reflist = read_stream_reflections_2_1(st,
- dtempl);
+ reflist = read_stream_reflections_2_1(st);
}
if ( reflist == NULL ) {
ERROR("Failed while reading reflections\n");
@@ -919,8 +913,7 @@ static void read_crystal(Stream *st, struct image *image,
/**
* Read the next chunk from a stream and return an image structure
*/
-struct image *stream_read_chunk(Stream *st, const DataTemplate *dtempl,
- StreamFlags srf)
+struct image *stream_read_chunk(Stream *st, StreamFlags srf)
{
char line[1024];
char *rval = NULL;
@@ -991,7 +984,7 @@ struct image *stream_read_chunk(Stream *st, const DataTemplate *dtempl,
&& strcmp(line, STREAM_PEAK_LIST_START_MARKER) == 0 ) {
ImageFeatureList *peaks;
- peaks = read_peaks(st, dtempl, image);
+ peaks = read_peaks(st, image);
if ( peaks == NULL ) {
ERROR("Failed while reading peaks\n");
@@ -1006,7 +999,7 @@ struct image *stream_read_chunk(Stream *st, const DataTemplate *dtempl,
if ( (srf & STREAM_CRYSTALS)
&& (strcmp(line, STREAM_CRYSTAL_START_MARKER) == 0) ) {
- read_crystal(st, image, dtempl, srf);
+ read_crystal(st, image, srf);
}
/* A chunk must have at least a filename and a wavelength,
@@ -1014,16 +1007,16 @@ struct image *stream_read_chunk(Stream *st, const DataTemplate *dtempl,
if ( strcmp(line, STREAM_CHUNK_END_MARKER) == 0 ) {
if ( have_filename && have_ev ) {
/* Success */
- create_detgeom(image, dtempl);
+ create_detgeom(image, st->dtempl);
if ( srf & STREAM_IMAGE_DATA ) {
image_read_image_data(image,
- dtempl,
+ st->dtempl,
image->filename,
image->ev);
} else {
- image_set_zero_data(image, dtempl);
+ image_set_zero_data(image, st->dtempl);
}
- image_set_zero_mask(image, dtempl);
+ image_set_zero_mask(image, st->dtempl);
return image;
}
ERROR("Incomplete chunk found in input file.\n");
@@ -1170,6 +1163,7 @@ static void read_geometry_file(Stream *st)
if ( success ) {
st->geometry_file = geom;
+ st->dtempl = data_template_new_from_string(geom);
}
}
@@ -1248,7 +1242,7 @@ Stream *stream_open_for_read(const char *filename)
*
* \returns A \ref Stream, or NULL on failure.
*/
-Stream *stream_open_fd_for_write(int fd)
+Stream *stream_open_fd_for_write(int fd, const DataTemplate *dtempl)
{
Stream *st;
@@ -1267,6 +1261,7 @@ Stream *stream_open_fd_for_write(int fd)
return NULL;
}
+ st->dtempl = dtempl;
st->major_version = LATEST_MAJOR_VERSION;
st->minor_version = LATEST_MINOR_VERSION;
@@ -1289,13 +1284,15 @@ void stream_write_target_cell(Stream *st, const UnitCell *cell)
/**
* \param filename Filename of new stream
+ * \param dtempl A DataTemplate
*
* Creates a new stream with name \p filename. If \p filename already
* exists, it will be overwritten.
*
* \returns A \ref Stream, or NULL on failure.
*/
-Stream *stream_open_for_write(const char *filename)
+Stream *stream_open_for_write(const char *filename,
+ const DataTemplate *dtempl)
{
Stream *st;
@@ -1308,6 +1305,7 @@ Stream *stream_open_for_write(const char *filename)
st->in_chunk = 0;
st->n_chunks = 0;
st->chunk_offsets = NULL;
+ st->dtempl = dtempl;
st->fh = fopen(filename, "w");
if ( st->fh == NULL ) {
diff --git a/libcrystfel/src/stream.h b/libcrystfel/src/stream.h
index ab98f3f9..0f28a4f8 100644
--- a/libcrystfel/src/stream.h
+++ b/libcrystfel/src/stream.h
@@ -92,8 +92,10 @@ extern "C" {
/* Opening/closing streams */
extern Stream *stream_open_for_read(const char *filename);
-extern Stream *stream_open_for_write(const char *filename);
-extern Stream *stream_open_fd_for_write(int fd);
+extern Stream *stream_open_for_write(const char *filename,
+ const DataTemplate *dtempl);
+extern Stream *stream_open_fd_for_write(int fd,
+ const DataTemplate *dtempl);
extern void stream_close(Stream *st);
/* Writing things to stream header */
@@ -120,12 +122,8 @@ extern int stream_scan_chunks(Stream *st);
extern int stream_select_chunk(Stream *st, int chunk_number);
/* Read/write chunks */
-extern struct image *stream_read_chunk(Stream *st,
- const DataTemplate *dtempl,
- StreamFlags srf);
-
+extern struct image *stream_read_chunk(Stream *st, StreamFlags srf);
extern int stream_write_chunk(Stream *st, struct image *image,
- const DataTemplate *dtempl,
StreamFlags srf);
#ifdef __cplusplus
diff --git a/src/ambigator.c b/src/ambigator.c
index fa405b4f..c3afd6c1 100644
--- a/src/ambigator.c
+++ b/src/ambigator.c
@@ -1259,7 +1259,7 @@ int main(int argc, char *argv[])
struct image *image;
int i;
- image = stream_read_chunk(st, NULL, STREAM_UNITCELL
+ image = stream_read_chunk(st, STREAM_UNITCELL
| STREAM_REFLECTIONS);
if ( image == NULL ) break;
diff --git a/src/cell_explorer.c b/src/cell_explorer.c
index 2eec4a19..84a8aa16 100644
--- a/src/cell_explorer.c
+++ b/src/cell_explorer.c
@@ -2002,7 +2002,7 @@ int main(int argc, char *argv[])
struct image *image;
int i;
- image = stream_read_chunk(st, NULL, STREAM_UNITCELL);
+ image = stream_read_chunk(st, STREAM_UNITCELL);
if ( image == NULL ) break;
for ( i=0; i<image->n_crystals; i++ ) {
diff --git a/src/crystfel_gui.c b/src/crystfel_gui.c
index a941dca6..7f4f29f0 100644
--- a/src/crystfel_gui.c
+++ b/src/crystfel_gui.c
@@ -145,7 +145,6 @@ static void update_imageview(struct crystfelproject *proj)
}
image = stream_read_chunk(proj->stream,
- proj->dtempl,
STREAM_UNITCELL
| STREAM_REFLECTIONS
| STREAM_PEAKS
diff --git a/src/im-sandbox.c b/src/im-sandbox.c
index 32c4fc13..1024b738 100644
--- a/src/im-sandbox.c
+++ b/src/im-sandbox.c
@@ -661,7 +661,7 @@ static void start_worker_process(struct sandbox *sb, int slot)
* prefix
*/
- st = stream_open_fd_for_write(stream_pipe[1]);
+ st = stream_open_fd_for_write(stream_pipe[1], sb->iargs->dtempl);
r = run_work(sb->iargs, st, slot, tmp, sb);
stream_close(st);
diff --git a/src/indexamajig.c b/src/indexamajig.c
index 2d0e53c8..15315952 100644
--- a/src/indexamajig.c
+++ b/src/indexamajig.c
@@ -993,7 +993,7 @@ int main(int argc, char *argv[])
free(rn);
/* Open output stream */
- st = stream_open_for_write(args.outfile);
+ st = stream_open_for_write(args.outfile, args.iargs.dtempl);
if ( st == NULL ) {
ERROR("Failed to open stream '%s'\n", args.outfile);
return 1;
diff --git a/src/partial_sim.c b/src/partial_sim.c
index dfadb94f..a0f60e1e 100644
--- a/src/partial_sim.c
+++ b/src/partial_sim.c
@@ -346,7 +346,6 @@ static void *create_job(void *vqargs)
struct image *image;
image = stream_read_chunk(qargs->template_stream,
- qargs->dtempl,
STREAM_UNITCELL | STREAM_REFLECTIONS);
if ( image == NULL ) {
ERROR("Failed to read template chunk!\n");
@@ -474,7 +473,7 @@ static void finalise_job(void *vqargs, void *vwargs)
int ret;
ret = stream_write_chunk(qargs->stream, wargs->image,
- qargs->dtempl, STREAM_UNITCELL
+ STREAM_UNITCELL
| STREAM_REFLECTIONS
| STREAM_CRYSTALS);
if ( ret != 0 ) {
@@ -852,7 +851,7 @@ int main(int argc, char *argv[])
ERROR("You must give a filename for the output.\n");
return 1;
}
- stream = stream_open_for_write(output_file);
+ stream = stream_open_for_write(output_file, dtempl);
if ( stream == NULL ) {
ERROR("Couldn't open output file '%s'\n", output_file);
return 1;
diff --git a/src/partialator.c b/src/partialator.c
index 959338ca..1a28e3f3 100644
--- a/src/partialator.c
+++ b/src/partialator.c
@@ -973,8 +973,6 @@ int main(int argc, char *argv[])
PartialityModel pmodel = PMODEL_XSPHERE;
int min_measurements = 2;
char *rval;
- const char *geom_str;
- DataTemplate *dtempl;
struct polarisation polarisation = {.fraction = 1.0,
.angle = 0.0,
.disable = 0};
@@ -1249,19 +1247,6 @@ int main(int argc, char *argv[])
return 1;
}
- geom_str = stream_geometry_file(st);
- if ( geom_str == NULL ) {
- ERROR("No geometry file\n");
- stream_close(st);
- return 1;
- }
-
- dtempl = data_template_new_from_string(geom_str);
- if ( dtempl == NULL ) {
- stream_close(st);
- return 1;
- }
-
if ( outfile == NULL ) {
outfile = strdup("partialator.hkl");
}
@@ -1420,7 +1405,7 @@ int main(int argc, char *argv[])
RefList *as;
int i;
- image = stream_read_chunk(st, dtempl, STREAM_REFLECTIONS
+ image = stream_read_chunk(st, STREAM_REFLECTIONS
| STREAM_UNITCELL);
if ( image == NULL ) break;
diff --git a/src/pattern_sim.c b/src/pattern_sim.c
index 4d74589b..b83677b7 100644
--- a/src/pattern_sim.c
+++ b/src/pattern_sim.c
@@ -1049,7 +1049,7 @@ int main(int argc, char *argv[])
Crystal *cr;
/* Get data from next chunk */
- templ_image = stream_read_chunk(st, dtempl,
+ templ_image = stream_read_chunk(st,
STREAM_CRYSTALS);
if ( templ_image == NULL ) break;
if ( templ_image->n_crystals == 0 ) continue;
diff --git a/src/process_hkl.c b/src/process_hkl.c
index 352bea4a..812903a2 100644
--- a/src/process_hkl.c
+++ b/src/process_hkl.c
@@ -397,7 +397,7 @@ static void display_progress(int n_images, int n_crystals, int n_crystals_used)
}
-static int merge_all(Stream *st, DataTemplate *dtempl,
+static int merge_all(Stream *st,
RefList *model, RefList *reference,
const SymOpList *sym,
double **hist_vals, signed int hist_h,
@@ -431,7 +431,7 @@ static int merge_all(Stream *st, DataTemplate *dtempl,
int i;
/* Get data from next chunk */
- image = stream_read_chunk(st, dtempl,
+ image = stream_read_chunk(st,
STREAM_REFLECTIONS
| STREAM_UNITCELL);
if ( image == NULL ) break;
@@ -517,8 +517,6 @@ int main(int argc, char *argv[])
int hist_i;
int space_for_hist = 0;
char *histo_params = NULL;
- const char *geom_str;
- DataTemplate *dtempl;
struct polarisation polarisation = {.fraction = 1.0,
.angle = 0.0,
.disable = 0};
@@ -730,19 +728,6 @@ int main(int argc, char *argv[])
return 1;
}
- geom_str = stream_geometry_file(st);
- if ( geom_str == NULL ) {
- ERROR("No geometry file found in stream\n");
- stream_close(st);
- return 1;
- }
-
- dtempl = data_template_new_from_string(geom_str);
- if ( dtempl == NULL ) {
- stream_close(st);
- return 1;
- }
-
model = reflist_new();
if ( histo != NULL ) {
@@ -799,7 +784,7 @@ int main(int argc, char *argv[])
if ( config_scale ) twopass = 1;
hist_i = 0;
- r = merge_all(st, dtempl, model, NULL, sym,
+ r = merge_all(st, model, NULL, sym,
&hist_vals, hist_h, hist_k, hist_l,
&hist_i, polarisation, min_measurements, min_snr,
max_adu, start_after, stop_after, min_res, push_res,
@@ -834,7 +819,7 @@ int main(int argc, char *argv[])
hist_i = 0;
}
- r = merge_all(st, dtempl, model, reference, sym, &hist_vals,
+ r = merge_all(st, model, reference, sym, &hist_vals,
hist_h, hist_k, hist_l, &hist_i,
polarisation, min_measurements, min_snr,
max_adu, start_after, stop_after, min_res,
diff --git a/src/process_image.c b/src/process_image.c
index a04e9468..60568ede 100644
--- a/src/process_image.c
+++ b/src/process_image.c
@@ -404,8 +404,7 @@ streamwrite:
time_accounts_set(taccs, TACC_WRITESTREAM);
set_last_task(last_task, "stream write");
sb_shared->pings[cookie]++;
- ret = stream_write_chunk(st, image, iargs->dtempl,
- iargs->stream_flags);
+ ret = stream_write_chunk(st, image, iargs->stream_flags);
if ( ret != 0 ) {
ERROR("Error writing stream file.\n");
}
diff --git a/src/whirligig.c b/src/whirligig.c
index 16688559..0d5a2f0d 100644
--- a/src/whirligig.c
+++ b/src/whirligig.c
@@ -720,7 +720,7 @@ int main(int argc, char *argv[])
struct image *image;
- image = stream_read_chunk(st, NULL, STREAM_REFLECTIONS
+ image = stream_read_chunk(st, STREAM_REFLECTIONS
| STREAM_UNITCELL);
if ( image == NULL ) break;