From 482cb6ec8245efddcc130838dce4b5a3c4eb8fe9 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 16 Jun 2020 17:02:55 +0200 Subject: image_hdf5_get_value without 'struct event' --- libcrystfel/src/image-hdf5.c | 115 ++++++++++++++++++++----------------------- 1 file changed, 54 insertions(+), 61 deletions(-) (limited to 'libcrystfel/src') diff --git a/libcrystfel/src/image-hdf5.c b/libcrystfel/src/image-hdf5.c index a203f6ac..088fd8e0 100644 --- a/libcrystfel/src/image-hdf5.c +++ b/libcrystfel/src/image-hdf5.c @@ -575,7 +575,6 @@ double image_hdf5_get_value(const char *name, const char *filename, hsize_t size[64]; herr_t r; herr_t check; - int dim_flag; int ndims; int i; char *subst_name = NULL; @@ -583,6 +582,7 @@ double image_hdf5_get_value(const char *name, const char *filename, double val; int *dim_vals; int n_dim_vals; + int dim_val_pos; if ( access(filename, R_OK) == -1 ) { ERROR("File does not exist or cannot be read: %s\n", filename); @@ -645,81 +645,74 @@ double image_hdf5_get_value(const char *name, const char *filename, return NAN; } - /* Check that the size in all dimensions is 1 - * or that one of the dimensions has the same - * size as the hyperplane events */ - - dim_flag = 0; - - for ( i=0; i ev->dim_entries[0]) ) { - dim_flag = 1; - } else { - H5Tclose(type); - H5Dclose(dh); - return NAN; - } + f_offset = malloc(ndims*sizeof(hsize_t)); + f_count = malloc(ndims*sizeof(hsize_t)); + if ( (f_offset == NULL) || (f_count == NULL) ) { + ERROR("Couldn't allocate dimension arrays\n"); + H5Tclose(type); + H5Dclose(dh); + return NAN; } - if ( dim_flag == 0 ) { + /* Every dimension of the dataset must either be size 1 or + * large enough to contain the next value from the event ID */ + dim_val_pos = 0; + for ( i=0; idim_entries[0]; - f_count[i] = 1; - } else { - f_offset[i] = 0; - f_count[i] = 0; - } + f_offset[i] = 0; + f_count[i] = 1; } - check = H5Sselect_hyperslab(sh, H5S_SELECT_SET, - f_offset, NULL, f_count, NULL); - if ( check <0 ) { - ERROR("Error selecting dataspace for float value"); - free(f_offset); - free(f_count); - return NAN; - } + } - ms = H5Screate_simple(1,msdims,NULL); - check = H5Sselect_hyperslab(ms, H5S_SELECT_SET, - m_offset, NULL, m_count, NULL); - if ( check < 0 ) { - ERROR("Error selecting memory dataspace for float value"); - free(f_offset); - free(f_count); - return NAN; - } + check = H5Sselect_hyperslab(sh, H5S_SELECT_SET, + f_offset, NULL, f_count, NULL); + if ( check <0 ) { + ERROR("Error selecting dataspace for float value"); + free(f_offset); + free(f_count); + return NAN; + } - r = H5Dread(dh, H5T_NATIVE_DOUBLE, ms, sh, H5P_DEFAULT, &val); - if ( r < 0 ) { - ERROR("Couldn't read value.\n"); - H5Tclose(type); - H5Dclose(dh); - return NAN; - } + ms = H5Screate_simple(1,msdims,NULL); + check = H5Sselect_hyperslab(ms, H5S_SELECT_SET, + m_offset, NULL, m_count, NULL); + if ( check < 0 ) { + ERROR("Error selecting memory dataspace for float value"); + free(f_offset); + free(f_count); + return NAN; + } + r = H5Dread(dh, H5T_NATIVE_DOUBLE, ms, sh, H5P_DEFAULT, &val); + if ( r < 0 ) { + ERROR("Couldn't read value.\n"); + H5Tclose(type); + H5Dclose(dh); + return NAN; } - free_event(ev); + free(f_offset); + free(f_count); + H5Tclose(type); free(subst_name); H5Fclose(fh); -- cgit v1.2.3