Skip to content

Instantly share code, notes, and snippets.

@gicmo
Created February 24, 2016 14:30
Show Gist options
  • Save gicmo/53a25c623cef4ad329b0 to your computer and use it in GitHub Desktop.
Save gicmo/53a25c623cef4ad329b0 to your computer and use it in GitHub Desktop.
#include "nix.hpp"
#include <chrono>
#include <thread>
#include <nix/base/Entity.hpp>
/*
struct cleaner {
cleaner(const std::vector<std::reference_wrapper<nix::base::ImplContainer<nix::base::IEntity>>> &x) : e(x){ };
template<typename T>
cleaner(std::initializer_list<T> args) {
size_t n = args.size();
e.resize(n);
std::transform(args.begin(), args.end(), e.begin(),
[](const T& val) {
return std::ref(val);
});
}
~cleaner() {
for (auto &x : e) {
x.get() = nix::none;
}
}
std::vector<std::reference_wrapper<nix::base::ImplContainer<nix::base::IEntity>>> e;
};
*/
void create_files(int count) {
nix::File f;
nix::Block b;
nix::DataArray da;
std::vector<double> data;
for(int i = 0; i < 1000; i ++) {
data.push_back(i * 3.14);
}
for (int i = 0; i < count; i++) {
std::cout << i << std::endl;
f = nix::File::open("test_file_" + nix::util::numToStr(i) + ".h5", nix::FileMode::Overwrite);
b = f.createBlock("block", "test");
da = b.createDataArray("array", "test", data);
da.unit("mV"); // comment to have it running
b = nix::none;
da = nix::none;
f.close();
}
}
void reopen_files(int count) {
nix::File f;
nix::Block b;
nix::DataArray da;
std::vector<double> data;
for (int i = 0; i < count; i++) {
f = nix::File::open("test_file_" + nix::util::numToStr(i) + ".h5", nix::FileMode::ReadOnly);
b = f.getBlock("block");
da = b.getDataArray("array");
std::cerr << da.id() << std::endl;
da = nix::none; // comment to have it crashing
b = nix::none; // do
f.close();
}
}
int main(int argc, char* argv[]) {
create_files(10);
reopen_files(10);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment