转载:http://apps.hi.baidu.com/share/detail/24119344
hdf (hierarchical data format) 中文可译为分级数据格式,卫星资料多用这种形势存储。
%----step one---------open file
s='D:\parter\ben\QS_XWGRD3_2006192.20070991754';
sd_id = hdfsd('start',s,'read');
% sd_id is the identifier of SD file
%read-read access ,create-create a new access ,rdwr or write-read
and write
�cess
%----step two---------find the information
[ndatasets,nglobal_attr,status] = hdfsd('fileinfo',sd_id);
% HDF4 file contains ndatasets data sets and nglobal_attr global
attribute.
% status 表示状态 vaule=-1 denote unsuccessful
%----step three--------get an file attibutes
% for
i=0:nglobal_attr-1;
% [attr,
status] = hdfsd('readattr', sd_id, i);
% 知道索引号,求其对应的全局变量名(文件)
% end
%sds_idx1=hdfsd('findattr',sd_id,'date_of_average')
%---得到(findattr)sd_sds的sttr属性的文件号-------
%[date_ave,status]=hdfsd('readattr',sd_id,sds_idx1)
%---打开(readattr)sds_idx1对应的属性-----------------
�cha=date_ave(7:15);
%scale
%size(double(scale))
%-------------step
four,five.six,seven----------------------------------
for
i=0:ndatasets-1
%---i相当于sds_idx-------
%for
i=0:0
sds_id = hdfsd('select',sd_id,i);% To select a data set (i)
% sds_id is HDF SD data set identifiers
[scale, status] = hdfsd('readattr', sds_id, 0);
%读对应变量的属性(scale)
[offset,status]=hdfsd('readattr', sds_id, 2);
%读对应变量的属性(offest),订正值
%-get data set information----------
[ds_name, ds_ndims, ds_dims, ds_type, ds_atts, stat]=...
hdfsd('getinfo',sds_id);
%----------------数组初始化-------------------
ds_start =
zeros(1,ds_ndims); % Creates the vector [0 0]
ds_stride =
[];
ds_edges =
ds_dims;
%----------------read data set-----------------------
[ds_data,
status]
=hdfsd('readdata',sds_id,ds_start,ds_stride,ds_edges);
%----------------转换量级和订正
ds_data=double(scale)*double(ds_data)-double(offset) ;
%---------------文件输出----------------------
s='D:\parter\ben\';
s=[s ds_name
'.dat'];
fid=fopen(s,'w');
fwrite(fid,ds_data,'float32');
fclose(fid);
stat =
hdfsd('endaccess',sds_id); %
close data set
end
hdfsd('end',sd_id); % close
file
综合上述,主要由以下几个函数关于hdfsd函数
1。'readattr' 读其对应值(文件(sd_id),数据(sds_id))的属性
2。 select 返回一个整数值sds_id =
hdfsd('select',sd_id,i); 选择数据
3。'readdata'
读数据hdfsd('readdata',sds_id,ds_start,ds_stride,ds_edges);
4。'getinfo'获得数据的信息
5。'fileinfo'获得文件信息
6。hdfsd('start',s,'read'); 获得一个读hdf文件的文件号
加载中,请稍候......