|||
下面的两个例子,
1,展示了如何往HDF文件中新建一个Vgroup并加入数据,
2,展示了如何往Vgroup中追加数据
process 1
%% insert a Vgroup to a exist HDF file
% open a hdf file
% written by WANG Zijun, 2010.09.20
% Jilin University, Email: wzj08@mails.jlu.edu.cn
fId = hdfh('open', 'LimbRad.hdf','rdwr', 0);
% init Vgroup and SD Interfaces
stat = hdfv('start', fId);
sdId = hdfsd('start', 'LimbRad.hdf', 'write');
%create a Vgroup and SDS
sdsId = hdfsd('create', sdId, 'lat_sat', 'double', 2, [21 14]);
stat = hdfsd('writedata', sdsId, [0 0], [], [21 14], lat_sat);
vgId = hdfv('attach', fId, -1, 'w');
stat = hdfv('setname', vgId, 'SatGeom');
stat = hdfv('setclass', vgId, 'class1');
% insert SDS in Vgroup
sRef = hdfsd('idtoref', sdsId);
stat = hdfv('addtagref', vgId, 720 , sRef);
stat = hdfsd('endaccess', sdsId);
stat = hdfsd('end', sdId);
% detach Vgroup, close Vgroup interface and file
stat = hdfv('detach', vgId);
stat = hdfv('end', fId);
stat = hdfh('close', fId);
hdfml('closeall');
process 2
%% reopen a hdf and insert SDS to a Vgroup
% open a hdf file
fId = hdfh('open', 'LimbRad.hdf','rdwr', 0);
% init Vgroup and SD Interfaces
stat = hdfv('start', fId);
sdId = hdfsd('start', 'LimbRad.hdf', 'write');
%create a SDS
sdsId = hdfsd('create', sdId, 'lon_sat', 'double', 2, [21 14]);
stat = hdfsd('writedata', sdsId, [0 0], [], [21 14], lon_sat);
%get the reference number of the target Vgroup
vgRef = hdfv('find', fId, 'SatGeom');
% Attach to the target vGroup
vgId = hdfv('attach', fId, vgRef, 'w');
% insert SDS to Vgroup
sRef = hdfsd('idtoref', sdsId);
stat = hdfv('addtagref', vgId, 720 , sRef);
stat = hdfsd('endaccess', sdsId);
stat = hdfsd('end', sdId);
% detach Vgroup, close Vgroup interface and file
stat = hdfv('detach', vgId);
stat = hdfv('end', fId);
stat = hdfh('close', fId);
hdfml('closeall');
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-12-26 23:40
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社