diff --git a/include/openmc/hdf5_interface.h b/include/openmc/hdf5_interface.h index 468c25980c..f0b3a245c7 100644 --- a/include/openmc/hdf5_interface.h +++ b/include/openmc/hdf5_interface.h @@ -162,13 +162,13 @@ void read_attribute(hid_t obj_id, const char* name, xt::xarray& arr) std::size_t size = 1; for (const auto x : shape) size *= x; - T* buffer = new T[size]; + std::vector buffer(size); // Read data from attribute - read_attr(obj_id, name, H5TypeMap::type_id, buffer); + read_attr(obj_id, name, H5TypeMap::type_id, buffer.data()); // Adapt array into xarray - arr = xt::adapt(buffer, size, xt::acquire_ownership(), shape); + arr = xt::adapt(buffer, shape); } // overload for std::string @@ -244,13 +244,13 @@ void read_dataset(hid_t dset, xt::xarray& arr, bool indep=false) std::size_t size = 1; for (const auto x : shape) size *= x; - T* buffer = new T[size]; + std::vector buffer(size); // Read data from attribute - read_dataset(dset, nullptr, H5TypeMap::type_id, buffer, indep); + read_dataset(dset, nullptr, H5TypeMap::type_id, buffer.data(), indep); // Adapt into xarray - arr = xt::adapt(buffer, size, xt::acquire_ownership(), shape); + arr = xt::adapt(buffer, shape); } template @@ -273,13 +273,13 @@ void read_dataset_as_shape(hid_t obj_id, const char* name, std::size_t size = 1; for (const auto x : arr.shape()) size *= x; - T* buffer = new T[size]; + std::vector buffer(size); // Read data from attribute - read_dataset(dset, nullptr, H5TypeMap::type_id, buffer, indep); + read_dataset(dset, nullptr, H5TypeMap::type_id, buffer.data(), indep); // Adapt into xarray - arr = xt::adapt(buffer, size, xt::acquire_ownership(), arr.shape()); + arr = xt::adapt(buffer, arr.shape()); close_dataset(dset); } diff --git a/include/openmc/search.h b/include/openmc/search.h index 81370a3de0..c91ad18fe1 100644 --- a/include/openmc/search.h +++ b/include/openmc/search.h @@ -14,6 +14,7 @@ template typename std::iterator_traits::difference_type lower_bound_index(It first, It last, const T& value) { + if (*first == value) return 0; It index = std::lower_bound(first, last, value) - 1; return (index == last) ? -1 : index - first; } diff --git a/src/hdf5_interface.F90 b/src/hdf5_interface.F90 index 40f56d88ef..0c7bdb92d5 100644 --- a/src/hdf5_interface.F90 +++ b/src/hdf5_interface.F90 @@ -675,6 +675,7 @@ contains ! If 'name' argument is passed, obj_id is interpreted to be a group and ! 'name' is the name of the dataset we should read from if (present(name)) then + allocate(name_(len_trim(name) + 1)) name_ = to_c_string(name) call read_double_c(obj_id, c_loc(name_), buffer_, indep_) else @@ -698,6 +699,7 @@ contains ! If 'name' argument is passed, obj_id is interpreted to be a group and ! 'name' is the name of the dataset we should read from if (present(name)) then + allocate(name_(len_trim(name) + 1)) name_ = to_c_string(name) call read_double_c(obj_id, c_loc(name_), buffer, indep_) else @@ -720,6 +722,7 @@ contains ! If 'name' argument is passed, obj_id is interpreted to be a group and ! 'name' is the name of the dataset we should read from if (present(name)) then + allocate(name_(len_trim(name) + 1)) name_ = to_c_string(name) call read_double_c(obj_id, c_loc(name_), buffer, indep_) else @@ -742,6 +745,7 @@ contains ! If 'name' argument is passed, obj_id is interpreted to be a group and ! 'name' is the name of the dataset we should read from if (present(name)) then + allocate(name_(len_trim(name) + 1)) name_ = to_c_string(name) call read_double_c(obj_id, c_loc(name_), buffer, indep_) else @@ -764,6 +768,7 @@ contains ! If 'name' argument is passed, obj_id is interpreted to be a group and ! 'name' is the name of the dataset we should read from if (present(name)) then + allocate(name_(len_trim(name) + 1)) name_ = to_c_string(name) call read_double_c(obj_id, c_loc(name_), buffer, indep_) else @@ -888,6 +893,7 @@ contains ! If 'name' argument is passed, obj_id is interpreted to be a group and ! 'name' is the name of the dataset we should read from if (present(name)) then + allocate(name_(len_trim(name) + 1)) name_ = to_c_string(name) call read_int_c(obj_id, c_loc(name_), buffer_, indep_) else @@ -911,6 +917,7 @@ contains ! If 'name' argument is passed, obj_id is interpreted to be a group and ! 'name' is the name of the dataset we should read from if (present(name)) then + allocate(name_(len_trim(name) + 1)) name_ = to_c_string(name) call read_int_c(obj_id, c_loc(name_), buffer, indep_) else @@ -933,6 +940,7 @@ contains ! If 'name' argument is passed, obj_id is interpreted to be a group and ! 'name' is the name of the dataset we should read from if (present(name)) then + allocate(name_(len_trim(name) + 1)) name_ = to_c_string(name) call read_int_c(obj_id, c_loc(name_), buffer, indep_) else @@ -955,6 +963,7 @@ contains ! If 'name' argument is passed, obj_id is interpreted to be a group and ! 'name' is the name of the dataset we should read from if (present(name)) then + allocate(name_(len_trim(name) + 1)) name_ = to_c_string(name) call read_int_c(obj_id, c_loc(name_), buffer, indep_) else @@ -977,6 +986,7 @@ contains ! If 'name' argument is passed, obj_id is interpreted to be a group and ! 'name' is the name of the dataset we should read from if (present(name)) then + allocate(name_(len_trim(name) + 1)) name_ = to_c_string(name) call read_int_c(obj_id, c_loc(name_), buffer, indep_) else @@ -1025,6 +1035,7 @@ contains ! If 'name' argument is passed, obj_id is interpreted to be a group and ! 'name' is the name of the dataset we should read from if (present(name)) then + allocate(name_(len_trim(name) + 1)) name_ = to_c_string(name) call read_llong_c(obj_id, c_loc(name_), buffer_, indep_) else @@ -1425,6 +1436,7 @@ contains ! If 'name' argument is passed, obj_id is interpreted to be a group and ! 'name' is the name of the dataset we should read from if (present(name)) then + allocate(name_(len_trim(name) + 1)) name_ = to_c_string(name) call read_complex_c(obj_id, c_loc(name_), buffer, indep_) else