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 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 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 List <(IVariableV1, NDArray)> load_weights(string filepath, bool by_name = false, bool skip_mismatch = false, object options = null) { long fileId = Hdf5.OpenFile(filepath, true); bool msuccess = Hdf5.GroupExists(fileId, "model_weights"); bool lsuccess = Hdf5.GroupExists(fileId, "layer_names"); if (!lsuccess && msuccess) { fileId = H5G.open(fileId, "model_weights"); } if (by_name) { //fdf5_format.load_weights_from_hdf5_group_by_name(); throw new NotImplementedException(""); } else { var weights = hdf5_format.load_weights_from_hdf5_group(fileId, Layers); Hdf5.CloseFile(fileId); // return a reference to prevent GC collect Variable. return(weights); } }
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 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); } }
static void ReadFile(string filePath) { var file = Hdf5.OpenFile(filePath, true); var group = Hdf5.CreateOrOpenGroup(file, "group"); var(ok, rawData) = Hdf5.ReadDataset <int>(group, "dataset"); if (ok) { var data = (int[, ])rawData; for (int i = 0; i < data.GetLength(0); ++i) { for (int j = 0; j < data.GetLength(1); ++j) { Write($"{data[i, j],3}"); } WriteLine(); } } //var dataSet = H5D.open(group, "dataset"); //var hello = Hdf5.ReadUnicodeString(dataSet, "string"); //H5D.close(dataSet); //WriteLine($"string: {hello}"); Hdf5.CloseGroup(group); Hdf5.CloseFile(file); }
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 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 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 load_weights(string filepath, bool by_name = false, bool skip_mismatch = false, object options = null) { long fileId = Hdf5.OpenFile(filepath, true); if (fileId < 0) { tf_output_redirect.WriteLine($"Can't find weights file {filepath}"); return; } bool msuccess = Hdf5.GroupExists(fileId, "model_weights"); bool lsuccess = Hdf5.GroupExists(fileId, "layer_names"); if (!lsuccess && msuccess) { fileId = H5G.open(fileId, "model_weights"); } if (by_name) { //fdf5_format.load_weights_from_hdf5_group_by_name(); throw new NotImplementedException(""); } else { hdf5_format.load_weights_from_hdf5_group(fileId, Layers); Hdf5.CloseFile(fileId); } }
//[TestMethod] public void ReadObject() { Hdf5.Settings.LowerCaseNaming = false; Hdf5.Settings.EnableErrorReporting(true); Hdf5Utils.LogWarning = (s) => Errors.Add(s); Hdf5Utils.LogError = (s) => Errors.Add(s); string filename = @"D:\h5\d.hdf5"; long fileId = -1; try { fileId = Hdf5.OpenFile(filename, true); Assert.IsTrue(fileId > 0); //var result = Hdf5.ReadObject<Coordinate>(fileId, "/MODEL_STAGE[1]/MODEL/NODES"); var step = "/MODEL_STAGE[1]/RESULTS/ON_NODES/DISPLACEMENT/DATA"; var result2 = Hdf5.ReadObject <Steps>(fileId, step); } finally { if (fileId > 0) { Hdf5.CloseFile(fileId); } } }
static void Main(string[] args) { string fileName = @"D:\Shubham\HDF5\HDFinOneLine_1434.H5"; var fileID = Hdf5.OpenFile(fileName); var groupId = H5G.open(fileID, "A/B"); Array dset2 = Hdf5.ReadDataset <Int32>(groupId, "Sequence 2", 100000, 200000); Console.WriteLine("Program Finished..."); Console.ReadKey(); }
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 KamaAcquisitionReadOnlyFile(string filename) { FileName = filename; ProcedureInformation = new ProcedureInformation(); SystemInformation = new SystemInformation(); PatientInformation = new Patient(); ECG = new ECGData(); EITs = new List <EITEntry>(); Events = new List <SystemEvent>(); Hdf5.Settings.LowerCaseNaming = true; Hdf5.Settings.DateTimeType = DateTimeType.UnixTimeMilliseconds; fileId = Hdf5.OpenFile(filename); }
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 ReadStructs() { string filename = Path.Combine(folder, "data", "testCompounds_WData2_WData3.H5"); try { var fileId = Hdf5.OpenFile(filename); Assert.IsTrue(fileId > 0); var cmpList = Hdf5.ReadCompounds <WData3>(fileId, "/test", "").ToArray(); Hdf5.CloseFile(fileId); CollectionAssert.AreEqual(wData2List, cmpList); } 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); } }
//[TestMethod] public void TestRead() { //string filename = @"D:\Data\9_pig.h5"; string filename = @"c:\kalpa\test.h5"; //string filename = @"d:\data\test2400.h5"; var fileId = Hdf5.OpenFile(filename); Stopwatch st = Stopwatch.StartNew(); var ds = Hdf5.ReadDatasetToArray <float>(fileId, "/eit/d1/voltages.im"); st.Stop(); Console.WriteLine(ds.result.Length); Console.WriteLine("read time im: " + st.ElapsedMilliseconds); st.Restart(); ds = Hdf5.ReadDatasetToArray <float>(fileId, "/eit/d1/voltages.re"); st.Stop(); Console.WriteLine(ds.result.Length); Console.WriteLine("read time re: " + st.ElapsedMilliseconds); Hdf5.CloseFile(fileId); }
public void WriteAndReadOneAsciiString() { try { string test = "This is a test string"; string filename = Path.Combine(folder, "testOneString.H5"); var fileId = Hdf5.CreateFile(filename); Hdf5.WriteAsciiString(fileId, "/test", test); Assert.IsTrue(Hdf5.CloseFile(fileId) == 0); fileId = Hdf5.OpenFile(filename); string readStr = Hdf5.ReadAsciiString(fileId, "/test"); Assert.IsTrue(test == readStr); Assert.IsTrue(Hdf5.CloseFile(fileId) == 0); } catch (Exception ex) { CreateExceptionAssert(ex); } }
public void WriteAndReadObjectWithHdf5Attributes() { string groupName = "anObject"; 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, groupName); Assert.IsTrue(Hdf5.CloseFile(fileId) == 0); } catch (Exception ex) { CreateExceptionAssert(ex); } var OpenFileId = Hdf5.OpenFile(filename); var data = Hdf5.ReadObject <AttributeClass>(OpenFileId, groupName); var att = Hdf5.ReadAttributes <AttributeClass>(OpenFileId, groupName); }
public void WriteOverrideAndReadObjectWithHdf5Attributes() { string groupName = "simpleObject"; string filename = Path.Combine(folder, "testSimpleHdf5Attribute.H5"); var attObject = new AttributeSimpleClass(); attObject.SetStringProperty("new value"); try { var fileId = Hdf5.CreateFile(filename); Assert.IsTrue(fileId > 0); Hdf5.WriteObject(fileId, attObject, groupName); Assert.IsTrue(Hdf5.CloseFile(fileId) == 0); } catch (Exception ex) { CreateExceptionAssert(ex); } var openFileId = Hdf5.OpenFile(filename); var data = Hdf5.ReadObject <AttributeSimpleClass>(openFileId, groupName); Hdf5.CloseFile(openFileId); Assert.IsTrue(data.Equals(attObject)); attObject.SetStringProperty("third"); attObject.datetime = DateTime.Now; openFileId = Hdf5.OpenFile(filename); Hdf5.WriteObject(openFileId, attObject, groupName); Assert.IsTrue(Hdf5.CloseFile(openFileId) == 0); openFileId = Hdf5.OpenFile(filename); data = Hdf5.ReadObject <AttributeSimpleClass>(openFileId, groupName); Hdf5.CloseFile(openFileId); Assert.IsTrue(data.Equals(attObject)); File.Delete(filename); }
public void OverrideDataset() { string filename1 = "overridedataset1.h5"; long id = WriteDataset(filename1); FileInfo fi = new FileInfo(filename1); var l1 = fi.Length; Hdf5.CloseFile(id); File.Delete(filename1); string filename = "overridedataset.h5"; Hdf5.Settings.EnableErrorReporting(true); Hdf5.Settings.OverrideExistingData = true; 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); for (int i = 0; i < 10; i++) { blah[4] = i + i; Hdf5.WriteDatasetFromArray <int>(tef2, "blah", blah); } var(success, result) = Hdf5.ReadDataset <int>(tef2, "blah"); Assert.IsTrue(success); Assert.IsTrue(result.Cast <int>().SequenceEqual(blah)); FileInfo fi2 = new FileInfo(filename); var l2 = fi.Length; Hdf5.CloseFile(tef2); File.Delete(filename); Assert.IsTrue(l1 == l2); }
public void WriteAndReadStructsWithArray() { string filename = Path.Combine(folder, "testArrayCompounds.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", responseList, attributes); 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); } }
//[TestMethod] public void ReadTable() { Hdf5.Settings.LowerCaseNaming = false; Hdf5.Settings.EnableErrorReporting(true); Hdf5Utils.LogWarning = (s) => Errors.Add(s); Hdf5Utils.LogError = (s) => Errors.Add(s); string filename = @"D:\h5\d.hdf5"; long fileId = -1; try { fileId = Hdf5.OpenFile(filename, true); var groupName = "/MODEL_STAGE[1]/RESULTS/ON_NODES/DISPLACEMENT/DATA"; var groupId = Hdf5.CreateOrOpenGroup(fileId, groupName); TabularData <double> tableOfData = Hdf5.Read2DTable <double>(groupId, "STEP_0"); } finally { if (fileId > 0) { Hdf5.CloseFile(fileId); } } }
public void WriteAndReadUserSystemEvents() { string filename = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "WriteAndReadUserSystemEvents.H5"); var userEventsData = new List <UserEventRecord>() { new UserEventRecord("research1", "button1", "none", DateTimeOffset.Now.ToUnixTimeMilliseconds()), new UserEventRecord("research1", "button2", "none", DateTimeOffset.Now.ToUnixTimeMilliseconds() + 10) }; var fileId = Hdf5.CreateFile(filename); Hdf5UserEvents hdf5UserEvents = new Hdf5UserEvents(userEventsData); Assert.IsTrue(fileId > 0); var status = Hdf5.WriteObject(fileId, hdf5UserEvents, "test"); Hdf5.CloseFile(fileId); fileId = Hdf5.OpenFile(filename); Assert.IsTrue(fileId > 0); var objWithStructs = Hdf5.ReadObject <Hdf5UserEvents>(fileId, "test"); CollectionAssert.AreEqual(hdf5UserEvents.Events, objWithStructs.Events); Hdf5.CloseFile(fileId); }