Skip to content

Commit

Permalink
start to fill in DatasetInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Smith committed Dec 26, 2022
1 parent 77a968c commit afe5f1c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
46 changes: 40 additions & 6 deletions modules/c++/hdf5.lite/source/Info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@
static herr_t group_info(hid_t loc_id, const char *name, const H5L_info_t* /*linfo*/, void *opdata)
{
// only interested in groups
const auto group = H5Gopen2(loc_id, name, H5P_DEFAULT);
if (group > 0)
const auto obj = H5Gopen2(loc_id, name, H5P_DEFAULT);
if (obj > 0)
{
H5Gclose(group);
H5Gclose(obj);

hdf5::lite::GroupInfo groupInfo;
groupInfo.name = name;
hdf5::lite::GroupInfo info;
info.name = name;

auto pRetval = static_cast<std::vector<hdf5::lite::GroupInfo>*>(opdata);
pRetval->push_back(groupInfo);
pRetval->push_back(info);
}

return 0;
Expand All @@ -60,6 +60,39 @@ static std::vector<hdf5::lite::GroupInfo> getGroups(H5::Group& group)
return retval;
}

// https://docs.hdfgroup.org/archive/support/HDF5/doc1.8/cpplus_RM/h5group_8cpp-example.html
static herr_t dataset_info(hid_t loc_id, const char *name, const H5L_info_t* /*linfo*/, void *opdata)
{
// only interested in Datasets
const auto obj = H5Dopen2(loc_id, name, H5P_DEFAULT);
if (obj > 0)
{
H5Dclose(obj);

hdf5::lite::DatasetInfo info;
info.name = name;

auto pRetval = static_cast<std::vector<hdf5::lite::DatasetInfo>*>(opdata);
pRetval->push_back(info);
}

return 0;
}
static std::vector<hdf5::lite::DatasetInfo> getDatasets(H5::Group& group)
{
std::vector<hdf5::lite::DatasetInfo> retval;

const auto herr = H5Literate(group.getId(), H5_INDEX_NAME, H5_ITER_INC, nullptr /*idx*/, dataset_info, &retval);
if (herr != 0)
{
// How can this happen?
throw std::logic_error("H5Literate failed.");
}

return retval;

}

// https://docs.hdfgroup.org/archive/support/HDF5/doc1.8/cpplus_RM/readdata_8cpp-example.html
static hdf5::lite::FileInfo fileInfo_(coda_oss::filesystem::path filename, std::string loc)
{
Expand All @@ -74,6 +107,7 @@ static hdf5::lite::FileInfo fileInfo_(coda_oss::filesystem::path filename, std::
auto group = file.openGroup(retval.name);

retval.groups = getGroups(group);
retval.datasets = getDatasets(group);

return retval;
}
Expand Down
2 changes: 2 additions & 0 deletions modules/c++/hdf5.lite/unittests/test_hdf5info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ TEST_CASE(test_hdf5Info)
TEST_ASSERT_EQ(path.string(), info.filename);
TEST_ASSERT_EQ("/", info.name);
TEST_ASSERT_EQ(info.groups.size(), 4);
TEST_ASSERT_TRUE(info.datasets.empty());
}

TEST_CASE(test_hdf5Info_IOException)
Expand Down Expand Up @@ -71,6 +72,7 @@ TEST_CASE(test_hdf5Info_loc)
TEST_ASSERT_EQ(path.string(), info.filename);
TEST_ASSERT_EQ("/g4", info.name);
TEST_ASSERT_TRUE(info.groups.empty());
TEST_ASSERT_EQ(info.datasets.size(), 4);
}

TEST_MAIN(
Expand Down

0 comments on commit afe5f1c

Please sign in to comment.