用C语言对HDF文件进行操作,包括文件打开、数据集读取、属性读取、空间维度获取、数据压缩、属性和数据写入文件等操作。
以三维数据读写为例
打开,读取空间属性、维度,数据集属性,文件属性,数据集的数据;
//写入txt文件(动态定义数组——用指针),写入DAT文件(可以用ENVI打开查看图像),写入HDF文件
写入HDF文件属性、数据属性、空间属性,数据压缩。
hid_t file_id,space_id,dset_id;
hsize_t dims[3]={0,0,0};
int ndims=0;
int status;
int col = 0;
int row =0;
int high=0;
char FileName[200];
char OutFileName[200];
int N=0;
int i,j,k;
memset(FileName,0,sizeof(FileName));
memset(OutFileName,0,sizeof(OutFileName));
strcpy(FileName,"C:\\Users\\hanss\\Desktop\\FY3B_MERSI_GBAL_L1_20170301_0000_1000M_ MS.HDF");
strcpy(OutFileName,"C:\\Users\\hanss\\Desktop\\FY3B.HDF");
unsignedint* dset=newunsignedint[row * col*high];
memset(dset,0,sizeof(unsignedint)* row * col*high);
一、打开HDF文件并读取相关数据信息
1、打开HDF文件
file_id = H5Fopen(FileName, H5F_ACC_RDONLY, H5P_DEFAULT);
2、打开数据集
dset_id = H5Dopen(file_id,"EV_1KM_RefSB",H5P_DEFAULT);
3、获取空间地址
space_id = H5Dget_space(dset_id);
4、获取空间维度信息