public void WriteAndReadDataset() { string filename = Path.Combine(folder, "testDataset.H5"); var dset = dsets.First(); try { var fileId = Hdf5.CreateFile(filename); Assert.IsTrue(fileId > 0); Hdf5.WriteDataset(fileId, "/test", dset); Hdf5.CloseFile(fileId); } catch (Exception ex) { CreateExceptionAssert(ex); } try { var fileId = Hdf5.OpenFile(filename); Assert.IsTrue(fileId > 0); double[,] dset2 = (double[, ])Hdf5.ReadDataset <double>(fileId, "/test").result; CompareDatasets(dset, dset2); bool same = dset == dset2; Hdf5.CloseFile(fileId); } catch (Exception ex) { CreateExceptionAssert(ex); } }
public void WriteAndReadDatetimeDataset() { string filename = Path.Combine(folder, "testDatetime.H5"); var times = new DateTime[10, 5]; var offset = new DateTime(2000, 1, 1, 12, 0, 0); for (var i = 0; i < 10; i++) { for (var j = 0; j < 5; j++) { times[i, j] = offset.AddDays(i + j * 5); } } try { var fileId = Hdf5.CreateFile(filename); Assert.IsTrue(fileId > 0); Hdf5.WriteDataset(fileId, "/test", times); var timesRead = (DateTime[, ])Hdf5.ReadDataset <DateTime>(fileId, "/test").result; CompareDatasets(times, timesRead); Hdf5.CloseFile(fileId); } catch (Exception ex) { CreateExceptionAssert(ex); } }
public void WriteAndReadTimespanDataset() { string filename = Path.Combine(folder, "testTimespan.H5"); var times = new TimeSpan[10, 5]; var offset = new TimeSpan(1, 0, 0, 0, 0); for (var i = 0; i < 10; i++) { for (var j = 0; j < 5; j++) { times[i, j] = offset.Add(new TimeSpan(i + j * 5, 0, 0)); } } try { var fileId = Hdf5.CreateFile(filename); Assert.IsTrue(fileId > 0); Hdf5.WriteDataset(fileId, "/test", times); TimeSpan[,] timesRead = (TimeSpan[, ])Hdf5.ReadDataset <TimeSpan>(fileId, "/test").result; CompareDatasets(times, timesRead); Hdf5.CloseFile(fileId); } catch (Exception ex) { CreateExceptionAssert(ex); } }
public void WriteAndReadGroupsWithDataset() { string filename = Path.Combine(folder, "testGroups.H5"); try { var fileId = Hdf5.CreateFile(filename); Assert.IsTrue(fileId > 0); var dset = dsets.First(); var groupId = H5G.create(fileId, Hdf5Utils.NormalizedName("/A")); ///B/C/D/E/F/G/H Hdf5.WriteDataset(groupId, Hdf5Utils.NormalizedName("test"), dset); var subGroupId = Hdf5.CreateOrOpenGroup(groupId, Hdf5Utils.NormalizedName("C")); var subGroupId2 = Hdf5.CreateOrOpenGroup(groupId, Hdf5Utils.NormalizedName("/D")); // will be saved at the root location dset = dsets.Skip(1).First(); Hdf5.WriteDataset(subGroupId, Hdf5Utils.NormalizedName("test2"), dset); Hdf5.CloseGroup(subGroupId); Hdf5.CloseGroup(subGroupId2); Hdf5.CloseGroup(groupId); groupId = H5G.create(fileId, Hdf5Utils.NormalizedName("/A/B")); ///B/C/D/E/F/G/H dset = dsets.Skip(1).First(); Hdf5.WriteDataset(groupId, Hdf5Utils.NormalizedName("test"), dset); Hdf5.CloseGroup(groupId); groupId = Hdf5.CreateGroupRecursively(fileId, Hdf5Utils.NormalizedName("A/B/C/D/E/F/I")); Hdf5.CloseGroup(groupId); Hdf5.CloseFile(fileId); fileId = Hdf5.OpenFile(filename); Assert.IsTrue(fileId > 0); fileId = Hdf5.OpenFile(filename); groupId = H5G.open(fileId, Hdf5Utils.NormalizedName("/A/B")); double[,] dset2 = (double[, ])Hdf5.ReadDataset <double>(groupId, Hdf5Utils.NormalizedName("test")).result; CompareDatasets(dset, dset2); Assert.IsTrue(Hdf5.CloseGroup(groupId) >= 0); groupId = H5G.open(fileId, Hdf5Utils.NormalizedName("/A/C")); dset2 = (double[, ])Hdf5.ReadDataset <double>(groupId, Hdf5Utils.NormalizedName("test2")).result; CompareDatasets(dset, dset2); Assert.IsTrue(Hdf5.CloseGroup(groupId) >= 0); bool same = dset == dset2; dset = dsets.First(); dset2 = (double[, ])Hdf5.ReadDataset <double>(fileId, Hdf5Utils.NormalizedName("/A/test")).result; CompareDatasets(dset, dset2); Assert.IsTrue(Hdf5Utils.ItemExists(fileId, Hdf5Utils.NormalizedName("A/B/C/D/E/F/I"), DataTypes.Hdf5ElementType.Dataset)); Assert.IsTrue(Hdf5.CloseFile(fileId) == 0); } catch (Exception ex) { CreateExceptionAssert(ex); } }
static void WriteFile(string filePath) { var file = Hdf5.CreateFile(filePath); var group = Hdf5.CreateOrOpenGroup(file, "group"); Hdf5.WriteDataset(group, "dataset", new int[, ] { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 } }); var hello = "早上好!"; Hdf5.WriteStringAttribute(group, "string", hello, "dataset"); Hdf5.CloseGroup(group); Hdf5.CloseFile(file); }