コード例 #1
0
        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);
            }
        }