Unverified Commit e978ae5a authored by Jan Kotanski's avatar Jan Kotanski
Browse files

add fix for writing from std vector

parent 7a70e2da
From: Jan Kotanski <jankotan@gmail.com>
Date: Mon, 2 Sep 2019 16:19:03 +0200
Subject: add fix for writing from std::vector
---
src/h5cpp/node/dataset.hpp | 38 ++++++++++++++++++++++++++++++++++++--
1 file changed, 36 insertions(+), 2 deletions(-)
diff --git a/src/h5cpp/node/dataset.hpp b/src/h5cpp/node/dataset.hpp
index 1021440..2be11db 100644
--- a/src/h5cpp/node/dataset.hpp
+++ b/src/h5cpp/node/dataset.hpp
@@ -635,6 +635,16 @@ void Dataset::write(const T &data,const property::DatasetTransferList &dtpl) con
auto file_space = dataspace();
file_space.selection.all();
+ if (file_space.size() == memory_space.size() &&
+ memory_space.type() == dataspace::Type::SIMPLE &&
+ file_space.type() == dataspace::Type::SIMPLE){
+ const dataspace::Simple & mem_space = dataspace::Simple(memory_space);
+ const dataspace::Simple & fl_space = dataspace::Simple(file_space);
+ if(fl_space.rank() > 1 && mem_space.rank() == 1){
+ write(data,memory_type,file_space,file_space,dtpl);
+ return;
+ }
+ }
write(data,memory_type,memory_space,file_space,dtpl);
}
@@ -728,9 +738,33 @@ void Dataset::write(const T &data,const dataspace::Selection &selection,
dataspace::Dataspace file_space = dataspace();
file_space.selection(dataspace::SelectionOperation::SET,selection);
- write(data,memory_type,memory_space,file_space,dtpl);
-}
+ if (memory_space.type() != dataspace::Type::SIMPLE) {
+ write(data,memory_type,memory_space,file_space,dtpl);
+ }
+ else{
+ try{
+
+ const dataspace::Hyperslab & hyper = dynamic_cast<const dataspace::Hyperslab &>(selection);
+ const dataspace::Simple & mem_space = dataspace::Simple(memory_space);
+
+ auto dims = hyper.block();
+ auto count = hyper.count();
+ for(Dimensions::size_type i = 0; i != dims.size(); i++)
+ dims[i] *= count[i];
+ dataspace::Simple selected_space(dims);
+ if(selected_space.rank() > 1 &&
+ mem_space.rank() == 1 &&
+ selected_space.size() == memory_space.size())
+ write(data,memory_type,selected_space,file_space,dtpl);
+ else
+ write(data,memory_type,memory_space,file_space,dtpl);
+ }
+ catch(const std::bad_cast&){
+ write(data,memory_type,memory_space,file_space,dtpl);
+ }
+ }
+}
template<typename T>
0001-fix-version.patch 0001-fix-version.patch
0002-add-fix-for-writing-from-std-vector.patch
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment