汪帮主卫星遥感空间分享 http://blog.sciencenet.cn/u/zjwang 湖北鄂州人,2011年博士毕业于吉林大学。现从事卫星遥感技术工作。

博文

基于MATLAB创建HDF文件及向存在HDF中追加数据

已有 10687 次阅读 2010-9-19 18:39 |个人分类:计算程序|系统分类:科研笔记

下面的例子展示了如何新建一个HDF文件并写入数据,及打开已关闭的HDF文件再向其追加数据。
本例测试于Linux(Ubuntu 10.04)系统,MATLAB版本为2009b.Unix。

%------------------------------------------
% the program example demonstrates the process that create a HDF file and wirte some data set into it, furthermore, the steps that how to reopen the created HDF file and add some data set into it are also illustrated.
% written by WANG Zijun
% Jilin University, Email: wzj08@mails.jlu.edu.cn
%------------------------------------------

% process 1
%% create a hdf file and write two data set

% create a new HDF file named sat_atmo.hdf in current directory
sdId = hdfsd('start','sat_atmo.hdf','create');
% in my example the lat_sat is a 14*22 array
% lat_sat = ...
% define a scientific data set
dsName = 'lat_sat';
dsType = 'double';
dsRank = ndims(lat_sat);
dsDims = fliplr(size(lat_sat));
% and create it
sdsId = hdfsd('create', sdId, dsName, dsType,dsRank, dsDims);
% define the data set range
dsStart = zeros(1, ndims(lat_sat));
dsStride =[];
dsEdges = fliplr(size(lat_sat));
% and write the data set lat_sat into the HDF file
stat = hdfsd('writedata', sdsId, dsStart, dsStride, dsEdges, lat_sat);

% Add another data set lon_sat into the HDF file
dsName = 'lon_sat';
dsType = 'double';
dsRank = ndims(lon_sat);
dsDims = fliplr(size(lon_sat));
sdsId = hdfsd('create', sdId, dsName, dsType,dsRank, dsDims);

dsStart = zeros(1, ndims(lon_sat));
dsStride =[];
dsEdges = fliplr(size(lon_sat));
stat = hdfsd('writedata', sdsId, dsStart, dsStride, dsEdges, lon_sat);

% terminate the file access and close the file
stat = hdfsd('endaccess', sdsId);
stat = hdfsd('end', sdId)
hdfml('closeall');


% process 2
%% reopen the hdf file and add a data set
% in our example the wavelength is 14 *3 array
% wl = ...
sdId = hdfsd('start', 'sat_atmo.hdf', 'rdwr');
dsName = 'wavelegnth';
dsType = 'double';
dsRank = ndims(wl);
dsDims = fliplr(size(wl));
sdsId = hdfsd('create', sdId, dsName, dsType, dsRank, dsDims);
dsStart = zeros(1, ndims(wl));
dsStride = [];
dsEdges = fliplr(size(wl));
stat = hdfsd('writedata', sdsId, dsStart, dsStride, dsEdges, wl);

stat = hdfsd('endaccess', sdsId);
stat = hdfsd('end', sdId)

hdfml('closeall');


https://wap.sciencenet.cn/blog-43777-364662.html

上一篇:CWzjWAData类:c++数组与MATLAB数组相互转换
下一篇:基于MATLAB创建HDF之Vgroup及向存在Vgroup中追加数据
收藏 IP: .*| 热度|

0

发表评论 评论 (1 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-11-10 07:11

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部