aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel/src/image.c
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2020-08-11 15:33:50 +0200
committerThomas White <taw@physics.org>2020-08-11 15:33:50 +0200
commit8daec0a7b0b25fadb22cd3caadc25dad71d491a6 (patch)
tree869ac76a8e740384d1dbb098b81a21958adf093c /libcrystfel/src/image.c
parent7d3593fcbce70a7d7783f0e9d1c9955ecb75dc11 (diff)
image_read_image_data: Set zero values if file not found
Diffstat (limited to 'libcrystfel/src/image.c')
-rw-r--r--libcrystfel/src/image.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/libcrystfel/src/image.c b/libcrystfel/src/image.c
index d48e4f3b..c12a9889 100644
--- a/libcrystfel/src/image.c
+++ b/libcrystfel/src/image.c
@@ -35,6 +35,7 @@
#include <assert.h>
#include <math.h>
#include <stdio.h>
+#include <sys/stat.h>
#include "image.h"
#include "utils.h"
@@ -551,11 +552,30 @@ int image_set_zero_mask(struct image *image,
}
+static int file_exists(const char *filename)
+{
+ struct stat statbuf;
+ int r;
+
+ r = stat(filename, &statbuf);
+ if ( r != 0 ) {
+ return 0;
+ }
+
+ return 1;
+}
+
+
int image_read_image_data(struct image *image,
const DataTemplate *dtempl,
const char *filename,
const char *event)
{
+ if ( !file_exists(filename) ) {
+ ERROR("File not found: %s\n", filename);
+ return image_set_zero_data(image, dtempl);
+ }
+
if ( is_hdf5_file(filename) ) {
return image_hdf5_read(image, dtempl, filename, event);