Esempio n. 1
0
        // test that we can create an empty file and add matrices
        public static void CreateMatrixTest(string file)
        {
            int zones = 3;

            double[,] testblock;
            string[]       matrixNames = { "mat1", "mat2" };
            OmxWriteStream ws          = OmxFile.Create(file, zones, true);

            // NOTE: cannot create data type until after file stream is created
            H5DataTypeId matrixDataTypes = H5T.copy(H5T.H5Type.NATIVE_DOUBLE);

            for (int i = 0; i < matrixNames.Length; i++)
            {
                ws.AddMatrix(matrixNames[i], matrixDataTypes);
            }

            ws.Close();

            OmxReadStream rs = OmxFile.OpenReadOnly(file);

            for (int i = 0; i < matrixNames.Length; i++)
            {
                testblock = rs.GetMatrixBlock <double>(matrixNames[i], 0, 0, 1, 1);
            }

            Console.WriteLine("mat shape is {0},{1}", rs.Shape[0], rs.Shape[1]);
            Console.WriteLine("mat names are {0},{1}", rs.MatrixNames[0], rs.MatrixNames[1]);
            Console.WriteLine("mat data type: {0},{1}",
                              H5T.getClass(rs.GetMatrixDataType(matrixNames[0])),
                              H5T.getClass(rs.GetMatrixDataType(matrixNames[1])));
            rs.Close();
        }
Esempio n. 2
0
        // test that we can read/write with a created matrix tables
        public static void ReadWriteTablesTest(string testCSharp, string testMtx)
        {
            int zones = 200;

            //make a file and some data
            OmxWriteStream ws = OmxFile.Create(testCSharp, zones, true);

            double[,] MtxTest = new double[zones, zones];

            for (int i = 0; i < zones; i++)
            {
                for (int j = 0; j < zones; j++)
                {
                    MtxTest[i, j] = Convert.ToDouble(i + j);
                }
            }

            H5DataTypeId matrixTypeId = H5T.copy(H5T.H5Type.NATIVE_DOUBLE);

            ws.AddMatrix(testMtx, matrixTypeId);
            ws.SetMatrix <double>(testMtx, MtxTest);
            ws.Close();

            //now open the file again and read the data back in
            OmxReadStream rs = OmxFile.OpenReadOnly(testCSharp);

            double[,] omxTestRead = rs.GetMatrix <double>(testMtx);

            double testValue  = MtxTest[4, 4];
            double testValue2 = omxTestRead[4, 4];

            if (testValue == testValue2)
            {
                Console.WriteLine(" Value match success");
            }
            else
            {
                Console.WriteLine(" Value match failure");
            }
            rs.Close();
        }