%------------------------------------------ % 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);