[c#]代码库
using System;using System.Collections.Generic;using System.Linq;using System.Text;using HDF5DotNet;using System.Collections;namespace ReadHDF5{/** 2011.2.14 xyj* 数据集操作主要有在指定群组中获取所有的数据集名称,获取指定名称的数据集的数据* *///得到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/*“EV_Emissive“*/;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/*“EV_Emissive“*/;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/*“EV_Emissive“*/;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) 回复
积分
回复评论