using System; using System.Collections.Generic; using System.Linq; using System.Text; using HDF5DotNet; using System.Collections; namespace ReadHDF5{ //得到hdf5数据集的数据,主要为 int 数组, float 、 double 数组保存 class GetHdf5DataSet{region 获取数据集数据,主要包含 int , float ,doubleprivate Array _dataSet; public Array get_Hdf5DataSet{ get { return _dataSet;}}/// /// 得到 int 类型的数据集/// /// 文件名称,包含路径/// 数据集所在的群组/// 数据集的名称/// 输出的结果数据集 public void hdf5_getDataSetstring fileName, string GroupName, string DsName, int [, ,] dataSet{H5FileId fileId H5F.openfileName, H5F.OpenMode.ACC_RDONLY;H5GroupId groupId H5G.openfileId, GroupName;H5DataSetId dataSetId H5D.opengroupId, DsName ;H5DataTypeId tid0 H5D.getTypedataSetId; H5DataTypeId tid1 H5T.enumCreatetid0;// new H5DataTypeIdH5T.H5Type.NATIVE_INT;//数据类型// Read the array backH5D.readdataSetId, tid1, new H5ArraydataSet;//dataSetId, tid1, new H5ArrayvlReadBackArray;H5D.closedataSetId;H5G.closegroupId;H5F.closefileId;_dataSet dataSet;}/// /// 得到 float 类型的数据集/// /// 文件名称,包含路径/// 数据集所在的群组/// 数据集的名称/// 输出的 float []结果数据集 public void hdf5_getDataSetstring fileName, string GroupName, string DsName, float [, ,] dataSet{H5FileId fileId H5F.openfileName, H5F.OpenMode.ACC_RDONLY;H5GroupId groupId H5G.openfileId, GroupName;H5DataSetId dataSetId H5D.opengroupId, DsName ;H5DataTypeId tid1 new H5DataTypeIdH5T.H5Type.NATIVE_FLOAT;// Read the array backH5D.readdataSetId, tid1, new H5ArraydataSet;//dataSetId, tid1, new H5ArrayvlReadBackArray;H5D.closedataSetId;H5G.closegroupId;H5F.closefileId;}/// /// 得到 double 类型的数据集 /// /// 文件名称,包含路径/// 数据集所在的群组/// 数据集的名称/// 输出的结果数据集 double [] public void hdf5_getDataSetstring fileName, string GroupName, string DsName, double [, ,] dataSet{H5FileId fileId H5F.openfileName, H5F.OpenMode.ACC_RDONLY;H5GroupId groupId H5G.openfileId, GroupName;H5DataSetId dataSetId H5D.opengroupId, DsName ;H5DataTypeId tid1 new H5DataTypeIdH5T.H5Type.NATIVE_DOUBLE;// Read the array backH5D.readdataSetId, tid1, new H5ArraydataSet;//dataSetId, tid1, new H5ArrayvlReadBackArray;H5D.closedataSetId;H5G.closegroupId;H5F.closefileId;}/// /// 得到 int 数据集/// /// 文件id/// 群组id/// 数据集id/// int 类型的数据集 public void hdf5_getDataSetH5FileId fileId, H5GroupId groupId, H5DataSetId dataSetId, int [, ,] dataSet{H5DataTypeId tid1 new H5DataTypeIdH5T.H5Type.NATIVE_INT;//数据类型// Read the array backH5D.readdataSetId, tid1, new H5ArraydataSet;//dataSetId, tid1, new H5ArrayvlReadBackArray;_dataSet dataSet;} /// /// 得到 float 数据集/// /// 文件id/// 群组id/// 数据集id/// float 类型的数据集 public void hdf5_getDataSetH5FileId fileId, H5GroupId groupId, H5DataSetId dataSetId, float [, ,] dataSet{H5DataTypeId tid1 new H5DataTypeIdH5T.H5Type.NATIVE_FLOAT;//数据类型// Read the array backH5D.readdataSetId, tid1, new H5ArraydataSet;//dataSetId, tid1, new H5ArrayvlReadBackArray;_dataSet dataSet;}/// /// 得到 double 数据集/// /// 文件id/// 群组id/// 数据集id/// double 类型的数据集 public void hdf5_getDataSetH5FileId fileId, H5GroupId groupId, H5DataSetId dataSetId, double [, ,] dataSet{H5DataTypeId tid1 new H5DataTypeIdH5T.H5Type.NATIVE_DOUBLE;//数据类型// Read the array backH5D.readdataSetId, tid1, new H5ArraydataSet;//dataSetId, tid1, new H5ArrayvlReadBackArray;_dataSet dataSet;}//---------------------------------------------------------------------------------------------------endregion/// /// 获取群组中所有的数据集名称/// /// 文件名/// 群组名/// public string [] getDatasetNamesstring filename, string GroupName{// filename “D\FY_data\FY3A_VIRRX_GBAL_L1_20090503_0240_1000M_MS.HDF“;H5FileId fileId H5F.openfilename, H5F.OpenMode.ACC_RDONLY;H5GroupId groupId H5G.openfileId, “/“; ulong num_objs H5G.getNumObjectsgroupId; int num Convert.ToInt32num_objs; string [] dataNames new string [num]; for int i 0; i /// 得到群组中所有属性字段名,Function used with H5A.iterate /// /// /// /// /// /// static H5IterationResult MyH5AFunctionH5AttributeId attributeId,String attributeName,H5AttributeInfo info,Object attributeNames{// Console.WriteLine“Iteration attribute is {0}“, attributeName;ArrayList nameList ArrayListattributeNames;nameList.AddattributeName;// Returning SUCCESS means that iteration should continue to the // next attribute if one exists. return H5IterationResult.SUCCESS;}/// /// 返回群组中所有的属性名称/// /// 群组id号/// public ArrayList getAttributeNamesH5ObjectWithAttributes dataSetId{H5AIterateDelegate attributeDelegate;attributeDelegate MyH5AFunction;ArrayList attributeNames new ArrayList; ulong position 0;H5A.iteratedataSetId, H5IndexType.CRT_ORDER,H5IterationOrder.INCREASING, ref position, attributeDelegate,objectattributeNames; return attributeNames;}//--------------------------------------------------endregionregion 获取属性值/// /// 得到属性值,不足,不能得到rank为的值,返回值也不好获取/// /// 可以为groupID,dataSetId/// public |
中级程序员
by: 我爱写代码 发表于:2022-06-18 15:38:20 顶(27) | 踩(25) 回复
积分
回复评论