DataSet DataSet::create(const H5::CommonFG &parent, const std::string &name, const H5::DataType &fileType, const NDSize &size, const NDSize &maxsize, const NDSize &chunks, bool max_size_unlimited, bool guess_chunks) { H5::DataSpace space; if (size) { if (maxsize) { space = DataSpace::create(size, maxsize); } else { space = DataSpace::create(size, max_size_unlimited); } } H5::DSetCreatPropList plcreate = H5::DSetCreatPropList::DEFAULT; if (chunks) { int rank = static_cast<int>(chunks.size()); plcreate.setChunk(rank, chunks.data()); } else if (guess_chunks) { NDSize guessedChunks = DataSet::guessChunking(size, fileType.getSize()); plcreate.setChunk(static_cast<int>(guessedChunks.size()), guessedChunks.data()); } H5::DataSet dset = parent.createDataSet(name, fileType, space); return DataSet(dset); }
void DiscretizationBlock::read( const H5::CommonFG &loc, const string &entry, const shared_ptr<Discretization> &discretization) { this->discretization = discretization; auto group = loc.openGroup(entry); assert(H5::readAttribute<string>( group, "type", discretization->manifold.lock()->project.lock()->enumtype) == "DiscretizationBlock"); H5::readAttribute(group, "name", name); assert(H5::readGroupAttribute<string>(group, "discretization", "name") == discretization->name); if (group.attrExists("offset")) { vector<hssize_t> offset, shape; H5::readAttribute(group, "offset", offset); std::reverse(offset.begin(), offset.end()); H5::readAttribute(group, "shape", shape); std::reverse(shape.begin(), shape.end()); region = box_t(offset, point_t(offset) + shape); } if (group.attrExists("active")) { // TODO read_active<0>(group, *this, active); read_active<1>(group, *this, active); read_active<2>(group, *this, active); read_active<3>(group, *this, active); read_active<4>(group, *this, active); } }
void DiscretizationBlock::write(const H5::CommonFG &loc, const H5::H5Location &parent) const { assert(invariant()); auto group = loc.createGroup(name); H5::createAttribute( group, "type", discretization.lock()->manifold.lock()->project.lock()->enumtype, "DiscretizationBlock"); H5::createAttribute(group, "name", name); H5::createHardLink(group, "discretization", parent, "."); if (region.valid()) { #warning "TODO: write using boxtype HDF5 type" vector<hssize_t> offset = region.lower(), shape = region.shape(); std::reverse(offset.begin(), offset.end()); H5::createAttribute(group, "offset", offset); std::reverse(shape.begin(), shape.end()); H5::createAttribute(group, "shape", shape); } if (active.valid()) { // TODO write_active<0>(group, *this, active); write_active<1>(group, *this, active); write_active<2>(group, *this, active); write_active<3>(group, *this, active); write_active<4>(group, *this, active); } }
void Field::read(const H5::CommonFG &loc, const string &entry, const shared_ptr<Project> &project) { m_project = project; auto group = loc.openGroup(entry); assert(H5::readAttribute<string>(group, "type", project->enumtype) == "Field"); H5::readAttribute(group, "name", m_name); assert(H5::readGroupAttribute<string>(group, "project", "name") == project->name()); // TODO: Read and interpret objects (shallowly) instead of naively only // looking at their names m_manifold = project->manifolds().at( H5::readGroupAttribute<string>(group, "manifold", "name")); m_configuration = project->configurations().at( H5::readGroupAttribute<string>(group, "configuration", "name")); assert(H5::readGroupAttribute<string>(group, "configuration/fields/" + name(), "name") == name()); assert(H5::readGroupAttribute<string>(group, "manifold/fields/" + name(), "name") == name()); m_tangentspace = project->tangentspaces().at( H5::readGroupAttribute<string>(group, "tangentspace", "name")); assert(H5::readGroupAttribute<string>(group, "tangentspace/fields/" + name(), "name") == name()); m_tensortype = project->tensortypes().at( H5::readGroupAttribute<string>(group, "tensortype", "name")); H5::readGroup(group, "discretefields", [&](const H5::Group &group, const string &name) { readDiscreteField(group, name); }); m_configuration->insert(name(), shared_from_this()); m_manifold->insert(name(), shared_from_this()); m_tangentspace->insert(name(), shared_from_this()); m_tensortype->noinsert(shared_from_this()); }
void Field::write(const H5::CommonFG &loc, const H5::H5Location &parent) const { assert(invariant()); auto group = loc.createGroup(name()); H5::createAttribute(group, "type", project()->enumtype, "Field"); H5::createAttribute(group, "name", name()); // H5::createHardLink(group, "project", parent, "."); H5::createHardLink(group, "..", parent, "."); H5::createSoftLink(group, "project", ".."); // H5::createHardLink(group, "configuration", parent, // "configurations/" + configuration->name()); H5::createSoftLink(group, "configuration", "../configurations/" + configuration()->name()); H5::createHardLink(group, "project/configurations/" + configuration()->name() + "/fields", name(), group, "."); // H5::createHardLink(group, "manifold", parent, // "manifolds/" + manifold->name()); H5::createSoftLink(group, "manifold", "../manifolds/" + manifold()->name()); H5::createHardLink(group, "project/manifolds/" + manifold()->name() + "/fields", name(), group, "."); // H5::createHardLink(group, "tangentspace", parent, // "tangentspaces/" + tangentspace->name()); H5::createSoftLink(group, "tangentspace", "../tangentspaces/" + tangentspace()->name()); H5::createHardLink(group, "project/tangentspaces/" + tangentspace()->name() + "/fields", name(), group, "."); // H5::createHardLink(group, "tensortype", parent, // "tensortypes/" + tensortype->name()); H5::createSoftLink(group, "tensortype", "../tensortypes/" + tensortype()->name()); H5::createGroup(group, "discretefields", discretefields()); }
void ParameterValue::write(const H5::CommonFG &loc, const H5::H5Location &parent) const { assert(invariant()); auto group = loc.createGroup(name); H5::createAttribute(group, "type", parameter.lock()->project.lock()->enumtype, "ParameterValue"); H5::createAttribute(group, "name", name); H5::createHardLink(group, "parameter", parent, string("project/parameters/") + parameter.lock()->name); switch (value_type) { case type_empty: // do nothing break; case type_int: H5::createAttribute(group, "data", value_int); break; case type_double: H5::createAttribute(group, "data", value_double); break; case type_string: H5::createAttribute(group, "data", value_string); break; default: assert(0); } group.createGroup("configurations"); }
void hdfutil::WriteString(const H5::CommonFG& group, const std::string & dsname, const std::string & str) { hsize_t dims[] = {1}; H5::DataSpace dataspace(1, dims); // 1 string H5::StrType strtype (0, str.size()); // string length H5::DataSet dset = group.createDataSet(dsname, strtype, dataspace, CreatePropList()); dset.write(&str[0], strtype); }
void SubDiscretization::read(const H5::CommonFG &loc, const string &entry, const shared_ptr<Manifold> &manifold) { m_manifold = manifold; auto group = loc.openGroup(entry); assert( H5::readAttribute<string>(group, "type", manifold->project()->enumtype) == "SubDiscretization"); H5::readAttribute(group, "name", m_name); assert(H5::readGroupAttribute<string>(group, "manifold", "name") == manifold->name()); m_parent_discretization = manifold->discretizations().at( H5::readGroupAttribute<string>(group, "parent_discretization", "name")); assert(H5::readGroupAttribute<string>( group, string("parent_discretization/child_discretizations/") + name(), "name") == name()); m_child_discretization = manifold->discretizations().at( H5::readGroupAttribute<string>(group, "child_discretization", "name")); assert(H5::readGroupAttribute<string>( group, string("child_discretization/parent_discretizations/") + name(), "name") == name()); H5::readAttribute(group, "factor", m_factor); std::reverse(m_factor.begin(), m_factor.end()); H5::readAttribute(group, "offset", m_offset); std::reverse(m_offset.begin(), m_offset.end()); m_parent_discretization->insertChild(name(), shared_from_this()); m_child_discretization->insertParent(name(), shared_from_this()); }
void Manifold::read(const H5::CommonFG &loc, const string &entry, const shared_ptr<Project> &project) { this->m_project = project; auto group = loc.openGroup(entry); assert(H5::readAttribute<string>(group, "type", project->enumtype) == "Manifold"); H5::readAttribute(group, "name", m_name); assert(H5::readGroupAttribute<string>(group, "project", "name") == project->name()); m_configuration = project->configurations().at( H5::readGroupAttribute<string>(group, "configuration", "name")); assert(H5::readGroupAttribute<string>( group, "configuration/manifolds/" + name(), "name") == name()); H5::readAttribute(group, "dimension", m_dimension); H5::readGroup(group, "discretizations", [&](const H5::Group &group, const string &name) { readDiscretization(group, name); }); H5::readGroup(group, "subdiscretizations", [&](const H5::Group &group, const string &name) { readSubDiscretization(group, name); }); // Cannot check "fields", "coordinatesystems" since they have not been read // yet // assert(H5::checkGroupNames(group, "fields", fields)); // assert(H5::checkGroupNames(group, "coordinatesystems", fields)); m_configuration->insert(name(), shared_from_this()); }
void Project::read(const H5::CommonFG &loc) { auto group = loc.openGroup("."); createTypes(); // TODO: read from file instead to ensure integer constants are // consistent assert(H5::readAttribute<string>(group, "type", enumtype) == "Project"); H5::readAttribute(group, "name", m_name); H5::readGroup(group, "parameters", [&](const H5::Group &group, const string &name) { readParameter(group, name); }); H5::readGroup(group, "configurations", [&](const H5::Group &group, const string &name) { readConfiguration(group, name); }); H5::readGroup(group, "tensortypes", [&](const H5::Group &group, const string &name) { readTensorType(group, name); }); H5::readGroup(group, "manifolds", [&](const H5::Group &group, const string &name) { readManifold(group, name); }); H5::readGroup(group, "tangentspaces", [&](const H5::Group &group, const string &name) { readTangentSpace(group, name); }); H5::readGroup(group, "fields", [&](const H5::Group &group, const string &name) { readField(group, name); }); H5::readGroup(group, "coordinatesystems", [&](const H5::Group &group, const string &name) { readCoordinateSystem(group, name); }); }
void Project::write(const H5::CommonFG &loc, const H5::H5Location &parent) const { assert(invariant()); // auto group = loc.createGroup(name()); auto group = loc.openGroup("."); createTypes(); auto typegroup = group.createGroup("types"); enumtype.commit(typegroup, "SimulationIO"); #if 0 rangetype.commit(typegroup, "Range"); #endif for (int d = 0; d < int(pointtypes.size()); ++d) pointtypes.at(d).commit(typegroup, "Point[" + itos(d) + "]"); for (int d = 0; d < int(boxtypes.size()); ++d) boxtypes.at(d).commit(typegroup, "Box[" + itos(d) + "]"); for (int d = 0; d < int(regiontypes.size()); ++d) regiontypes.at(d).commit(typegroup, "Region[" + itos(d) + "]"); H5::createAttribute(group, "type", enumtype, "Project"); H5::createAttribute(group, "name", name()); // no link to parent H5::createGroup(group, "parameters", parameters()); H5::createGroup(group, "configurations", configurations()); H5::createGroup(group, "tensortypes", tensortypes()); H5::createGroup(group, "manifolds", manifolds()); H5::createGroup(group, "tangentspaces", tangentspaces()); H5::createGroup(group, "fields", fields()); H5::createGroup(group, "coordinatesystems", coordinatesystems()); }
std::string load_version_information(const H5::CommonFG& root) { using namespace H5; char buf[32]; const DataSet dataset(DataSet(root.openDataSet("version"))); dataset.read(buf, dataset.getDataType()); return std::string(buf); }
void Parameter::write(const H5::CommonFG &loc, const H5::H5Location &parent) const { assert(invariant()); auto group = loc.createGroup(name); H5::createAttribute(group, "type", project.lock()->enumtype, "Parameter"); H5::createAttribute(group, "name", name); H5::createHardLink(group, "project", parent, "."); H5::createGroup(group, "parametervalues", parametervalues); }
std::shared_ptr<H5::DataSet> NDArray<T, Nd>::WriteToH5( const H5::CommonFG& group, const std::string& dsetName) const { H5::DataType h5DType = GetH5DataType<T>(); hsize_t dims[Nd]; for (int i=0; i<Nd; ++i) dims[i] = mN[i]; H5::DataSpace h5DSpace(Nd, dims); std::shared_ptr<H5::DataSet> dset = std::make_shared<H5::DataSet>( group.createDataSet(dsetName.c_str(), h5DType, h5DSpace)); dset->write(mData, h5DType); return dset; }
void TensorComponent::write(const H5::CommonFG &loc, const H5::H5Location &parent) const { assert(invariant()); auto group = loc.createGroup(name()); H5::createAttribute(group, "type", tensortype()->project()->enumtype, "TensorComponent"); H5::createAttribute(group, "name", name()); // H5::createHardLink(group, "tensortype", parent, "."); H5::createHardLink(group, "..", parent, "."); H5::createSoftLink(group, "tensortype", ".."); H5::createAttribute(group, "storage_index", storage_index()); H5::createAttribute(group, "indexvalues", indexvalues()); }
void TensorComponent::read(const H5::CommonFG &loc, const string &entry, const shared_ptr<TensorType> &tensortype) { m_tensortype = tensortype; auto group = loc.openGroup(entry); assert(H5::readAttribute<string>(group, "type", tensortype->project()->enumtype) == "TensorComponent"); H5::readAttribute(group, "name", m_name); assert(H5::readGroupAttribute<string>(group, "tensortype", "name") == tensortype->name()); H5::readAttribute(group, "storage_index", m_storage_index); H5::readAttribute(group, "indexvalues", m_indexvalues); }
std::string hdfutil::ReadString (const H5::CommonFG& group, const std::string & dsname) { const H5::DataSet & dataset = group.openDataSet(dsname); try { H5::DataType type = dataset.getDataType(); std::string retval; retval.resize(type.getSize()); dataset.read(&retval[0], dataset.getStrType()); return retval; } catch (H5::Exception e) { std::string error = "Unable to ReadString.";// + dsname; throw std::runtime_error(error.c_str()); } }
void TensorType::write(const H5::CommonFG &loc, const H5::H5Location &parent) const { assert(invariant()); auto group = loc.createGroup(name()); H5::createAttribute(group, "type", project()->enumtype, "TensorType"); H5::createAttribute(group, "name", name()); // H5::createHardLink(group, "project", parent, "."); H5::createHardLink(group, "..", parent, "."); H5::createSoftLink(group, "project", ".."); H5::createAttribute(group, "dimension", dimension()); H5::createAttribute(group, "rank", rank()); H5::createGroup(group, "tensorcomponents", tensorcomponents()); // TODO: write storage_indices }
void Parameter::read(const H5::CommonFG &loc, const string &entry, const shared_ptr<Project> &project) { this->project = project; auto group = loc.openGroup(entry); assert(H5::readAttribute<string>(group, "type", project->enumtype) == "Parameter"); H5::readAttribute(group, "name", name); assert(H5::readGroupAttribute<string>(group, "project", "name") == project->name); H5::readGroup(group, "parametervalues", [&](const H5::Group &group, const string &name) { readParameterValue(group, name); }); }
void TangentSpace::write(const H5::CommonFG &loc, const H5::H5Location &parent) const { assert(invariant()); auto group = loc.createGroup(name); H5::createAttribute(group, "type", project.lock()->enumtype, "TangentSpace"); H5::createAttribute(group, "name", name); H5::createHardLink(group, "project", parent, "."); H5::createHardLink(group, "configuration", parent, string("configurations/") + configuration->name); H5::createHardLink(group, string("project/configurations/") + configuration->name + "/tangentspaces", name, group, "."); H5::createAttribute(group, "dimension", dimension); H5::createGroup(group, "bases", bases); group.createGroup("fields"); }
void TensorType::read(const H5::CommonFG &loc, const string &entry, const shared_ptr<Project> &project) { m_project = project; auto group = loc.openGroup(entry); assert(H5::readAttribute<string>(group, "type", project->enumtype) == "TensorType"); H5::readAttribute(group, "name", m_name); assert(H5::readGroupAttribute<string>(group, "project", "name") == project->name()); H5::readAttribute(group, "dimension", m_dimension); H5::readAttribute(group, "rank", m_rank); H5::readGroup(group, "tensorcomponents", [&](const H5::Group &group, const string &name) { readTensorComponent(group, name); }); // TODO: check storage_indices }
void Basis::read(const H5::CommonFG &loc, const string &entry, const shared_ptr<TangentSpace> &tangentspace) { m_tangentspace = tangentspace; auto group = loc.openGroup(entry); assert(H5::readAttribute<string>( group, "type", tangentspace->project()->enumtype) == "Basis"); H5::readAttribute(group, "name", m_name); assert(H5::readGroupAttribute<string>(group, "tangentspace", "name") == tangentspace->name()); m_configuration = tangentspace->project()->configurations().at( H5::readGroupAttribute<string>(group, "configuration", "name")); assert(H5::readGroupAttribute<string>( group, string("configuration/bases/") + name(), "name") == name()); H5::readGroup(group, "basisvectors", [&](const H5::Group &group, const string &name) { readBasisVector(group, name); }); // TODO: check group directions m_configuration->insert(name(), shared_from_this()); }
void Basis::write(const H5::CommonFG &loc, const H5::H5Location &parent) const { assert(invariant()); auto group = loc.createGroup(name()); H5::createAttribute(group, "type", tangentspace()->project()->enumtype, "Basis"); H5::createAttribute(group, "name", name()); // H5::createHardLink(group, "tangentspace", parent, "."); H5::createHardLink(group, "..", parent, "."); H5::createSoftLink(group, "tangentspace", ".."); // H5::createHardLink(group, "configuration", parent, // string("project/configurations/") + // configuration->name); H5::createSoftLink(group, "configuration", string("../project/configurations/") + configuration()->name()); H5::createHardLink(group, string("tangentspace/project/configurations/") + configuration()->name() + "/bases", name(), group, "."); H5::createGroup(group, "basisvectors", basisvectors()); // TODO: output directions }
void Manifold::write(const H5::CommonFG &loc, const H5::H5Location &parent) const { assert(invariant()); auto group = loc.createGroup(name()); H5::createAttribute(group, "type", project()->enumtype, "Manifold"); H5::createAttribute(group, "name", name()); // H5::createHardLink(group, "project", parent, "."); H5::createHardLink(group, "..", parent, "."); H5::createSoftLink(group, "project", ".."); // H5::createHardLink(group, "configuration", parent, // "configurations/" + configuration->name()); H5::createSoftLink(group, "configuration", "../configurations/" + configuration()->name()); H5::createHardLink(group, "project/configurations/" + configuration()->name() + "/manifolds", name(), group, "."); H5::createAttribute(group, "dimension", dimension()); H5::createGroup(group, "discretizations", discretizations()); H5::createGroup(group, "subdiscretizations", subdiscretizations()); group.createGroup("fields"); group.createGroup("coordinatesystems"); }
void TangentSpace::read(const H5::CommonFG &loc, const string &entry, const shared_ptr<Project> &project) { this->project = project; auto group = loc.openGroup(entry); assert(H5::readAttribute<string>(group, "type", project->enumtype) == "TangentSpace"); H5::readAttribute(group, "name", name); assert(H5::readGroupAttribute<string>(group, "project", "name") == project->name); configuration = project->configurations.at( H5::readGroupAttribute<string>(group, "configuration", "name")); assert(H5::readGroupAttribute<string>( group, string("configuration/tangentspaces/") + name, "name") == name); H5::readAttribute(group, "dimension", dimension); H5::readGroup(group, "bases", [&](const H5::Group &group, const string &name) { readBasis(group, name); }); // Cannot check "fields" since fields have not been read yet // assert(H5::checkGroupNames(group, "fields", fields)); configuration->insert(name, shared_from_this()); }
void SubDiscretization::write(const H5::CommonFG &loc, const H5::H5Location &parent) const { assert(invariant()); auto group = loc.createGroup(name()); H5::createAttribute(group, "type", manifold()->project()->enumtype, "SubDiscretization"); H5::createAttribute(group, "name", name()); // H5::createHardLink(group, "manifold", parent, "."); H5::createHardLink(group, "..", parent, "."); H5::createSoftLink(group, "manifold", ".."); // H5::createHardLink(group, "parent_discretization", parent, // string("discretizations/") + // parent_discretization->name()); H5::createSoftLink(group, "parent_discretization", string("../discretizations/") + parent_discretization()->name()); H5::createHardLink(group, string("manifold/discretizations/") + parent_discretization()->name() + "/child_discretizations", name(), group, "."); // H5::createHardLink(group, "child_discretization", parent, // string("discretizations/") + // child_discretization->name()); H5::createSoftLink(group, "child_discretization", string("../discretizations/") + child_discretization()->name()); H5::createHardLink(group, string("manifold/discretizations/") + child_discretization()->name() + "/parent_discretizations", name(), group, "."); auto tmp_factor = factor(); std::reverse(tmp_factor.begin(), tmp_factor.end()); H5::createAttribute(group, "factor", tmp_factor); auto tmp_offset = offset(); std::reverse(tmp_offset.begin(), tmp_offset.end()); H5::createAttribute(group, "offset", tmp_offset); }
void ParameterValue::read(const H5::CommonFG &loc, const string &entry, const shared_ptr<Parameter> ¶meter) { this->parameter = parameter; value_type = type_empty; auto group = loc.openGroup(entry); assert(H5::readAttribute<string>(group, "type", parameter->project.lock()->enumtype) == "ParameterValue"); H5::readAttribute(group, "name", name); assert(H5::readGroupAttribute<string>(group, "parameter", "name") == parameter->name); // TODO: Read and interpret objects (shallowly) instead of naively only // looking at their names if (group.attrExists("data")) { auto attr = group.openAttribute("data"); auto type = attr.getDataType(); auto cls = type.getClass(); switch (cls) { case H5T_INTEGER: H5::readAttribute(group, "data", value_int); value_type = type_int; break; case H5T_FLOAT: H5::readAttribute(group, "data", value_double); value_type = type_double; break; case H5T_STRING: H5::readAttribute(group, "data", value_string); value_type = type_string; break; default: assert(0); } } // Cannot check "configurations" since configurations have not been read yet // assert(H5::checkGroupNames(group, "configurations", configurations)); }