openEMS/matlab/ReadHDF5Mesh.m

60 lines
1.6 KiB
Matlab
Raw Normal View History

2010-04-05 21:16:52 +00:00
function hdf_mesh = ReadHDF5Mesh(file)
% function hdf_mesh = ReadHDF5Mesh(file)
%
% Get the raw mesh data stored in the hdf5 dump file created by openEMS
%
% returns:
% hdf_mesh.type (0-> cartesian, 1-> cylindrical mesh type)
% hdf_mesh.names (e.g. 'Mesh/y')
% hdf_mesh.lines (e.g. [0,1,2,3,4])
%
% openEMS matlab interface
% -----------------------
% author: Thorsten Liebig
2010-05-28 13:13:45 +00:00
%
% See also ReadHDF5FieldData
2010-04-05 21:16:52 +00:00
2010-10-02 19:04:28 +00:00
isOctave = exist('OCTAVE_VERSION','builtin') ~= 0;
if isOctave
hdf_mesh = ReadHDF5Mesh_octave(file);
return
end
2010-04-05 21:16:52 +00:00
info = hdf5info(file);
for n=1:numel(info.GroupHierarchy.Groups)
if strcmp(info.GroupHierarchy.Groups(n).Name,'/Mesh')
for m=1:numel(info.GroupHierarchy.Groups(n).Datasets)
names{m} = info.GroupHierarchy.Groups(n).Datasets(m).Name;
end
end
end
hdf_mesh.names = names;
for n=1:numel(names)
hdf_mesh.lines{n} = double(hdf5read(file,names{n}));
end
if (strcmp(names{1},'/Mesh/alpha'))
% alpha and rho are in the wrong order, flip to have rho, alpha, z
hdf_mesh.names(1:2) = fliplr(hdf_mesh.names(1:2));
hdf_mesh.lines(1:2) = fliplr(hdf_mesh.lines(1:2));
hdf_mesh.type=1;
return
end
hdf_mesh.type=0;
2010-10-02 19:04:28 +00:00
function hdf_mesh = ReadHDF5Mesh_octave(file)
hdf = load( '-hdf5', file );
hdf_mesh.names = fieldnames(hdf.Mesh);
hdf_mesh.type = 0; % cartesian mesh
for n=1:numel(hdf_mesh.names)
hdf_mesh.lines{n} = hdf.Mesh.(hdf_mesh.names{n});
hdf_mesh.names{n} = ['/Mesh/' hdf_mesh.names{n}];
if strcmp(hdf_mesh.names{n},'/Mesh/alpha')
hdf_mesh.type = 1; % cylindrical mesh
end
end