aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2022-09-21 16:32:20 +0200
committerThomas White <taw@physics.org>2022-09-21 16:32:20 +0200
commit7c42f8e2b675e017ab1144ca38c9e74c24d68266 (patch)
tree2d8c969184e56a4a1260503a541446d687976f89
parentef7157ef517cf66dfc5b2c2cfc6602e30a31d060 (diff)
create_detgeom: Return detgeom structure rather than altering image argument
-rw-r--r--libcrystfel/src/datatemplate.c23
-rw-r--r--libcrystfel/src/datatemplate_priv.h6
-rw-r--r--libcrystfel/src/image.c7
-rw-r--r--libcrystfel/src/stream.c3
4 files changed, 21 insertions, 18 deletions
diff --git a/libcrystfel/src/datatemplate.c b/libcrystfel/src/datatemplate.c
index 94a8de2a..8f909eb8 100644
--- a/libcrystfel/src/datatemplate.c
+++ b/libcrystfel/src/datatemplate.c
@@ -1853,24 +1853,24 @@ static int im_get_length(struct image *image, const char *from,
}
-
-int create_detgeom(struct image *image, const DataTemplate *dtempl)
+struct detgeom *create_detgeom(struct image *image,
+ const DataTemplate *dtempl)
{
struct detgeom *detgeom;
int i;
if ( dtempl == NULL ) {
ERROR("NULL data template!\n");
- return 1;
+ return NULL;
}
detgeom = malloc(sizeof(struct detgeom));
- if ( detgeom == NULL ) return 1;
+ if ( detgeom == NULL ) return NULL;
detgeom->panels = malloc(dtempl->n_panels*sizeof(struct detgeom_panel));
if ( detgeom->panels == NULL ) {
free(detgeom);
- return 1;
+ return NULL;
}
detgeom->n_panels = dtempl->n_panels;
@@ -1888,11 +1888,10 @@ int create_detgeom(struct image *image, const DataTemplate *dtempl)
/* NB cnx,cny are in pixels, cnz is in m */
p->cnx = tmpl->cnx;
p->cny = tmpl->cny;
- if ( im_get_length(image, tmpl->cnz_from,
- 1e-3, &p->cnz) )
+ if ( im_get_length(image, tmpl->cnz_from, 1e-3, &p->cnz) )
{
ERROR("Failed to read length from '%s'\n", tmpl->cnz_from);
- return 1;
+ return NULL;
}
/* Apply offset (in m) and then convert cnz from
@@ -1905,12 +1904,12 @@ int create_detgeom(struct image *image, const DataTemplate *dtempl)
if ( im_get_length(image, dtempl->shift_x_from, 1.0, &shift_x) ) {
ERROR("Failed to read length from '%s'\n",
dtempl->shift_x_from);
- return 1;
+ return NULL;
}
if ( im_get_length(image, dtempl->shift_y_from, 1.0, &shift_y) ) {
ERROR("Failed to read length from '%s'\n",
dtempl->shift_y_from);
- return 1;
+ return NULL;
}
} else {
shift_x = 0.0;
@@ -1957,7 +1956,7 @@ int create_detgeom(struct image *image, const DataTemplate *dtempl)
}
- image->detgeom = detgeom;
+ return detgeom;
+}
- return 0;
}
diff --git a/libcrystfel/src/datatemplate_priv.h b/libcrystfel/src/datatemplate_priv.h
index 7ade9ff8..3e61f216 100644
--- a/libcrystfel/src/datatemplate_priv.h
+++ b/libcrystfel/src/datatemplate_priv.h
@@ -32,6 +32,8 @@
#ifndef DATATEMPLATE_PRIV_H
#define DATATEMPLATE_PRIV_H
+#include "detgeom.h"
+
/* Maximum number of dimensions expected in data files */
#define MAX_DIMS (16)
@@ -234,7 +236,7 @@ struct _datatemplate
};
extern double convert_to_m(double val, int units);
-extern int create_detgeom(struct image *image,
- const DataTemplate *dtempl);
+extern struct detgeom *create_detgeom(struct image *image,
+ const DataTemplate *dtempl);
#endif /* DATATEMPLATE_PRIV_H */
diff --git a/libcrystfel/src/image.c b/libcrystfel/src/image.c
index 3ce8914e..45b61bec 100644
--- a/libcrystfel/src/image.c
+++ b/libcrystfel/src/image.c
@@ -1074,7 +1074,8 @@ struct image *image_create_for_simulation(const DataTemplate *dtempl)
return NULL;
}
- if ( create_detgeom(image, dtempl) ) {
+ image->detgeom = create_detgeom(image, dtempl);
+ if ( image->detgeom == NULL ) {
image_free(image);
return NULL;
}
@@ -1125,9 +1126,9 @@ static int do_image_read(struct image *image, const DataTemplate *dtempl,
}
profile_start("create-detgeom");
- r = create_detgeom(image, dtempl);
+ image->detgeom = create_detgeom(image, dtempl);
profile_end("create-detgeom");
- if ( r ) {
+ if ( image->detgeom == NULL ) {
ERROR("Failed to read geometry information\n");
return 1;
}
diff --git a/libcrystfel/src/stream.c b/libcrystfel/src/stream.c
index 960d0a02..3a4f5dae 100644
--- a/libcrystfel/src/stream.c
+++ b/libcrystfel/src/stream.c
@@ -897,7 +897,8 @@ struct image *stream_read_chunk(Stream *st, StreamFlags srf)
if ( have_filename && have_ev ) {
/* Success */
if ( srf & STREAM_DATA_DETGEOM ) {
- if ( create_detgeom(image, st->dtempl_read) ) {
+ image->detgeom = create_detgeom(image, st->dtempl_read);
+ if ( image->detgeom == NULL ) {
image_free(image);
return NULL;
}