diff options
author | Thomas White <taw@physics.org> | 2022-03-09 10:32:48 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2022-03-09 10:51:38 +0100 |
commit | fa397e933d2ba0ecdfb94e6a9d876886598be9f5 (patch) | |
tree | 29ea8fed5cb0522f2e706fe20d6c7117225e5da9 /libcrystfel | |
parent | 54752e2ce0a0d5c9ea0e8b6832affb4bc5ef6554 (diff) |
Meson: enable building without HDF5
Diffstat (limited to 'libcrystfel')
-rw-r--r-- | libcrystfel/libcrystfel-config.h.cmake.in | 1 | ||||
-rw-r--r-- | libcrystfel/libcrystfel-config.h.meson.in | 1 | ||||
-rw-r--r-- | libcrystfel/src/image-hdf5.c | 66 | ||||
-rw-r--r-- | libcrystfel/src/image.c | 35 |
4 files changed, 74 insertions, 29 deletions
diff --git a/libcrystfel/libcrystfel-config.h.cmake.in b/libcrystfel/libcrystfel-config.h.cmake.in index 31f28ee1..830055cb 100644 --- a/libcrystfel/libcrystfel-config.h.cmake.in +++ b/libcrystfel/libcrystfel-config.h.cmake.in @@ -11,6 +11,7 @@ #cmakedefine HAVE_LIBCCP4 #cmakedefine HAVE_MSGPACK #cmakedefine HAVE_CLOCK_GETTIME +#cmakedefine HAVE_HDF5 #cmakedefine HAVE_FORKPTY_PTY_H #cmakedefine HAVE_FORKPTY_UTIL_H diff --git a/libcrystfel/libcrystfel-config.h.meson.in b/libcrystfel/libcrystfel-config.h.meson.in index 6796857e..7d43147d 100644 --- a/libcrystfel/libcrystfel-config.h.meson.in +++ b/libcrystfel/libcrystfel-config.h.meson.in @@ -9,6 +9,7 @@ #mesondefine HAVE_LIBCCP4 #mesondefine HAVE_MSGPACK #mesondefine HAVE_CLOCK_GETTIME +#mesondefine HAVE_HDF5 #mesondefine HAVE_FORKPTY_PTY_H #mesondefine HAVE_FORKPTY_UTIL_H diff --git a/libcrystfel/src/image-hdf5.c b/libcrystfel/src/image-hdf5.c index 702c1392..7023e811 100644 --- a/libcrystfel/src/image-hdf5.c +++ b/libcrystfel/src/image-hdf5.c @@ -33,9 +33,11 @@ #include <assert.h> #include <math.h> #include <stdio.h> +#include <unistd.h> +#ifdef HAVE_HDF5 #include <hdf5.h> #include <hdf5_hl.h> -#include <unistd.h> +#endif #include "image.h" #include "utils.h" @@ -45,34 +47,6 @@ #include "datatemplate_priv.h" -static void close_hdf5(hid_t fh) -{ - int n_ids, i; - hid_t ids[2048]; - - n_ids = H5Fget_obj_ids(fh, H5F_OBJ_ALL, 2048, ids); - - for ( i=0; i<n_ids; i++ ) { - - hid_t id; - H5I_type_t type; - - id = ids[i]; - - type = H5Iget_type(id); - - if ( type == H5I_GROUP ) H5Gclose(id); - if ( type == H5I_DATASET ) H5Dclose(id); - if ( type == H5I_DATATYPE ) H5Tclose(id); - if ( type == H5I_DATASPACE ) H5Sclose(id); - if ( type == H5I_ATTR ) H5Aclose(id); - - } - - H5Fclose(fh); -} - - /* Get the path parts of the event ID * e.g. ev_orig = abc/def/ghi//5/2/7 * -> [abc, def, ghi], with *pn_plvals=3. @@ -320,6 +294,8 @@ char *substitute_path(const char *ev, const char *pattern, int skip_ok) } +#ifdef HAVE_HDF5 + static void make_placeholder_skip(signed int *dt_dims, signed int *panel_dims) { @@ -355,6 +331,36 @@ static int total_dimensions(const struct panel_template *p) } +static void close_hdf5(hid_t fh) +{ + int n_ids, i; + hid_t ids[2048]; + + n_ids = H5Fget_obj_ids(fh, H5F_OBJ_ALL, 2048, ids); + + for ( i=0; i<n_ids; i++ ) { + + hid_t id; + H5I_type_t type; + + id = ids[i]; + + type = H5Iget_type(id); + + if ( type == H5I_GROUP ) H5Gclose(id); + if ( type == H5I_DATASET ) H5Dclose(id); + if ( type == H5I_DATATYPE ) H5Tclose(id); + if ( type == H5I_DATASPACE ) H5Sclose(id); + if ( type == H5I_ATTR ) H5Aclose(id); + + } + + H5Fclose(fh); +} + + + + static int load_hdf5_hyperslab(struct panel_template *p, hid_t fh, const char *event, @@ -2316,3 +2322,5 @@ int image_hdf5_write(const struct image *image, free(locations); return 0; } + +#endif /* HAVE_HDF5 */ diff --git a/libcrystfel/src/image.c b/libcrystfel/src/image.c index 3a8fb482..e428b606 100644 --- a/libcrystfel/src/image.c +++ b/libcrystfel/src/image.c @@ -49,6 +49,13 @@ /** \file image.h */ +#ifndef HAVE_HDF5 +int is_hdf5_file(const char *filename) +{ + return 0; +} +#endif + struct _imagefeaturelist { struct imagefeature *features; @@ -378,7 +385,11 @@ static int read_header_to_cache(struct image *image, const char *from) return 1; case DATA_SOURCE_TYPE_HDF5: + #ifdef HAVE_HDF5 return image_hdf5_read_header_to_cache(image, from); + #else + return 1; + #endif case DATA_SOURCE_TYPE_CBF: case DATA_SOURCE_TYPE_CBFGZ: @@ -776,7 +787,11 @@ static int image_read_image_data(struct image *image, return 1; case DATA_SOURCE_TYPE_HDF5: + #ifdef HAVE_HDF5 return image_hdf5_read(image, dtempl); + #else + return 1; + #endif case DATA_SOURCE_TYPE_CBF: return image_cbf_read(image, dtempl, 0); @@ -1008,8 +1023,10 @@ static int load_mask(struct panel_template *p, unsigned int mask_bad) { if ( is_hdf5_file(mask_fn) ) { + #ifdef HAVE_HDF5 image_hdf5_read_mask(p, mask_fn, ev, bad, mask_location, mask_good, mask_bad); + #endif } else if ( is_cbf_file(mask_fn) ) { image_cbf_read_mask(p, mask_fn, ev, 0, bad, @@ -1189,9 +1206,11 @@ static int create_satmap(struct image *image, } if ( is_hdf5_file(map_fn) ) { + #ifdef HAVE_HDF5 image->sat[i] = image_hdf5_read_satmap(p, map_fn, image->ev, p->satmap); + #endif } else { ERROR("Saturation map must be in HDF5 format\n"); @@ -1476,6 +1495,7 @@ ImageFeatureList *image_read_peaks(const DataTemplate *dtempl, { if ( is_hdf5_file(filename) ) { + #ifdef HAVE_HDF5 enum peak_layout layout; if ( dtempl->peak_list_type == PEAK_LIST_AUTO ) { @@ -1516,6 +1536,10 @@ ImageFeatureList *image_read_peaks(const DataTemplate *dtempl, return NULL; } + #else + ERROR("Can't read peak list - compiled without HDF5\n"); + return NULL; + #endif } else { ERROR("Peak lists can only be read from HDF5 files\n"); @@ -1528,8 +1552,14 @@ char **image_expand_frames(const DataTemplate *dtempl, const char *filename, int *n_frames) { if ( is_hdf5_file(filename) ) { + #ifdef HAVE_HDF5 return image_hdf5_expand_frames(dtempl, filename, n_frames); + #else + ERROR("Can't expand frames - compiled without HDF5\n"); + return NULL; + #endif + } else { char **list; list = malloc(sizeof(char *)); @@ -1580,7 +1610,12 @@ int image_write(const struct image *image, const char *filename) { if ( is_hdf5_file(filename) ) { + #ifdef HAVE_HDF5 return image_hdf5_write(image, dtempl, filename); + #else + ERROR("Can't write image - compiled without HDF5\n"); + return 1; + #endif } ERROR("Can only write to HDF5 files.\n"); |