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 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 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 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 WriteAndReadAttributes() { string filename = Path.Combine(folder, "testAttributes.H5"); int[] intValues = new[] { 1, 2 }; double dblValue = 1.1; string strValue = "test"; string[] strValues = new string[2] { "test", "another test" }; bool boolValue = true; DateTime dateValue = new DateTime(1969, 1, 12); var groupStr = "/test"; //string concatFunc(string x) => string.Concat(groupStr, "/", x); string intName = nameof(intValues); string dblName = nameof(dblValue); string strName = nameof(strValue); string strNames = nameof(strValues); string boolName = nameof(boolValue); string dateName = nameof(dateValue); try { var fileId = Hdf5.CreateFile(filename); Assert.IsTrue(fileId > 0); var groupId = Hdf5.CreateOrOpenGroup(fileId, groupStr); Hdf5.WriteAttributes <int>(groupId, intName, intValues); Hdf5.WriteAttribute(groupId, dblName, dblValue); Hdf5.WriteAttribute(groupId, strName, strValue); Hdf5.WriteAttributes <string>(groupId, strNames, strValues); Hdf5.WriteAttribute(groupId, boolName, boolValue); Hdf5.WriteAttribute(groupId, dateName, dateValue); H5G.close(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); IEnumerable <int> readInts = (int[])Hdf5.ReadAttributes <int>(groupId, intName).result; Assert.IsTrue(intValues.SequenceEqual(readInts)); double readDbl = Hdf5.ReadAttribute <double>(groupId, dblName); Assert.IsTrue(dblValue == readDbl); string readStr = Hdf5.ReadAttribute <string>(groupId, strName); Assert.IsTrue(strValue == readStr); IEnumerable <string> readStrs = (string[])Hdf5.ReadAttributes <string>(groupId, strNames).result; Assert.IsTrue(strValues.SequenceEqual(readStrs)); bool readBool = Hdf5.ReadAttribute <bool>(groupId, boolName); Assert.IsTrue(boolValue == readBool); DateTime readDate = Hdf5.ReadAttribute <DateTime>(groupId, dateName); Assert.IsTrue(dateValue == readDate); H5G.close(groupId); Hdf5.CloseFile(fileId); } catch (Exception ex) { CreateExceptionAssert(ex); } }