public void WriteAndReadOneString() { try { string[] str = new string[] { "test" }; string filename = Path.Combine(folder, "testOneStringList.H5"); // Open file and write the strings var fileId = Hdf5.CreateFile(filename); Assert.IsTrue(fileId > 0); Hdf5.WriteStrings(fileId, "/test", str); // Read the strings and close file Assert.IsTrue(fileId > 0); IEnumerable <string> strs2 = Hdf5.ReadStrings(fileId, "/test", "").result; Assert.IsTrue(strs2.Count() == 1); foreach (var s in strs2) { Assert.IsTrue(str[0] == s); } ; Hdf5.CloseFile(fileId); } catch (Exception ex) { CreateExceptionAssert(ex); } }
public void WriteAndOverrideChunkedDataset() { var data = CreateDataset(); string filename = Path.Combine(folder, "testOverrideChunks.H5"); string groupName = "/test"; string datasetName = "Data"; //create var fileId = Hdf5.CreateFile(filename); Assert.IsTrue(fileId > 0); var groupId = Hdf5.CreateOrOpenGroup(fileId, groupName); Assert.IsTrue(groupId >= 0); using (var chunkedDset = new ChunkedDataset <double>(datasetName, groupId)) { chunkedDset.AppendOrCreateDataset(data); } Hdf5.CloseFile(fileId); //read fileId = Hdf5.OpenFile(filename); var dataRead = Hdf5.ReadDatasetToArray <double>(fileId, string.Concat(groupName, "/", datasetName)); Hdf5.CloseFile(fileId); CompareDatasets(dataRead.result as double[, ], data); }
public void WriteAndReadOneUnicodeString() { try { string test = "Γαζέες καὶ μυρτιὲς δὲν θὰ βρῶ πιὰ στὸ χρυσαφὶ ξέφωτο"; string filename = Path.Combine(folder, "testUnicodeString.H5"); var fileId = Hdf5.CreateFile(filename); Hdf5.WriteUnicodeString(fileId, "/test", test); Assert.IsTrue(Hdf5.CloseFile(fileId) >= 0); fileId = Hdf5.OpenFile(filename); string readStr = Hdf5.ReadUnicodeString(fileId, "/test"); //var readStr = Hdf5.ReadStrings(fileId, "/test"); Assert.IsTrue(test == readStr); Assert.IsTrue(Hdf5.CloseFile(fileId) >= 0); Hdf5.CloseFile(fileId); } catch (Exception ex) { CreateExceptionAssert(ex); } }
public KamaAcquisitionFile(string filename, AcquisitionInterface acquisitionInterface, ILogger logger, int eitDefaultChunkSize = 24000, int ecgDefaultChunkSize = 10) { FileName = filename; Logger = logger; EITDefaultChunkSize = eitDefaultChunkSize; ECGDefaultChunkSize = ecgDefaultChunkSize; RecordNumber = 1; H5E.set_auto(H5E.DEFAULT, null, IntPtr.Zero); fileId = Hdf5.CreateFile(filename); groupRoot = fileId; groupEIT = Hdf5.CreateOrOpenGroup(groupRoot, "eit"); ProcedureInformation = new ProcedureInformation(fileId, groupRoot, logger) { ProcedureDirectory = Path.GetDirectoryName(filename), StartDateTime = DateTime.Now, EndDateTime = DateTime.Now }; SystemInformation = new SystemInformation(fileId, groupRoot, logger); SystemInformation.SystemType = acquisitionInterface.ToString(); // InjectionGroup = new InjectionGroup(fileId, groupRoot); CalibrationGroup = new CalibrationGroup(fileId, groupRoot, logger); SystemEvents = new SystemEventGroup(fileId, groupRoot, logger); RPosition = new RPositionGroup(fileId, groupRoot, logger); Tags = new TagsGroup(fileId, groupRoot, logger); UserEventsGroup = new UserEventsGroup(fileId, groupRoot, logger); }
public void WriteAndReadStructsWithDatetime() { string filename = Path.Combine(folder, "testCompounds.H5"); try { var fileId = Hdf5.CreateFile(filename); Assert.IsTrue(fileId > 0); var status = Hdf5.WriteCompounds(fileId, "/test", wDataList); Hdf5.CloseFile(fileId); } catch (Exception ex) { CreateExceptionAssert(ex); } try { var fileId = Hdf5.OpenFile(filename); Assert.IsTrue(fileId > 0); var cmpList = Hdf5.ReadCompounds <WData>(fileId, "/test").ToArray(); Hdf5.CloseFile(fileId); CollectionAssert.AreEqual(wDataList, cmpList); } catch (Exception ex) { CreateExceptionAssert(ex); } }
public void WriteAndReadAttribute() { string filename = Path.Combine(folder, "testAttribute.H5"); try { var fileId = Hdf5.CreateFile(filename); Assert.IsTrue(fileId > 0); var groupId = Hdf5.CreateOrOpenGroup(fileId, "test"); DateTime nowTime = DateTime.Now; Hdf5.WriteAttribute(groupId, "time", nowTime); Hdf5.WriteAttributes <DateTime>(groupId, "times", new List <DateTime> { nowTime, nowTime.AddDays(1) }.ToArray()); DateTime readTime = Hdf5.ReadAttribute <DateTime>(groupId, "time"); var allTimes = Hdf5.ReadAttributes <DateTime>(groupId, "times"); Assert.IsTrue(readTime == nowTime); Assert.IsTrue(Hdf5.CloseFile(fileId) == 0); } catch (Exception ex) { CreateExceptionAssert(ex); } }
public void WriteAndReadListOfStrings() { try { List <string> strs = new List <string>(); strs.Add("t"); strs.Add("tst"); strs.Add("test1"); strs.Add("small test"); string filename = Path.Combine(folder, "testStringList.H5"); // Open file and write the strings var fileId = Hdf5.CreateFile(filename); Assert.IsTrue(fileId > 0); Hdf5.WriteStrings(fileId, "/test", strs); // Read the strings and close file Assert.IsTrue(fileId > 0); IEnumerable <string> strs2 = Hdf5.ReadStrings(fileId, "/test"); Assert.IsTrue(strs.Count() == strs2.Count()); foreach (var item in strs2.Select((str, i) => new { i, str })) { Assert.IsTrue(item.str == strs[item.i]); } Hdf5.CloseFile(fileId); } catch (Exception ex) { CreateExceptionAssert(ex); } }
public void WriteAndReadStringAttribute() { string filename = Path.Combine(folder, "testAttributeString.H5"); try { var fileId = Hdf5.CreateFile(filename); Assert.IsTrue(fileId > 0); var groupId = Hdf5.CreateOrOpenGroup(fileId, "test"); string attrStr = "this is an attribute"; Hdf5.WriteAttribute(groupId, "time", attrStr); string readStr = Hdf5.ReadAttribute <string>(groupId, "time_Non_Exist"); Assert.IsTrue(string.IsNullOrEmpty(readStr)); readStr = Hdf5.ReadAttribute <string>(groupId, "time"); Assert.IsTrue(readStr == attrStr); Assert.IsTrue(H5G.close(groupId) == 0); Assert.IsTrue(Hdf5.CloseFile(fileId) == 0); ErrorCountExpected = 2; } catch (Exception ex) { CreateExceptionAssert(ex); } }
public void WriteAndReadStructs() { string filename = Path.Combine(folder, "testCompoundsWithDifferentDisplayName.H5"); Dictionary <string, List <string> > attributes = new Dictionary <string, List <string> >(); try { var fileId = Hdf5.CreateFile(filename); Assert.IsTrue(fileId > 0); var status = Hdf5.WriteCompounds(fileId, "/test", wData2List, attributes); Hdf5.CloseFile(fileId); } catch (Exception ex) { CreateExceptionAssert(ex); } try { var fileId = Hdf5.OpenFile(filename); Assert.IsTrue(fileId > 0); var cmpList = Hdf5.ReadCompounds <WData2>(fileId, "/test", "").ToArray(); Hdf5.CloseFile(fileId); CollectionAssert.AreEqual(wData2List, cmpList); } catch (Exception ex) { CreateExceptionAssert(ex); } }
public void WriteAndReadJaggedArray() { string filename = Path.Combine(folder, $"{nameof(WriteAndReadJaggedArray)}.H5"); var obj = new TestClassWithJaggedArray(); try { var fileId = Hdf5.CreateFile(filename); Assert.IsTrue(fileId > 0); var status = Hdf5.WriteObject(fileId, obj, "test"); Hdf5.CloseFile(fileId); } catch (Exception ex) { CreateExceptionAssert(ex); } try { var fileId = Hdf5.OpenFile(filename); Assert.IsTrue(fileId > 0); var obj2 = Hdf5.ReadObject <TestClassWithJaggedArray>(fileId, "test"); Assert.IsTrue(obj.Equals(obj2)); Hdf5.CloseFile(fileId); } catch (Exception ex) { CreateExceptionAssert(ex); } }
public void WriteAndReadListOfList() { string filename = Path.Combine(folder, $"{nameof(WriteAndReadList)}.H5"); TestClassListOfList data = new TestClassListOfList(); try { var fileId = Hdf5.CreateFile(filename); Assert.IsTrue(fileId > 0); Hdf5.WriteObject(fileId, data, "test"); Hdf5.CloseFile(fileId); } catch (Exception ex) { CreateExceptionAssert(ex); } try { var fileId = Hdf5.OpenFile(filename); Assert.IsTrue(fileId > 0); var objWithList = Hdf5.ReadObject <TestClassListOfList>(fileId, "test"); Hdf5.CloseFile(fileId); Assert.IsTrue(objWithList.Data[0].SequenceEqual(data.Data[0])); Assert.IsTrue(objWithList.Data[1].SequenceEqual(data.Data[1])); } catch (Exception ex) { CreateExceptionAssert(ex); } }
public void WriteAndReadSystemEvent() { string filename = Path.Combine(folder, "testCompounds.H5"); List <SystemEvent> se = new List <SystemEvent>(); Dictionary <string, List <string> > attributes = new Dictionary <string, List <string> >(); try { se.Add(new SystemEvent(5, "55", "3300000000000000000000000", "555555555555555555555555555555555")); se.Add(new SystemEvent(1, "255", "3d3000000000007777773", "ggggggggggggdf")); var fileId = Hdf5.CreateFile(filename); Assert.IsTrue(fileId > 0); var status = Hdf5.WriteCompounds(fileId, "/test", se, attributes); Hdf5.CloseFile(fileId); } catch (Exception ex) { CreateExceptionAssert(ex); } try { var fileId = Hdf5.OpenFile(filename); Assert.IsTrue(fileId > 0); var cmpList = Hdf5.ReadCompounds <SystemEvent>(fileId, "/test", "").ToArray(); Hdf5.CloseFile(fileId); CollectionAssert.AreEqual(se, cmpList); } 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 WriteAndReadStructsWithArray() { string filename = Path.Combine(folder, "testArrayCompounds.H5"); try { var fileId = Hdf5.CreateFile(filename); Assert.IsTrue(fileId > 0); var status = Hdf5.WriteCompounds(fileId, "/test", responseList); Hdf5.CloseFile(fileId); } catch (Exception ex) { CreateExceptionAssert(ex); } try { var fileId = Hdf5.OpenFile(filename); Assert.IsTrue(fileId > 0); Responses[] cmpList = Hdf5.ReadCompounds <Responses>(fileId, "/test").ToArray(); Hdf5.CloseFile(fileId); var isSame = responseList.Zip(cmpList, (r, c) => { return(r.MCID == c.MCID && r.PanelIdx == c.PanelIdx && r.ResponseValues.Zip(c.ResponseValues, (rr, cr) => rr == cr).All(v => v == true)); }); Assert.IsTrue(isSame.All(s => s == true)); } catch (Exception ex) { CreateExceptionAssert(ex); } }
public void save_weights(string filepath, bool overwrite = true, string save_format = null, object options = null) { long fileId = Hdf5.CreateFile(filepath); hdf5_format.save_weights_to_hdf5_group(fileId, Layers); Hdf5.CloseFile(fileId); }
public void WriteReadAndEditAttribute() { string filename = Path.Combine(folder, "WriteReadAndEditAttribute.H5"); try { var fileId = Hdf5.CreateFile(filename); Assert.IsTrue(fileId > 0); var groupId = Hdf5.CreateOrOpenGroup(fileId, "test"); DateTime nowTime = DateTime.Now; Hdf5.WriteAttribute(groupId, "time", nowTime); DateTime readTime = Hdf5.ReadAttribute <DateTime>(groupId, "time"); Assert.IsTrue(readTime == nowTime); Hdf5.CloseFile(fileId); fileId = Hdf5.OpenFile(filename, false); readTime = Hdf5.ReadAttribute <DateTime>(groupId, "time"); Assert.IsTrue(readTime == nowTime); nowTime = DateTime.Now; Hdf5.WriteAttribute(groupId, "time", nowTime); readTime = Hdf5.ReadAttribute <DateTime>(groupId, "time"); Assert.IsTrue(readTime == nowTime); Hdf5.CloseFile(fileId); fileId = Hdf5.OpenFile(filename, false); readTime = Hdf5.ReadAttribute <DateTime>(groupId, "time"); Assert.IsTrue(readTime == nowTime); 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 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 WriteAndReadObjectWithStructs() { string filename = Path.Combine(folder, "testObjectWithStructArray.H5"); try { var fileId = Hdf5.CreateFile(filename); Assert.IsTrue(fileId > 0); var status = Hdf5.WriteObject(fileId, classWithStructs, "test"); Hdf5.CloseFile(fileId); } catch (Exception ex) { CreateExceptionAssert(ex); } try { TestClassWithStructs objWithStructs; var fileId = Hdf5.OpenFile(filename); Assert.IsTrue(fileId > 0); objWithStructs = Hdf5.ReadObject <TestClassWithStructs>(fileId, "test"); CollectionAssert.AreEqual(wDataList, objWithStructs.DataList); 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); } }
public void WriteAndReadChunckedDataset2() { string filename = Path.Combine(folder, "testChunks2.H5"); string groupName = "/test"; string datasetName = "Data"; try { var fileId = Hdf5.CreateFile(filename); Assert.IsTrue(fileId > 0); var groupId = Hdf5.CreateGroup(fileId, groupName); Assert.IsTrue(groupId >= 0); //var chunkSize = new ulong[] { 5, 5 }; using (var chunkedDset = new ChunkedDataset <double>(datasetName, groupId)) { foreach (var ds in dsets) { chunkedDset.AppendOrCreateDataset(ds); } ; } Hdf5.CloseFile(fileId); } catch (Exception ex) { CreateExceptionAssert(ex); } try { var fileId = Hdf5.OpenFile(filename); //var groupId = H5G.open(fileId, groupName); //var dset = Hdf5.ReadDatasetToArray<double>(groupId, datasetName); var dset = Hdf5.ReadDatasetToArray <double>(fileId, string.Concat(groupName, "/", datasetName)); Assert.IsTrue(dset.result.Rank == dsets.First().Rank); var xSum = dsets.Select(d => d.GetLength(0)).Sum(); Assert.IsTrue(xSum == dset.result.GetLength(0)); var testRange = Enumerable.Range(0, 30).Select(t => (double)t); // get every 5th element in the matrix var x0Range = dset.result.Cast <double>().Where((d, i) => i % 5 == 0); Assert.IsTrue(testRange.SequenceEqual(x0Range)); Hdf5.CloseFile(fileId); } catch (Exception ex) { CreateExceptionAssert(ex); } }
public void WriteAndReadPrimitives() { string filename = Path.Combine(folder, "testPrimitives.H5"); int intValue = 2; double dblValue = 1.1; string strValue = "test"; bool boolValue = true; var groupStr = "/test"; string concatFunc(string x) => string.Concat(groupStr, "/", x); Dictionary <string, List <string> > attributes = new Dictionary <string, List <string> >(); try { var fileId = Hdf5.CreateFile(filename); Assert.IsTrue(fileId > 0); var groupId = Hdf5.CreateGroup(fileId, groupStr); Hdf5.WriteOneValue(groupId, concatFunc(nameof(intValue)), intValue, attributes); Hdf5.WriteOneValue(groupId, concatFunc(nameof(dblValue)), dblValue, attributes); Hdf5.WriteOneValue(groupId, concatFunc(nameof(strValue)), strValue, attributes); Hdf5.WriteOneValue(groupId, concatFunc(nameof(boolValue)), boolValue, attributes); Hdf5.CloseGroup(groupId); Hdf5.CloseFile(fileId); } catch (Exception ex) { CreateExceptionAssert(ex); } try { var fileId = Hdf5.OpenFile(filename); Assert.IsTrue(fileId > 0); var groupId = H5G.open(fileId, groupStr); int readInt = Hdf5.ReadOneValue <int>(groupId, concatFunc(nameof(intValue))); Assert.IsTrue(intValue == readInt); double readDbl = Hdf5.ReadOneValue <double>(groupId, concatFunc(nameof(dblValue))); Assert.IsTrue(dblValue == readDbl); string readStr = Hdf5.ReadOneValue <string>(groupId, concatFunc(nameof(strValue))); Assert.IsTrue(strValue == readStr); bool readBool = Hdf5.ReadOneValue <bool>(groupId, concatFunc(nameof(boolValue))); Assert.IsTrue(boolValue == readBool); H5G.close(groupId); Hdf5.CloseFile(fileId); } catch (Exception ex) { CreateExceptionAssert(ex); } }
public void WriteAndReadSubsetOfDataset() { string filename = Path.Combine(folder, "testSubset.H5"); try { var fileId = Hdf5.CreateFile(filename); Assert.IsTrue(fileId > 0); var chunkSize = new ulong[] { 5, 5 }; using (var chunkedDset = new ChunkedDataset <double>("/test", fileId, dsets.First())) { foreach (var ds in dsets.Skip(1)) { chunkedDset.AppendDataset(ds); } ; } Hdf5.CloseFile(fileId); } catch (Exception ex) { CreateExceptionAssert(ex); } try { var fileId = Hdf5.OpenFile(filename); ulong begIndex = 8; ulong endIndex = 21; var dset = Hdf5.ReadDataset <double>(fileId, "/test", begIndex, endIndex); Hdf5.CloseFile(fileId); Assert.IsTrue(dset.Rank == dsets.First().Rank); int count = Convert.ToInt32(endIndex - begIndex + 1); Assert.IsTrue(count == dset.GetLength(0)); // Creat a range from number 8 to 21 var testRange = Enumerable.Range((int)begIndex, count).Select(t => (double)t); // Get the first column from row index number 8 (the 9th row) to row index number 21 (22th row) var x0Range = dset.Cast <double>().Where((d, i) => i % 5 == 0); Assert.IsTrue(testRange.SequenceEqual(x0Range)); } catch (Exception ex) { CreateExceptionAssert(ex); } }
public void WriteAndReadObjectWithPropertiesAndArrayPropertyTest() { try { var testClass = new TestClassWithArray() { TestInteger = 2, TestDouble = 1.1, TestBoolean = true, TestString = "test string", TestDoubles = new double[] { 1.1, 1.2, -1.1, -1.2 }, TestStrings = new string[] { "one", "two", "three", "four" } }; testClassWithArrays.TestInteger = 2; testClassWithArrays.TestDouble = 1.1; testClassWithArrays.TestBoolean = true; testClassWithArrays.TestString = "test string"; testClassWithArrays.TestDoubles = new double[] { 1.1, 1.2, -1.1, -1.2 }; testClassWithArrays.TestStrings = new string[] { "one", "two", "three", "four" }; string filename = Path.Combine(folder, "testArrayObjects.H5"); var fileId = Hdf5.CreateFile(filename); Assert.IsTrue(fileId >= 0); Hdf5.WriteObject(fileId, testClassWithArrays, "objectWithTwoArrays"); TestClassWithArray readObject = new TestClassWithArray { TestStrings = new string[0], TestDoubles = null, TestDouble = double.NaN }; readObject = Hdf5.ReadObject(fileId, readObject, "objectWithTwoArrays"); Assert.IsTrue(testClassWithArrays.Equals(readObject)); readObject = Hdf5.ReadObject <TestClassWithArray>(fileId, "objectWithTwoArrays"); Assert.IsTrue(testClassWithArrays.Equals(readObject)); Assert.IsTrue(Hdf5.CloseFile(fileId) >= 0); } catch (Exception ex) { CreateExceptionAssert(ex); } }
public void WriteAndReadObjectWithHdf5Attributes() { string filename = Path.Combine(folder, "testHdf5Attribute.H5"); var attObject = new AttributeClass(); try { var fileId = Hdf5.CreateFile(filename); Assert.IsTrue(fileId > 0); Hdf5.WriteObject(fileId, attObject, "anObject"); Assert.IsTrue(Hdf5.CloseFile(fileId) == 0); } catch (Exception ex) { CreateExceptionAssert(ex); } }
private long WriteDataset(string filename) { long tef2 = Hdf5.CreateFile(filename); int[] blah = { 1, 2, 4, 5, 0 }; Hdf5.WriteDatasetFromArray <int>(tef2, "blah", blah); Hdf5.CloseFile(tef2); var what = "???"; // breakpoint in VS to test h5 file contents independently before next write step tef2 = Hdf5.OpenFile(filename); blah[4] = 6; Hdf5.WriteDatasetFromArray <int>(tef2, "blah", blah); // This command throws several debug errors from PInvoke var(success, result) = Hdf5.ReadDataset <int>(tef2, "blah"); Assert.IsTrue(success); Assert.IsTrue(result.Cast <int>().SequenceEqual(blah)); // loading the hdf5 file shows it only has {1, 2, 4, 5, 0} stored. return(tef2); }
public void WriteAndReadObjectWithPropertiesTest() { string filename = Path.Combine(folder, "testObjects.H5"); try { testClass.TestInteger = 2; testClass.TestDouble = 1.1; testClass.TestBoolean = true; testClass.TestString = "test string"; // 31-Oct-2003, 18:00 is 731885.75 in matlab testClass.TestTime = new DateTime(2003, 10, 31, 18, 0, 0); var fileId = Hdf5.CreateFile(filename); Assert.IsTrue(fileId > 0); Hdf5.WriteObject(fileId, testClass, "objectWithProperties"); Hdf5.CloseFile(fileId); } catch (Exception ex) { CreateExceptionAssert(ex); } try { var fileId = Hdf5.OpenFile(filename); Assert.IsTrue(fileId > 0); TestClass readObject = new TestClass(); readObject = Hdf5.ReadObject(fileId, readObject, "objectWithProperties"); Assert.IsTrue(testClass.Equals(readObject)); readObject = Hdf5.ReadObject <TestClass>(fileId, "objectWithProperties"); Assert.IsTrue(testClass.Equals(readObject)); Assert.IsTrue(Hdf5.CloseFile(fileId) >= 0); } catch (Exception ex) { CreateExceptionAssert(ex); } }
public void WriteAndReadStringAttribute() { string filename = Path.Combine(folder, "testAttributeString.H5"); try { var fileId = Hdf5.CreateFile(filename); Assert.IsTrue(fileId > 0); var groupId = Hdf5.CreateGroup(fileId, "test"); string attrStr = "this is an attribute"; Hdf5.WriteAttribute(groupId, "time", attrStr); string readStr = Hdf5.ReadAttribute <string>(groupId, "time"); Assert.IsTrue(readStr == attrStr); Assert.IsTrue(Hdf5.CloseFile(fileId) == 0); } catch (Exception ex) { CreateExceptionAssert(ex); } }
public void WriteAndReadAllPrimitives() { string filename = Path.Combine(folder, "testAllPrimitives.H5"); //var groupStr = "/test"; //string concatFunc(string x) => string.Concat(groupStr, "/", x); try { var fileId = Hdf5.CreateFile(filename); Assert.IsTrue(fileId > 0); Hdf5.WriteObject(fileId, allTypesObject, "/test"); var readObject = Hdf5.ReadObject <AllTypesClass>(fileId, "/test"); Assert.IsTrue(allTypesObject.PublicInstanceFieldsEqual(readObject)); Assert.IsTrue(Hdf5.CloseFile(fileId) == 0); } catch (Exception ex) { CreateExceptionAssert(ex); } }
public void WriteAndReadAttributeByPath() { string filename = Path.Combine(folder, "testAttributeByPath.H5"); string path = "/A/B/C/D/E/F/I"; string attributeValue = "test"; Hdf5.Settings.LowerCaseNaming = false; var fileId = Hdf5.CreateFile(filename); Assert.IsTrue(fileId > 0); var groupId = Hdf5.CreateGroupRecursively(fileId, Hdf5Utils.NormalizedName(path)); var result = Hdf5Utils.WriteAttributeByPath(filename, path, "VALID", attributeValue); Assert.IsTrue(result); var write = Hdf5Utils.ReadAttributeByPath(filename, path, "VALID"); Assert.IsTrue(write.success); Assert.IsTrue(write.value == attributeValue); Assert.IsTrue(H5G.close(groupId) == 0); Assert.IsTrue(Hdf5.CloseFile(fileId) == 0); }