// test read/write row function public static void ReadWriteRowTest(string file, string matName) { OmxWriteStream ws = OmxFile.OpenReadWrite(file); Console.WriteLine("mat shape is {0},{1}", ws.Shape[0], ws.Shape[1]); H5DataTypeId dt = ws.GetMatrixDataType(matName); // blocks we are reading need to match the data type of the matrix var rowData = new double[ws.Shape[0]]; var rowData2 = new double[ws.Shape[0]]; rowData = ws.GetMatrixRow <double>(matName, 2); rowData[2] = rowData[2] + 1.0; ws.SetMatrixRow <double>(matName, 2, rowData); rowData2 = ws.GetMatrixRow <double>(matName, 2); if (rowData.Sum() == rowData2.Sum()) { Console.WriteLine("Row Read/Write successful"); } else { Console.WriteLine("Read/Write mismatch"); } ws.Close(); }
// test that we can store and retrieve index maps public static void MappingTest(string testCSharp, string testMtx) { //test mapping the data to a new set of ids OmxWriteStream ws = OmxFile.OpenReadWrite(testCSharp); int zones = (int)ws.Shape[0]; int[] testMap = new int[zones]; for (int i = 0; i < zones; i++) { testMap[i] = i + 2; } string mapName = "mapping"; H5DataTypeId mapData = H5T.copy(H5T.H5Type.NATIVE_INT); // create map ws.CreateMapping <int>(testMap, mapData, mapName); // get map data type H5DataTypeId returnedData = ws.GetMappingDataType(mapName); if (mapData.GetType().Equals(returnedData.GetType())) { Console.WriteLine("Mapping data match"); } else { Console.WriteLine("Mapping data MISMATCH"); } // read map and use it to read data from matrix int[] testReadMap = ws.GetMapping <int>(mapName); Console.WriteLine("value for map at 2 is {0}", testReadMap[2]); int offsetsize = Convert.ToInt32(zones) - 2; double[,] omxTestReadMap = ws.GetMatrixBlock <double>(testMtx, testReadMap[0], testReadMap[0], offsetsize, offsetsize); Console.WriteLine("Value for matrix at 4,4 is {0}", omxTestReadMap[4, 4]); ws.Close(); }