Skip to content

Commit

Permalink
latest from coda-oss and nitro
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Smith authored and Dan Smith committed Jan 10, 2023
1 parent 8423b28 commit c68727a
Show file tree
Hide file tree
Showing 18 changed files with 627 additions and 25 deletions.
4 changes: 4 additions & 0 deletions externals/coda-oss/UnitTest/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,12 @@
#include <future>
#include <cassert>
#include <tuple>
#include <complex>
#include <stdexcept>

#include "CppUnitTest.h"

#include "coda_oss/span.h"
#include "gsl/gsl.h"
#include "import/sys.h"
#include "import/math.h"
Expand All @@ -58,6 +61,7 @@
#include "import/mem.h"
#include <mem/SharedPtr.h>
#include <mem/AutoPtr.h>
#include <mem/ComplexView.h>
#include "import/cli.h"
#include "polygon/DrawPolygon.h"
#include "polygon/PolygonMask.h"
Expand Down
1 change: 1 addition & 0 deletions externals/coda-oss/modules/c++/coda-oss-lite.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
<ClInclude Include="mem\include\mem\Align.h" />
<ClInclude Include="mem\include\mem\AutoPtr.h" />
<ClInclude Include="mem\include\mem\BufferView.h" />
<ClInclude Include="mem\include\mem\ComplexView.h" />
<ClInclude Include="mem\include\mem\ScopedAlignedArray.h" />
<ClInclude Include="mem\include\mem\ScopedArray.h" />
<ClInclude Include="mem\include\mem\ScopedCloneablePtr.h" />
Expand Down
3 changes: 3 additions & 0 deletions externals/coda-oss/modules/c++/coda-oss-lite.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,9 @@
<ClInclude Include="mem\include\mem\AutoPtr.h">
<Filter>mem</Filter>
</ClInclude>
<ClInclude Include="mem\include\mem\ComplexView.h">
<Filter>mem</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="pch.cpp" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ namespace lite
{

CODA_OSS_API types::RowCol<size_t> readFile(coda_oss::filesystem::path, std::string datasetName, std::vector<double>&);
CODA_OSS_API types::RowCol<size_t> readFile(coda_oss::filesystem::path, std::string datasetName, std::vector<float>&);

}
}
Expand Down
4 changes: 2 additions & 2 deletions externals/coda-oss/modules/c++/hdf5.lite/source/Info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ static hdf5::lite::GroupInfo groupInfo_(coda_oss::filesystem::path filename, std
}
hdf5::lite::GroupInfo hdf5::lite::groupInfo(coda_oss::filesystem::path filename, std::string loc)
{
return details::try_catch_H5Exceptions(groupInfo_, filename, loc);
return details::try_catch_H5Exceptions(groupInfo_, __FILE__, __LINE__, filename, loc);
}
hdf5::lite::FileInfo hdf5::lite::fileInfo(coda_oss::filesystem::path filename)
{
Expand Down Expand Up @@ -208,5 +208,5 @@ static hdf5::lite::DatasetInfo datasetInfo_(coda_oss::filesystem::path filename,
}
hdf5::lite::DatasetInfo hdf5::lite::datasetInfo(coda_oss::filesystem::path filename, std::string loc)
{
return details::try_catch_H5Exceptions(datasetInfo_, filename, loc);
return details::try_catch_H5Exceptions(datasetInfo_, __FILE__, __LINE__, filename, loc);
}
13 changes: 9 additions & 4 deletions externals/coda-oss/modules/c++/hdf5.lite/source/Read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,14 @@ inline types::RowCol<size_t> readDataset_(const H5::DataSet& dataset, std::vecto
static_assert(sizeof(float) * 8 == 32, "'float' should be 32-bits"); // IEEE_F32LE
return readDatasetT(dataset, H5T_FLOAT, H5::PredType::IEEE_F32LE, result);
}

inline types::RowCol<size_t> readDataset_(const H5::DataSet& dataset, std::vector<double>& result)
{
static_assert(sizeof(double) * 8 == 64, "'double' should be 64-bits"); // IEEE_F64LE
return readDatasetT(dataset, H5T_FLOAT, H5::PredType::IEEE_F64LE, result);
}

template<typename T>
static types::RowCol<size_t> readFile_(const coda_oss::filesystem::path& fileName, const std::string& datasetName,
std::vector<double>& result)
std::vector<T>& result)
{
/*
* Open the specified file and the specified dataset in the file.
Expand All @@ -68,8 +67,14 @@ static types::RowCol<size_t> readFile_(const coda_oss::filesystem::path& fileNam
const auto dataset = file.openDataSet(datasetName);
return readDataset_(dataset, result);
}

types::RowCol<size_t> hdf5::lite::readFile(coda_oss::filesystem::path fileName, std::string datasetName,
std::vector<double>& result)
{
return details::try_catch_H5Exceptions(readFile_, fileName, datasetName, result);
return details::try_catch_H5Exceptions(readFile_<double>, __FILE__, __LINE__, fileName, datasetName, result);
}
types::RowCol<size_t> hdf5::lite::readFile(coda_oss::filesystem::path fileName, std::string datasetName,
std::vector<float>& result)
{
return details::try_catch_H5Exceptions(readFile_<float>, __FILE__, __LINE__, fileName, datasetName, result);
}
23 changes: 14 additions & 9 deletions externals/coda-oss/modules/c++/hdf5.lite/source/hdf5.lite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@

#include "hdf5.lite.h"

void hdf5::lite::details::try_catch_H5Exceptions_(std::function<void(void*)> f, void* context)
inline except::Context make_Context(const H5::Exception& error, const char* file, int line)
{
return except::Context(error.getDetailMsg(), file, line, error.getFuncName());
}

void hdf5::lite::details::try_catch_H5Exceptions_(std::function<void(void*)> f, const char* file, int line, void* context)
{
try
{
Expand All @@ -34,28 +39,28 @@ void hdf5::lite::details::try_catch_H5Exceptions_(std::function<void(void*)> f,

f(context);
}

// catch failure caused by the H5File operations
catch (const H5::FileIException& error)
{
const except::Context ctx(error.getDetailMsg(), __FILE__, __LINE__, error.getFuncName());
throw except::IOException(ctx);
throw except::IOException(make_Context(error, file, line));
}

// catch failure caused by the DataSet operations
catch (const H5::DataSetIException& error)
{
const except::Context ctx(error.getDetailMsg(), __FILE__, __LINE__, error.getFuncName());
throw hdf5::lite::DataSetException(ctx);
throw hdf5::lite::DataSetException(make_Context(error, file, line));
}

// catch failure caused by the DataSpace operations
catch (const H5::DataSpaceIException& error)
{
const except::Context ctx(error.getDetailMsg(), __FILE__, __LINE__, error.getFuncName());
throw hdf5::lite::DataSpaceException(ctx);
throw hdf5::lite::DataSpaceException(make_Context(error, file, line));
}

// catch failure caused by the DataType operations
catch (const H5::DataTypeIException& error)
{
const except::Context ctx(error.getDetailMsg(), __FILE__, __LINE__, error.getFuncName());
throw hdf5::lite::DataTypeException(ctx);
throw hdf5::lite::DataTypeException(make_Context(error, file, line));
}
}
6 changes: 3 additions & 3 deletions externals/coda-oss/modules/c++/hdf5.lite/source/hdf5.lite.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,21 @@ namespace lite
namespace details
{
// Call the given function, converting H5 exceptions to our own.
void try_catch_H5Exceptions_(std::function<void(void*)> f, void* context = nullptr);
void try_catch_H5Exceptions_(std::function<void(void*)> f, const char* file, int line, void* context = nullptr);

template <typename R, typename... Args>
R return_type_of(R (*)(Args...));

template<typename TFunc, typename ...TArgs>
auto try_catch_H5Exceptions(TFunc f, TArgs&&... args)
auto try_catch_H5Exceptions(TFunc f, const char* file, int line, TArgs&&... args)
{
// Figure out return type by "calling" the function at compile-time
// https://stackoverflow.com/a/53673522/8877
decltype(return_type_of(f)) retval;

// "Hide" the arguments inside of a lambda
auto call_f = [&](void*) { retval = f(std::forward<TArgs>(args)...); };
details::try_catch_H5Exceptions_(call_f);
details::try_catch_H5Exceptions_(call_f, file, line, &retval /*context*/);
return retval;
}

Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
% https://www.mathworks.com/help/matlab/ref/h5write.html
mydata = rand(10, 1);

h5create('123_barfoo_catdog_cx.h5', '/1/bar/cat/i', [10, 1])
h5write('123_barfoo_catdog_cx.h5', '/1/bar/cat/i', mydata)
h5create('123_barfoo_catdog_cx.h5', '/1/bar/cat/r', [10, 1])
h5write('123_barfoo_catdog_cx.h5', '/1/bar/cat/r', mydata)
h5create('123_barfoo_catdog_cx.h5', '/1/bar/dog/i', [10, 1])
h5write('123_barfoo_catdog_cx.h5', '/1/bar/dog/i', mydata)
h5create('123_barfoo_catdog_cx.h5', '/1/bar/dog/r', [10, 1])
h5write('123_barfoo_catdog_cx.h5', '/1/bar/dog/r', mydata)
h5create('123_barfoo_catdog_cx.h5', '/1/foo/cat/i', [10, 1])
h5write('123_barfoo_catdog_cx.h5', '/1/foo/cat/i', mydata)
h5create('123_barfoo_catdog_cx.h5', '/1/foo/cat/r', [10, 1])
h5write('123_barfoo_catdog_cx.h5', '/1/foo/cat/r', mydata)
h5create('123_barfoo_catdog_cx.h5', '/1/foo/dog/i', [10, 1])
h5write('123_barfoo_catdog_cx.h5', '/1/foo/dog/i', mydata)
h5create('123_barfoo_catdog_cx.h5', '/1/foo/dog/r', [10, 1])
h5write('123_barfoo_catdog_cx.h5', '/1/foo/dog/r', mydata)

h5create('123_barfoo_catdog_cx.h5', '/2/bar/cat/i', [10, 1])
h5write('123_barfoo_catdog_cx.h5', '/2/bar/cat/i', mydata)
h5create('123_barfoo_catdog_cx.h5', '/2/bar/cat/r', [10, 1])
h5write('123_barfoo_catdog_cx.h5', '/2/bar/cat/r', mydata)
h5create('123_barfoo_catdog_cx.h5', '/2/bar/dog/i', [10, 1])
h5write('123_barfoo_catdog_cx.h5', '/2/bar/dog/i', mydata)
h5create('123_barfoo_catdog_cx.h5', '/2/bar/dog/r', [10, 1])
h5write('123_barfoo_catdog_cx.h5', '/2/bar/dog/r', mydata)
h5create('123_barfoo_catdog_cx.h5', '/2/foo/cat/i', [10, 1])
h5write('123_barfoo_catdog_cx.h5', '/2/foo/cat/i', mydata)
h5create('123_barfoo_catdog_cx.h5', '/2/foo/cat/r', [10, 1])
h5write('123_barfoo_catdog_cx.h5', '/2/foo/cat/r', mydata)
h5create('123_barfoo_catdog_cx.h5', '/2/foo/dog/i', [10, 1])
h5write('123_barfoo_catdog_cx.h5', '/2/foo/dog/i', mydata)
h5create('123_barfoo_catdog_cx.h5', '/2/foo/dog/r', [10, 1])
h5write('123_barfoo_catdog_cx.h5', '/2/foo/dog/r', mydata)

h5create('123_barfoo_catdog_cx.h5', '/3/bar/cat/i', [10, 1])
h5write('123_barfoo_catdog_cx.h5', '/3/bar/cat/i', mydata)
h5create('123_barfoo_catdog_cx.h5', '/3/bar/cat/r', [10, 1])
h5write('123_barfoo_catdog_cx.h5', '/3/bar/cat/r', mydata)
h5create('123_barfoo_catdog_cx.h5', '/3/bar/dog/i', [10, 1])
h5write('123_barfoo_catdog_cx.h5', '/3/bar/dog/i', mydata)
h5create('123_barfoo_catdog_cx.h5', '/3/bar/dog/r', [10, 1])
h5write('123_barfoo_catdog_cx.h5', '/3/bar/dog/r', mydata)
h5create('123_barfoo_catdog_cx.h5', '/3/foo/cat/i', [10, 1])
h5write('123_barfoo_catdog_cx.h5', '/3/foo/cat/i', mydata)
h5create('123_barfoo_catdog_cx.h5', '/3/foo/cat/r', [10, 1])
h5write('123_barfoo_catdog_cx.h5', '/3/foo/cat/r', mydata)
h5create('123_barfoo_catdog_cx.h5', '/3/foo/dog/i', [10, 1])
h5write('123_barfoo_catdog_cx.h5', '/3/foo/dog/i', mydata)
h5create('123_barfoo_catdog_cx.h5', '/3/foo/dog/r', [10, 1])
h5write('123_barfoo_catdog_cx.h5', '/3/foo/dog/r', mydata)

h5disp('123_barfoo_catdog_cx.h5')
111 changes: 107 additions & 4 deletions externals/coda-oss/modules/c++/hdf5.lite/unittests/test_hdf5info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ static std::filesystem::path find_unittest_file(const std::filesystem::path& nam
static const auto unittests = std::filesystem::path("modules") / "c++" / "hdf5.lite" / "unittests";
return sys::test::findGITModuleFile("coda-oss", unittests, name);
}

TEST_CASE(test_hdf5Info_IOException)
{
static const std::filesystem::path path = "does not exist . h5";
Expand All @@ -55,6 +56,16 @@ TEST_CASE(test_hdf5FileInfo)
static const auto path = find_unittest_file("example.h5");

// https://www.mathworks.com/help/matlab/ref/h5info.html
/*
info = struct with fields:
Filename: '/mathworks/devel/bat/Bdoc22b/build/matlab/toolbox/matlab/demos/example.h5'
Name: '/'
Groups: [4x1 struct]
Datasets: []
Datatypes: []
Links: []
Attributes: [2x1 struct]
*/
const auto info = hdf5::lite::fileInfo(path);
TEST_ASSERT_EQ(path.string(), info.filename);
TEST_ASSERT_EQ("/", info.name);
Expand All @@ -71,7 +82,16 @@ TEST_CASE(test_hdf5GroupInfo)

// https://www.mathworks.com/help/matlab/ref/h5info.html
const auto info = hdf5::lite::groupInfo(path, "/g4");

/*
info = struct with fields:
Filename: '/mathworks/devel/bat/Bdoc22b/build/matlab/toolbox/matlab/demos/example.h5'
Name: '/g4'
Groups: []
Datasets: [4x1 struct]
Datatypes: []
Links: []
Attributes: []
*/
TEST_ASSERT_EQ(path.string(), info.filename);
TEST_ASSERT_EQ("/g4", info.name);
TEST_ASSERT_TRUE(info.groups.empty());
Expand All @@ -87,21 +107,104 @@ TEST_CASE(test_hdf5DatasetInfo)

// https://www.mathworks.com/help/matlab/ref/h5info.html
const auto info = hdf5::lite::datasetInfo(path, "/g4/time");

/*
info = struct with fields:
Filename: '/mathworks/devel/bat/Bdoc22b/build/matlab/toolbox/matlab/demos/example.h5'
Name: 'time'
Datatype: [1x1 struct]
Dataspace: [1x1 struct]
ChunkSize: 10
FillValue: 0
Filters: []
Attributes: [2x1 struct]
*/
TEST_ASSERT_EQ(path.string(), info.filename);
TEST_ASSERT_EQ("time", info.name);
TEST_ASSERT(info.datatype.h5Class == hdf5::lite::Class::Float);
//TEST_ASSERT(info.dataspace == hdf5::lite::Class::Float);
// TEST_ASSERT(info.chunkSize == hdf5::lite::Class::Float);
// TEST_ASSERT(info.fillValue == hdf5::lite::Class::Float);
//TEST_ASSERT_EQ(info.chunkSize, 10);
//TEST_ASSERT_EQ(info.fillValue, 0);
//TEST_ASSERT_TRUE(info.filters.empty());
//TEST_ASSERT_EQ(info.attributes.size(), 2);
}

static void read_complex(const std::string& testName,
const std::filesystem::path& path, const std::string& datasetPath)
{
const auto i_info = hdf5::lite::datasetInfo(path, datasetPath + "/i");
TEST_ASSERT(i_info.datatype.h5Class == hdf5::lite::Class::Float);

const auto r_info = hdf5::lite::datasetInfo(path, datasetPath + "/r");
TEST_ASSERT(r_info.datatype.h5Class == hdf5::lite::Class::Float);
}

TEST_CASE(test_hdf5Info_nested)
{
/*
Group '/'
Group '/1'
Group '/1/bar'
Group '/1/bar/cat'
Dataset 'i'
Size: 10x1
MaxSize: 10x1
Datatype: H5T_IEEE_F64LE (double)
ChunkSize: []
Filters: none
FillValue: 0.000000
*/

// outer groups: 1, 2, 3
// sub groups: bar, foo
// sub-sub groups: cat, dog
// data: i (float array), r (float array)
static const auto path = find_unittest_file("123_barfoo_catdog_cx.h5");

// https://www.mathworks.com/help/matlab/ref/h5info.html
const auto info = hdf5::lite::fileInfo(path);
TEST_ASSERT_EQ(path.string(), info.filename);
TEST_ASSERT_EQ("/", info.name);
TEST_ASSERT_TRUE(info.datasets.empty());
TEST_ASSERT_TRUE(info.datatypes.empty());

const std::vector<std::string> expectedOuterGroupNames{"1" , "2", "3"};
TEST_ASSERT_EQ(info.groups.size(), expectedOuterGroupNames.size());
for (size_t outer = 0; outer < info.groups.size(); outer++)
{
const auto groupName = info.groups[outer].name;
TEST_ASSERT_EQ(groupName, expectedOuterGroupNames[outer]);

const auto subGroupInfo = hdf5::lite::groupInfo(path, "/" + groupName);

const std::vector<std::string> expectedSubGroupNames{"bar", "foo"};
TEST_ASSERT_EQ(subGroupInfo.groups.size(), expectedSubGroupNames.size());
for (size_t sub = 0; sub < subGroupInfo.groups.size(); sub++)
{
const auto subGroupName = subGroupInfo.groups[sub].name;
TEST_ASSERT_EQ(subGroupName, expectedSubGroupNames[sub]);

const auto subSubGroupInfo = hdf5::lite::groupInfo(path, "/" + groupName + "/" + subGroupName);

const std::vector<std::string> expectedSubSubGroupNames{"cat", "dog"};
TEST_ASSERT_EQ(subSubGroupInfo.groups.size(), expectedSubSubGroupNames.size());
for (size_t subsub = 0; subsub < subSubGroupInfo.groups.size(); subsub++)
{
const auto subSubGroupName = subSubGroupInfo.groups[subsub].name;
TEST_ASSERT_EQ(subSubGroupName, expectedSubSubGroupNames[subsub]);

const auto datasetPath = "/" + groupName + "/" + subGroupName + "/" + subSubGroupName;
read_complex(testName, path, datasetPath);
}
}
}
}

TEST_MAIN(
TEST_CHECK(test_hdf5Info_IOException);

TEST_CHECK(test_hdf5FileInfo);
TEST_CHECK(test_hdf5GroupInfo);
TEST_CHECK(test_hdf5DatasetInfo);

TEST_CHECK(test_hdf5Info_nested);
)
Loading

0 comments on commit c68727a

Please sign in to comment.