aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2010-09-24 18:25:49 +0200
committerThomas White <taw@physics.org>2012-02-22 15:26:59 +0100
commit8bb2c7e3f5f4cfe9793256c009f62b0289607332 (patch)
treec00a292d572d268eb6a108105edb7154ab97deb4
parent7b3e720829c62b63259b65ede4a4006e4417b32e (diff)
Move stream handling functions to a separate module
-rw-r--r--Makefile.am3
-rw-r--r--Makefile.in3
-rw-r--r--src/Makefile.am6
-rw-r--r--src/Makefile.in14
-rw-r--r--src/cubeit.c70
-rw-r--r--src/process_hkl.c21
-rw-r--r--src/reintegrate.c70
-rw-r--r--src/stream.c111
-rw-r--r--src/stream.h24
9 files changed, 153 insertions, 169 deletions
diff --git a/Makefile.am b/Makefile.am
index daa4e174..111ec48d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -9,5 +9,6 @@ EXTRA_DIST = configure src/cell.h src/hdf5-file.h src/image.h \
src/povray.h src/index-priv.h src/geometry.h src/templates.h \
data/sfac/Ca.nff data/sfac/C.nff data/sfac/Fe.nff data/sfac/H.nff \
data/sfac/Mg.nff data/sfac/N.nff data/sfac/O.nff data/sfac/P.nff \
- data/sfac/S.nff data/sfac/f0_WaasKirf.dat src/render_hkl.h
+ data/sfac/S.nff data/sfac/f0_WaasKirf.dat src/render_hkl.h \
+ src/stream.h
SUBDIRS = src data doc scripts
diff --git a/Makefile.in b/Makefile.in
index e9f28d3e..154245aa 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -207,7 +207,8 @@ EXTRA_DIST = configure src/cell.h src/hdf5-file.h src/image.h \
src/povray.h src/index-priv.h src/geometry.h src/templates.h \
data/sfac/Ca.nff data/sfac/C.nff data/sfac/Fe.nff data/sfac/H.nff \
data/sfac/Mg.nff data/sfac/N.nff data/sfac/O.nff data/sfac/P.nff \
- data/sfac/S.nff data/sfac/f0_WaasKirf.dat src/render_hkl.h
+ data/sfac/S.nff data/sfac/f0_WaasKirf.dat src/render_hkl.h \
+ src/stream.h
SUBDIRS = src data doc scripts
all: config.h
diff --git a/src/Makefile.am b/src/Makefile.am
index fa6a6f41..09ee5062 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -18,7 +18,7 @@ endif
pattern_sim_LDADD = @LIBS@
process_hkl_SOURCES = process_hkl.c sfac.c statistics.c cell.c utils.c \
- reflections.c symmetry.c
+ reflections.c symmetry.c stream.c
process_hkl_LDADD = @LIBS@
indexamajig_SOURCES = indexamajig.c hdf5-file.c utils.c cell.c image.c \
@@ -62,11 +62,11 @@ facetron_SOURCES = facetron.c cell.c hdf5-file.c utils.c detector.c peaks.c \
facetron_LDADD = @LIBS@
cubeit_SOURCES = cubeit.c cell.c hdf5-file.c utils.c detector.c diffraction.c \
- sfac.c render.c filters.c image.c symmetry.c
+ sfac.c render.c filters.c image.c symmetry.c stream.c
cubeit_LDADD = @LIBS@
reintegrate_SOURCES = reintegrate.c cell.c hdf5-file.c utils.c detector.c \
- peaks.c image.c diffraction.c sfac.c geometry.c
+ peaks.c image.c diffraction.c sfac.c geometry.c stream.c
reintegrate_LDADD = @LIBS@
INCLUDES = "-I$(top_srcdir)/data"
diff --git a/src/Makefile.in b/src/Makefile.in
index 81a5c34e..8c8e93e0 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -67,7 +67,8 @@ compare_hkl_DEPENDENCIES =
am_cubeit_OBJECTS = cubeit.$(OBJEXT) cell.$(OBJEXT) \
hdf5-file.$(OBJEXT) utils.$(OBJEXT) detector.$(OBJEXT) \
diffraction.$(OBJEXT) sfac.$(OBJEXT) render.$(OBJEXT) \
- filters.$(OBJEXT) image.$(OBJEXT) symmetry.$(OBJEXT)
+ filters.$(OBJEXT) image.$(OBJEXT) symmetry.$(OBJEXT) \
+ stream.$(OBJEXT)
cubeit_OBJECTS = $(am_cubeit_OBJECTS)
cubeit_DEPENDENCIES =
am_facetron_OBJECTS = facetron.$(OBJEXT) cell.$(OBJEXT) \
@@ -118,13 +119,13 @@ powder_plot_OBJECTS = $(am_powder_plot_OBJECTS)
powder_plot_DEPENDENCIES =
am_process_hkl_OBJECTS = process_hkl.$(OBJEXT) sfac.$(OBJEXT) \
statistics.$(OBJEXT) cell.$(OBJEXT) utils.$(OBJEXT) \
- reflections.$(OBJEXT) symmetry.$(OBJEXT)
+ reflections.$(OBJEXT) symmetry.$(OBJEXT) stream.$(OBJEXT)
process_hkl_OBJECTS = $(am_process_hkl_OBJECTS)
process_hkl_DEPENDENCIES =
am_reintegrate_OBJECTS = reintegrate.$(OBJEXT) cell.$(OBJEXT) \
hdf5-file.$(OBJEXT) utils.$(OBJEXT) detector.$(OBJEXT) \
peaks.$(OBJEXT) image.$(OBJEXT) diffraction.$(OBJEXT) \
- sfac.$(OBJEXT) geometry.$(OBJEXT)
+ sfac.$(OBJEXT) geometry.$(OBJEXT) stream.$(OBJEXT)
reintegrate_OBJECTS = $(am_reintegrate_OBJECTS)
reintegrate_DEPENDENCIES =
am_render_hkl_OBJECTS = render_hkl.$(OBJEXT) cell.$(OBJEXT) \
@@ -265,7 +266,7 @@ pattern_sim_SOURCES = pattern_sim.c diffraction.c utils.c image.c \
$(am__append_2)
pattern_sim_LDADD = @LIBS@
process_hkl_SOURCES = process_hkl.c sfac.c statistics.c cell.c utils.c \
- reflections.c symmetry.c
+ reflections.c symmetry.c stream.c
process_hkl_LDADD = @LIBS@
indexamajig_SOURCES = indexamajig.c hdf5-file.c utils.c cell.c image.c \
@@ -301,11 +302,11 @@ facetron_SOURCES = facetron.c cell.c hdf5-file.c utils.c detector.c peaks.c \
facetron_LDADD = @LIBS@
cubeit_SOURCES = cubeit.c cell.c hdf5-file.c utils.c detector.c diffraction.c \
- sfac.c render.c filters.c image.c symmetry.c
+ sfac.c render.c filters.c image.c symmetry.c stream.c
cubeit_LDADD = @LIBS@
reintegrate_SOURCES = reintegrate.c cell.c hdf5-file.c utils.c detector.c \
- peaks.c image.c diffraction.c sfac.c geometry.c
+ peaks.c image.c diffraction.c sfac.c geometry.c stream.c
reintegrate_LDADD = @LIBS@
INCLUDES = "-I$(top_srcdir)/data"
@@ -453,6 +454,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/render_hkl.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sfac.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/statistics.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stream.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/symmetry.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/templates.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/utils.Po@am__quote@
diff --git a/src/cubeit.c b/src/cubeit.c
index f6ff2c67..4bc466a6 100644
--- a/src/cubeit.c
+++ b/src/cubeit.c
@@ -31,6 +31,7 @@
#include "diffraction.h"
#include "render.h"
#include "symmetry.h"
+#include "stream.h"
#define MAX_THREADS (256)
@@ -383,75 +384,6 @@ static void write_slice(const char *filename, double *vals, int z,
}
-static UnitCell *read_orientation_matrix(FILE *fh)
-{
- float u, v, w;
- struct rvec as, bs, cs;
- UnitCell *cell;
- char line[1024];
-
- if ( fgets(line, 1023, fh) == NULL ) return NULL;
- if ( sscanf(line, "astar = %f %f %f", &u, &v, &w) != 3 ) {
- ERROR("Couldn't read a-star\n");
- return NULL;
- }
- as.u = u*1e9; as.v = v*1e9; as.w = w*1e9;
- if ( fgets(line, 1023, fh) == NULL ) return NULL;
- if ( sscanf(line, "bstar = %f %f %f", &u, &v, &w) != 3 ) {
- ERROR("Couldn't read b-star\n");
- return NULL;
- }
- bs.u = u*1e9; bs.v = v*1e9; bs.w = w*1e9;
- if ( fgets(line, 1023, fh) == NULL ) return NULL;
- if ( sscanf(line, "cstar = %f %f %f", &u, &v, &w) != 3 ) {
- ERROR("Couldn't read c-star\n");
- return NULL;
- }
- cs.u = u*1e9; cs.v = v*1e9; cs.w = w*1e9;
- cell = cell_new_from_axes(as, bs, cs);
-
- return cell;
-}
-
-
-static int find_chunk(FILE *fh, UnitCell **cell, char **filename)
-{
- char line[1024];
- char *rval = NULL;
-
- do {
-
- rval = fgets(line, 1023, fh);
- if ( rval == NULL ) continue;
-
- chomp(line);
-
- if ( strncmp(line, "Reflections from indexing", 25) != 0 ) {
- continue;
- }
-
- *filename = strdup(line+29);
-
- /* Skip two lines (while checking for errors) */
- rval = fgets(line, 1023, fh);
- if ( rval == NULL ) continue;
- rval = fgets(line, 1023, fh);
- if ( rval == NULL ) continue;
-
- *cell = read_orientation_matrix(fh);
- if ( *cell == NULL ) {
- STATUS("Got filename but no cell for %s\n", *filename);
- continue;
- }
-
- return 0;
-
- } while ( rval != NULL );
-
- return 1;
-}
-
-
static void add_to_mean(UnitCell *cell, double *ast, double *bst, double *cst,
double *alst, double *best, double *gast)
{
diff --git a/src/process_hkl.c b/src/process_hkl.c
index 0df12e75..7bc04846 100644
--- a/src/process_hkl.c
+++ b/src/process_hkl.c
@@ -26,6 +26,7 @@
#include "sfac.h"
#include "reflections.h"
#include "symmetry.h"
+#include "stream.h"
/* Number of divisions for intensity histograms */
@@ -535,26 +536,6 @@ static void merge_all(FILE *fh, double **pmodel, ReflItemList **pobserved,
}
-static int count_patterns(FILE *fh)
-{
- char *rval;
-
- int n_total_patterns = 0;
- do {
- char line[1024];
-
- rval = fgets(line, 1023, fh);
- if ( rval == NULL ) continue;
- if ( (strncmp(line, "Reflections from indexing", 25) == 0)
- || (strncmp(line, "New pattern", 11) == 0) ) {
- n_total_patterns++;
- }
- } while ( rval != NULL );
-
- return n_total_patterns;
-}
-
-
int main(int argc, char *argv[])
{
int c;
diff --git a/src/reintegrate.c b/src/reintegrate.c
index af5f9e7a..3261ba72 100644
--- a/src/reintegrate.c
+++ b/src/reintegrate.c
@@ -28,6 +28,7 @@
#include "hdf5-file.h"
#include "symmetry.h"
#include "peaks.h"
+#include "stream.h"
#define MAX_THREADS (256)
@@ -147,75 +148,6 @@ static void *worker_thread(void *pargsv)
}
-static UnitCell *read_orientation_matrix(FILE *fh)
-{
- float u, v, w;
- struct rvec as, bs, cs;
- UnitCell *cell;
- char line[1024];
-
- if ( fgets(line, 1023, fh) == NULL ) return NULL;
- if ( sscanf(line, "astar = %f %f %f", &u, &v, &w) != 3 ) {
- ERROR("Couldn't read a-star\n");
- return NULL;
- }
- as.u = u*1e9; as.v = v*1e9; as.w = w*1e9;
- if ( fgets(line, 1023, fh) == NULL ) return NULL;
- if ( sscanf(line, "bstar = %f %f %f", &u, &v, &w) != 3 ) {
- ERROR("Couldn't read b-star\n");
- return NULL;
- }
- bs.u = u*1e9; bs.v = v*1e9; bs.w = w*1e9;
- if ( fgets(line, 1023, fh) == NULL ) return NULL;
- if ( sscanf(line, "cstar = %f %f %f", &u, &v, &w) != 3 ) {
- ERROR("Couldn't read c-star\n");
- return NULL;
- }
- cs.u = u*1e9; cs.v = v*1e9; cs.w = w*1e9;
- cell = cell_new_from_axes(as, bs, cs);
-
- return cell;
-}
-
-
-static int find_chunk(FILE *fh, UnitCell **cell, char **filename)
-{
- char line[1024];
- char *rval = NULL;
-
- do {
-
- rval = fgets(line, 1023, fh);
- if ( rval == NULL ) continue;
-
- chomp(line);
-
- if ( strncmp(line, "Reflections from indexing", 25) != 0 ) {
- continue;
- }
-
- *filename = strdup(line+29);
-
- /* Skip two lines (while checking for errors) */
- rval = fgets(line, 1023, fh);
- if ( rval == NULL ) continue;
- rval = fgets(line, 1023, fh);
- if ( rval == NULL ) continue;
-
- *cell = read_orientation_matrix(fh);
- if ( *cell == NULL ) {
- STATUS("Got filename but no cell for %s\n", *filename);
- continue;
- }
-
- return 0;
-
- } while ( rval != NULL );
-
- return 1;
-}
-
-
static void integrate_all(int nthreads, struct detector *det, FILE *fh,
int config_basename, const char *prefix)
{
diff --git a/src/stream.c b/src/stream.c
new file mode 100644
index 00000000..75a80c72
--- /dev/null
+++ b/src/stream.c
@@ -0,0 +1,111 @@
+/*
+ * stream.c
+ *
+ * Indexed stream tools
+ *
+ * (c) 2006-2010 Thomas White <taw@physics.org>
+ *
+ * Part of CrystFEL - crystallography with a FEL
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "cell.h"
+#include "utils.h"
+
+
+int count_patterns(FILE *fh)
+{
+ char *rval;
+
+ int n_total_patterns = 0;
+ do {
+ char line[1024];
+
+ rval = fgets(line, 1023, fh);
+ if ( rval == NULL ) continue;
+ if ( (strncmp(line, "Reflections from indexing", 25) == 0)
+ || (strncmp(line, "New pattern", 11) == 0) ) {
+ n_total_patterns++;
+ }
+ } while ( rval != NULL );
+
+ return n_total_patterns;
+}
+
+
+static UnitCell *read_orientation_matrix(FILE *fh)
+{
+ float u, v, w;
+ struct rvec as, bs, cs;
+ UnitCell *cell;
+ char line[1024];
+
+ if ( fgets(line, 1023, fh) == NULL ) return NULL;
+ if ( sscanf(line, "astar = %f %f %f", &u, &v, &w) != 3 ) {
+ ERROR("Couldn't read a-star\n");
+ return NULL;
+ }
+ as.u = u*1e9; as.v = v*1e9; as.w = w*1e9;
+ if ( fgets(line, 1023, fh) == NULL ) return NULL;
+ if ( sscanf(line, "bstar = %f %f %f", &u, &v, &w) != 3 ) {
+ ERROR("Couldn't read b-star\n");
+ return NULL;
+ }
+ bs.u = u*1e9; bs.v = v*1e9; bs.w = w*1e9;
+ if ( fgets(line, 1023, fh) == NULL ) return NULL;
+ if ( sscanf(line, "cstar = %f %f %f", &u, &v, &w) != 3 ) {
+ ERROR("Couldn't read c-star\n");
+ return NULL;
+ }
+ cs.u = u*1e9; cs.v = v*1e9; cs.w = w*1e9;
+ cell = cell_new_from_axes(as, bs, cs);
+
+ return cell;
+}
+
+
+int find_chunk(FILE *fh, UnitCell **cell, char **filename)
+{
+ char line[1024];
+ char *rval = NULL;
+
+ do {
+
+ rval = fgets(line, 1023, fh);
+ if ( rval == NULL ) continue;
+
+ chomp(line);
+
+ if ( strncmp(line, "Reflections from indexing", 25) != 0 ) {
+ continue;
+ }
+
+ *filename = strdup(line+29);
+
+ /* Skip two lines (while checking for errors) */
+ rval = fgets(line, 1023, fh);
+ if ( rval == NULL ) continue;
+ rval = fgets(line, 1023, fh);
+ if ( rval == NULL ) continue;
+
+ *cell = read_orientation_matrix(fh);
+ if ( *cell == NULL ) {
+ STATUS("Got filename but no cell for %s\n", *filename);
+ continue;
+ }
+
+ return 0;
+
+ } while ( rval != NULL );
+
+ return 1;
+}
diff --git a/src/stream.h b/src/stream.h
new file mode 100644
index 00000000..b21b5e4d
--- /dev/null
+++ b/src/stream.h
@@ -0,0 +1,24 @@
+/*
+ * stream.h
+ *
+ * Indexed stream tools
+ *
+ * (c) 2006-2010 Thomas White <taw@physics.org>
+ *
+ * Part of CrystFEL - crystallography with a FEL
+ *
+ */
+
+#ifndef STREAM_H
+#define STREAM_H
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+
+extern int count_patterns(FILE *fh);
+extern int find_chunk(FILE *fh, UnitCell **cell, char **filename);
+
+
+#endif /* STREAM_H */