From 8daec0a7b0b25fadb22cd3caadc25dad71d491a6 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 11 Aug 2020 15:33:50 +0200 Subject: image_read_image_data: Set zero values if file not found --- libcrystfel/src/image.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'libcrystfel') 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 #include #include +#include #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); -- cgit v1.2.3