public Dictionary <string, string> TryReadDataTable(string datasetName) { Dictionary <string, string> result = null; var subDsDic = ds.GetSubDatasets(); if (subDsDic.Count > 0) { H5ID h5FileId = H5F.open(fileName, H5F.ACC_RDONLY); H5ID datasetId = H5D.open(h5FileId, datasetName); H5ID typeId = H5D.get_type(datasetId); H5ID spaceId = H5D.get_space(datasetId); if (H5T.get_class(typeId) == H5T.class_t.COMPOUND) { int numCount = H5T.get_nmembers(typeId); var size = H5T.get_size(typeId); byte[] buffer = new byte[size.ToInt32()]; GCHandle hnd = GCHandle.Alloc(buffer, GCHandleType.Pinned); int ndims = H5S.get_simple_extent_ndims(spaceId); if (ndims == 1) { result = new Dictionary <string, string>(); H5D.read(datasetId, typeId, H5S.ALL, H5S.ALL, H5P.DEFAULT, hnd.AddrOfPinnedObject()); for (uint i = 0; i < numCount; i++) { string name = Marshal.PtrToStringAnsi(H5T.get_member_name(typeId, i)); int offset = H5T.get_member_offset(typeId, i).ToInt32(); H5ID subTypeId = H5T.get_member_type(typeId, i); H5T.class_t typeClass = H5T.get_member_class(typeId, i); string value = ReadBuffer(buffer, offset, typeClass, subTypeId); result.Add(name, value); H5T.close(subTypeId); } } hnd.Free(); } if (spaceId != 0) { H5S.close(spaceId); } if (typeId != 0) { H5T.close(typeId); } if (datasetId != 0) { H5D.close(datasetId); } if (h5FileId != 0) { H5F.close(h5FileId); } } return(result); }
static void Main_Read(string[] args) { int DATA_ARRAY_LENGTH = 5; //var h5 = H5F.open(@"E:\HDF5\HDF5DotNet-src\examples\CSharpExample\CSharpExample1\table.h5", H5F.ACC_RDONLY); //var h5 = H5F.open(@"D:\test.h5", H5F.ACC_RDONLY); //var h5 = H5F.open(@"E:\HDF5\Hdf5DotnetTools-master\ToolTest\bin\Debug\table.h5", H5F.ACC_RDONLY); var h5 = H5F.open(@"E:\HDF5\test_gzip.h5", H5F.ACC_RDONLY); var dataset = H5D.open(h5, "trans_detail/20160929"); var spaceid = H5D.get_space(dataset); var npoints = H5S.get_simple_extent_npoints(spaceid); //var dims = H5S.get_simple_extent_dims(spaceid); int rank = H5S.get_simple_extent_ndims(spaceid); // 是不是不能用自己的type var dtype = H5D.get_type(dataset); var dtcls = H5T.get_class(dtype); var size = H5T.get_size(dtype); var sz = Marshal.SizeOf(typeof(ComType)); var dtype_n = H5T.get_nmembers(dtype); for (uint i = 0; i < dtype_n; ++i) { var x = H5T.get_member_name(dtype, i); var x4 = Marshal.PtrToStringAnsi(x); var y = H5T.get_member_type(dtype, i); var z = H5T.get_class(y); var x1 = H5T.get_member_offset(dtype, i); var x3 = H5T.get_size(y); Console.WriteLine(x4); Console.WriteLine(z); Console.WriteLine(x1); //var x2 = Marshal.OffsetOf(typeof(ComType), x4).ToInt32(); //Console.WriteLine(x2); Console.WriteLine(x3); } int ss1 = Marshal.SizeOf(typeof(ComType)); IntPtr p = Marshal.AllocHGlobal(ss1 * 11); H5D.read(dataset, dtype, H5S.ALL, H5S.ALL, H5P.DEFAULT, p); var s = Marshal.PtrToStructure(p, typeof(ComType)); Console.WriteLine(s); var s2 = Marshal.PtrToStructure(p + ss1, typeof(ComType)); Console.WriteLine(s2); var s3 = Marshal.PtrToStructure(p + ss1 * 4, typeof(ComType)); Console.WriteLine(s3); var s4 = Marshal.PtrToStructure(p + ss1 * 5, typeof(ComType)); Console.WriteLine(s4); var s6 = Marshal.PtrToStructure(p + ss1 * 10, typeof(ComType)); Console.WriteLine(s6); }