openEMS/matlab/ReadHDF5FieldData.m

90 lines
3.2 KiB
Matlab
Raw Normal View History

2010-04-05 21:16:52 +00:00
function hdf_fielddata = ReadHDF5FieldData(file)
% function hdf_fielddata = ReadHDF5FieldData(file)
%
% returns:
2010-05-28 13:13:45 +00:00
% hdf_fielddata.time
% hdf_fielddata.names
% hdf_fielddata.values
%
2010-05-28 13:13:45 +00:00
% example: values of timestep 12:
% hdf_fielddata.values{12}: array (x,y,z,polarization)
%
% plot z-field component along y-direction for timestep 12:
% plot( hdf_fielddata.values{12}(1,:,1,3) )
%
% openEMS matlab interface
% -----------------------
% author: Thorsten Liebig
2010-05-28 13:13:45 +00:00
%
% See also ReadHDF5Mesh ReadHDF5Dump
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_fielddata = ReadHDF5FieldData_octave(file);
return
end
2010-04-05 21:16:52 +00:00
info = hdf5info(file);
TD.names = {};
FD.names = {};
hdf_fielddata = [];
2010-04-05 21:16:52 +00:00
for n=1:numel(info.GroupHierarchy.Groups)
if strcmp(info.GroupHierarchy.Groups(n).Name,'/FieldData')
%found /FieldData, look for either TD or FD data
for nGroup=1:numel(info.GroupHierarchy.Groups(n).Groups)
%search and read TD data
if strcmp(info.GroupHierarchy.Groups(n).Groups(nGroup).Name,'/FieldData/TD')
for m=1:numel(info.GroupHierarchy.Groups(n).Groups(nGroup).Datasets)
TD.names{m} = info.GroupHierarchy.Groups(n).Groups(nGroup).Datasets(m).Name;
TD.time(m) = double(info.GroupHierarchy.Groups(n).Groups(nGroup).Datasets(m).Attributes.Value);
end
end
%search and read FD data
if strcmp(info.GroupHierarchy.Groups(n).Groups(nGroup).Name,'/FieldData/FD')
for m=1:numel(info.GroupHierarchy.Groups(n).Groups(nGroup).Datasets)
FD.names{m} = info.GroupHierarchy.Groups(n).Groups(nGroup).Datasets(m).Name;
FD.freq(m) = double(info.GroupHierarchy.Groups(n).Groups(nGroup).Datasets(m).Attributes.Value);
end
end
2010-04-05 21:16:52 +00:00
end
2010-04-05 21:16:52 +00:00
end
end
if (numel(TD.names)>0)
hdf_fielddata.TD.names=TD.names;
hdf_fielddata.TD.time=TD.time;
2011-01-02 10:28:03 +00:00
for n=1:numel(hdf_fielddata.TD.names)
hdf_fielddata.TD.values{n} = double(hdf5read(file,hdf_fielddata.TD.names{n}));
end
2010-10-02 19:04:28 +00:00
end
if (numel(FD.names)>0)
Nr_freq = numel(FD.names)
for n=1:Nr_freq
name = ['/FieldData/FD/f' int2str(n-1) '_real'];
ind = find(strcmp(FD.names,name));
if isempty(ind)
ind = find(strcmp(FD.names,['/FieldData/FD/f' int2str(n-1)]));
hdf_fielddata.FD.values{n} = double(hdf5read(file,FD.names{ind}));
hdf_fielddata.FD.freq(n) = FD.freq(ind);
else
hdf_fielddata.FD.values{n} = double(hdf5read(file,FD.names{ind}));
hdf_fielddata.FD.freq(n) = FD.freq(ind);
name = ['/FieldData/FD/f' int2str(n-1) '_imag'];
ind = find(strcmp(FD.names,name));
hdf_fielddata.FD.values{n} = hdf_fielddata.FD.values{n} + 1j*double(hdf5read(file,FD.names{ind}));
end
end
end
2010-10-02 19:04:28 +00:00
function hdf_fielddata = ReadHDF5FieldData_octave(file)
hdf = load( '-hdf5', file );
hdf_fielddata.names = fieldnames(hdf.FieldData);
for n=1:numel(hdf_fielddata.names)
hdf_fielddata.time(n) = str2double(hdf_fielddata.names{n}(2:end));
hdf_fielddata.values{n} = hdf.FieldData.(hdf_fielddata.names{n});
end