aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel/src
diff options
context:
space:
mode:
authorValerio Mariani <valerio.mariani@desy.de>2015-01-27 14:05:26 +0100
committervalerio.mariani@desy.de <vmariani@cfeld-valerio2.desy.de>2015-01-27 14:12:01 +0100
commitab916aa452f9e56d4246e1fbfebf2b3313f7caf1 (patch)
treea79a056cb953479cedf8ac716329ee8efcfbc64b /libcrystfel/src
parenta61f606acdfb844d105c10243fb8a1751525adea (diff)
Split nested code into separate functions
Diffstat (limited to 'libcrystfel/src')
-rw-r--r--libcrystfel/src/detector.c124
-rw-r--r--libcrystfel/src/stream.c60
2 files changed, 104 insertions, 80 deletions
diff --git a/libcrystfel/src/detector.c b/libcrystfel/src/detector.c
index 1a799637..a0de3be9 100644
--- a/libcrystfel/src/detector.c
+++ b/libcrystfel/src/detector.c
@@ -1882,6 +1882,71 @@ static void check_extents(struct panel p, double *min_x, double *min_y,
}
+static void process_panel_fields(const struct panel *p, char *line,
+ FILE *fh, char **bits,
+ int write_panel_coffset)
+{
+ char new_line[1024];
+ char string_to_write[512];
+
+ strcpy(new_line,"\0");
+ strcpy(string_to_write,"\0");
+
+ if(strstr(bits[1], "fs") != NULL &&
+ strstr(bits[1], "min_fs") == NULL &&
+ strstr(bits[1], "max_fs") == NULL) {
+
+ sprintf(string_to_write, "%+fx %+fy",
+ p->fsx, p->fsy);
+ build_output_line(line, new_line,
+ string_to_write);
+ fputs(new_line, fh);
+ return;
+
+ } else if ( strstr(bits[1], "ss") != NULL &&
+ strstr(bits[1], "min_ss") == NULL &&
+ strstr(bits[1], "max_ss") == NULL) {
+
+ sprintf(string_to_write, "%+fx %+fy",
+ p->ssx, p->ssy);
+ build_output_line(line, new_line,
+ string_to_write);
+ fputs(new_line, fh);
+ return;
+
+ } else if ( strstr(bits[1], "corner_x") != NULL) {
+
+ sprintf(string_to_write, "%g",
+ p->cnx);
+ build_output_line(line, new_line,
+ string_to_write);
+ fputs(new_line, fh);
+ return;
+
+ } else if ( strstr(bits[1], "corner_y") != NULL) {
+
+ sprintf(string_to_write, "%g",
+ p->cny);
+ build_output_line(line, new_line,
+ string_to_write);
+ fputs(new_line, fh);
+ return;
+
+ } else if ( strstr(bits[1], "coffset") != NULL) {
+
+ if ( write_panel_coffset ) {
+ return;
+ } else {
+ fputs(line, fh);
+ return;
+ }
+
+ } else {
+ fputs(line, fh);
+ }
+}
+
+
double largest_q(struct image *image)
{
struct rvec q;
@@ -1994,8 +2059,6 @@ int write_detector_geometry_2(const char *geometry_filename,
char *rval;
char line[1024];
- char new_line[1024];
- char string_to_write[512];
int n_bits;
char **bits;
@@ -2003,9 +2066,6 @@ int write_detector_geometry_2(const char *geometry_filename,
int i;
struct panel *p;
- strcpy(new_line,"\0");
- strcpy(string_to_write,"\0");
-
rval = fgets(line, 1023, ifh);
if ( rval == NULL ) break;
@@ -2023,59 +2083,9 @@ int write_detector_geometry_2(const char *geometry_filename,
p = find_panel_by_name(det, bits[0]);
if ( p != NULL ) {
+ process_panel_fields(p, line, fh, bits,
+ write_panel_coffset);
- if(strstr(bits[1], "fs") != NULL &&
- strstr(bits[1], "min_fs") == NULL &&
- strstr(bits[1], "max_fs") == NULL) {
-
- sprintf(string_to_write, "%+fx %+fy",
- p->fsx, p->fsy);
- build_output_line(line, new_line,
- string_to_write);
- fputs(new_line, fh);
- continue;
-
- } else if ( strstr(bits[1], "ss") != NULL &&
- strstr(bits[1], "min_ss") == NULL &&
- strstr(bits[1], "max_ss") == NULL) {
-
- sprintf(string_to_write, "%+fx %+fy",
- p->ssx, p->ssy);
- build_output_line(line, new_line,
- string_to_write);
- fputs(new_line, fh);
- continue;
-
- } else if ( strstr(bits[1], "corner_x") != NULL) {
-
- sprintf(string_to_write, "%g",
- p->cnx);
- build_output_line(line, new_line,
- string_to_write);
- fputs(new_line, fh);
- continue;
-
- } else if ( strstr(bits[1], "corner_y") != NULL) {
-
- sprintf(string_to_write, "%g",
- p->cny);
- build_output_line(line, new_line,
- string_to_write);
- fputs(new_line, fh);
- continue;
-
- } else if ( strstr(bits[1], "coffset") != NULL) {
-
- if ( write_panel_coffset ) {
- continue;
- } else {
- fputs(line, fh);
- continue;
- }
-
- } else {
- fputs(line, fh);
- }
} else {
fputs(line, fh);
}
diff --git a/libcrystfel/src/stream.c b/libcrystfel/src/stream.c
index 55ff73fe..118cd782 100644
--- a/libcrystfel/src/stream.c
+++ b/libcrystfel/src/stream.c
@@ -1051,6 +1051,39 @@ static void read_crystal(Stream *st, struct image *image, StreamReadFlags srf)
}
+static int read_and_store_hdf5_field(struct image *image, const char *line)
+{
+
+ char **new_fields;
+
+ if ( image->stuff_from_stream == NULL ) {
+ image->stuff_from_stream =
+ malloc(sizeof(struct stuff_from_stream));
+ if ( image->stuff_from_stream == NULL) {
+ ERROR("Failed reading hdf5 entries from "
+ "stream\n");
+ return 1;
+ }
+ image->stuff_from_stream->fields = NULL;
+ image->stuff_from_stream->n_fields = 0;
+ }
+
+ new_fields = realloc(image->stuff_from_stream->fields,
+ (1+image->stuff_from_stream->n_fields)*
+ sizeof(char *));
+ if ( new_fields == NULL ) {
+ ERROR("Failed reading hdf5 entries from stream\n");
+ return 1;
+ }
+ image->stuff_from_stream->fields = new_fields;
+ image->stuff_from_stream->fields[image->stuff_from_stream->n_fields]
+ = strdup(line);
+ image->stuff_from_stream->n_fields++;
+
+ return 0;
+}
+
+
/* Read the next chunk from a stream and fill in 'image' */
int read_chunk_2(Stream *st, struct image *image, StreamReadFlags srf)
{
@@ -1150,32 +1183,13 @@ int read_chunk_2(Stream *st, struct image *image, StreamReadFlags srf)
if ( strncmp(line, "hdf5", 3) == 0 ) {
- char **new_fields;
-
- if ( image->stuff_from_stream == NULL ) {
- image->stuff_from_stream =
- malloc(sizeof(struct stuff_from_stream));
- if ( image->stuff_from_stream == NULL) {
- ERROR("Failed reading hdf5 entries from "
- "stream\n");
- return 1;
- }
- image->stuff_from_stream->fields = NULL;
- image->stuff_from_stream->n_fields = 0;
- }
+ int fail;
- new_fields = realloc(image->stuff_from_stream->fields,
- (1+image->stuff_from_stream->n_fields)*
- sizeof(char *));
- if ( new_fields == NULL ) {
- ERROR("Failed reading hdf5 entries from stream\n");
+ fail = read_and_store_hdf5_field(image, line);
+ if ( fail ) {
+ ERROR("Failed to read hd5 fields from stream.\n");
return 1;
}
- image->stuff_from_stream->fields = new_fields;
- image->stuff_from_stream->fields[image->stuff_from_stream->n_fields]
- = strdup(line);
- image->stuff_from_stream->n_fields++;
-
}
if ( (srf & STREAM_READ_PEAKS)