aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel/src/detector.c
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/detector.c
parenta61f606acdfb844d105c10243fb8a1751525adea (diff)
Split nested code into separate functions
Diffstat (limited to 'libcrystfel/src/detector.c')
-rw-r--r--libcrystfel/src/detector.c124
1 files changed, 67 insertions, 57 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);
}