Skip to content

Commit

Permalink
Putative fix for #30
Browse files Browse the repository at this point in the history
Work with what we have
  • Loading branch information
graeme-winter committed Nov 16, 2023
1 parent bec44c8 commit 58b765c
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions src/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ double scale_from_units(const char *unit_string) {

int get_nxs_dataset_dims(struct ds_desc_t *desc) {
hid_t g_id, ds_id, s_id, t_id;
hsize_t dims[3];
int retval = 0;
int ndims = 0;
int width = 0;
g_id = desc->data_g_id;
;

ds_id = H5Dopen2(g_id, "data", H5P_DEFAULT);
if (ds_id <= 0) {
Expand Down Expand Up @@ -100,10 +100,14 @@ int get_nxs_dataset_dims(struct ds_desc_t *desc) {
ERROR_JUMP(-1, close_space, message);
}

if (H5Sget_simple_extent_dims(s_id, desc->dims, NULL) < 0) {
if (H5Sget_simple_extent_dims(s_id, dims, NULL) < 0) {
ERROR_JUMP(-1, close_space, "Error getting dataset dimensions");
}

if (dims[1] && dims[2]) {
for (int j = 0; j < 3; j++) desc->dims[j] = dims[j];
}

desc->data_width = width;

close_space:
Expand Down Expand Up @@ -325,6 +329,9 @@ int get_dectris_eiger_dataset_dims(struct ds_desc_t *desc) {
}

frame_counts = malloc(n_datas * sizeof(*frame_counts));
for (int j = 0; j < n_datas; j++) {
frame_counts[j] = 0;
}

for (n = 0; n < n_datas; n++) {
hid_t ds_id, t_id, s_id;
Expand Down Expand Up @@ -361,8 +368,11 @@ int get_dectris_eiger_dataset_dims(struct ds_desc_t *desc) {
ERROR_JUMP(-1, close_space, "Unable to read dataset dimensions");
}

dims[1] = block_dims[1];
dims[2] = block_dims[2];
// handle missing blocks
if (block_dims[1] && block_dims[2]) {
dims[1] = block_dims[1];
dims[2] = block_dims[2];
}

dims[0] += block_dims[0];
frame_counts[n] = block_dims[0];
Expand All @@ -378,9 +388,18 @@ int get_dectris_eiger_dataset_dims(struct ds_desc_t *desc) {
break;
}

if (retval < 0) {
// if we failed on the first case then this is a hopeless cause, otherwise
// try and work with what we have
if ((retval < 0) && (frame_counts[0] == 0)) {
free(frame_counts);
} else {
// possibly re-write n_datas
for (int j = 0; j < n_datas; j++) {
if (frame_counts[j] == 0) {
n_datas = j;
break;
}
}
memcpy(desc->dims, dims, 3 * sizeof(*dims));
desc->data_width = data_width;
eiger_desc->n_data_blocks = n_datas;
Expand Down

0 comments on commit 58b765c

Please sign in to comment.