2010-04-05 21:16:52 +00:00
|
|
|
function hdf_mesh = ReadHDF5Mesh(file)
|
2010-04-24 14:43:22 +00:00
|
|
|
% function hdf_mesh = ReadHDF5Mesh(file)
|
|
|
|
%
|
2010-09-27 06:43:34 +00:00
|
|
|
% Get the raw mesh data stored in the hdf5 dump file created by openEMS
|
|
|
|
%
|
2010-04-24 14:43:22 +00:00
|
|
|
% returns:
|
2010-09-27 06:43:34 +00:00
|
|
|
% 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])
|
2010-04-24 14:43:22 +00:00
|
|
|
%
|
|
|
|
% 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)
|
2010-05-25 10:17:09 +00:00
|
|
|
hdf_mesh.lines{n} = double(hdf5read(file,names{n}));
|
2010-04-23 06:17:42 +00:00
|
|
|
end
|
|
|
|
|
2010-09-27 06:43:34 +00:00
|
|
|
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));
|
2010-04-23 06:17:42 +00:00
|
|
|
hdf_mesh.type=1;
|
2010-09-27 06:43:34 +00:00
|
|
|
return
|
|
|
|
end
|
2012-02-02 10:46:39 +00:00
|
|
|
if (strcmp(names{1},'/Mesh/phi'))
|
|
|
|
% reorder coordinates
|
|
|
|
hdf_mesh.names = hdf_mesh.names([2 3 1]);
|
|
|
|
hdf_mesh.lines = hdf_mesh.lines([2 3 1]);
|
|
|
|
hdf_mesh.type=2;
|
|
|
|
return
|
|
|
|
end
|
2010-09-27 06:43:34 +00:00
|
|
|
|
|
|
|
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
|
2012-02-02 10:46:39 +00:00
|
|
|
if strcmp(hdf_mesh.names{n},'/Mesh/phi')
|
|
|
|
hdf_mesh.type = 2; % cylindrical mesh
|
|
|
|
end
|
2010-10-02 19:04:28 +00:00
|
|
|
end
|
2012-01-16 12:30:50 +00:00
|
|
|
|
|
|
|
if (hdf_mesh.type==1)
|
|
|
|
% 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));
|
|
|
|
end
|
2012-02-02 10:46:39 +00:00
|
|
|
if (hdf_mesh.type==2)
|
|
|
|
% alpha and rho are in the wrong order, flip to have rho, alpha, z
|
|
|
|
hdf_mesh.names = hdf_mesh.names([2 3 1]);
|
|
|
|
hdf_mesh.lines = hdf_mesh.lines([2 3 1]);
|
|
|
|
end
|