From a84a601d01dfe4b49dc7aab9e73409ebf432286a Mon Sep 17 00:00:00 2001 From: Alan Grossfield Date: Fri, 29 Mar 2024 13:51:06 -0400 Subject: [PATCH] check for malformed MDTrajTraj --- src/mdtrajtraj.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/mdtrajtraj.cpp b/src/mdtrajtraj.cpp index ea231b31a..923b9e456 100644 --- a/src/mdtrajtraj.cpp +++ b/src/mdtrajtraj.cpp @@ -48,11 +48,16 @@ namespace loos { periodic = false; } - coords_dataset = file.openDataSet("coordinates"); - coords_dataspace = coords_dataset.getSpace(); - coords_datatype = coords_dataset.getDataType(); hsize_t coords_dims[3]; - int coords_ndims = coords_dataspace.getSimpleExtentDims(coords_dims, NULL); + int coords_ndims; + if (H5Lexists(file.getId(), "coordinates", H5P_DEFAULT)) { + coords_dataset = file.openDataSet("coordinates"); + coords_dataspace = coords_dataset.getSpace(); + coords_datatype = coords_dataset.getDataType(); + coords_ndims = coords_dataspace.getSimpleExtentDims(coords_dims, NULL); + } else{ + throw(FileError(_filename, "No coordinates dataset found in HDF5")); + } if (periodic) { if (coords_dims[0] != box_dims[0]) {