matlab: new ReadHDF5Attribute function to abstract hdf5 attribute reading
parent
ccdb47a4cb
commit
b3ca99ec56
|
@ -0,0 +1,33 @@
|
|||
function attr = ReadHDF5Attribute(file, groupname, attr_name)
|
||||
% attr = ReadHDF5Attribute(file, groupname, attr_name)
|
||||
%
|
||||
% internal function for openEMS to read hdf5 attributes
|
||||
%
|
||||
% See also: ReadHDF5ComplexData
|
||||
%
|
||||
% openEMS Matlab/Octave interface
|
||||
% -----------------------
|
||||
% author: Thorsten Liebig, 2012
|
||||
|
||||
|
||||
if isOctave
|
||||
if (exist('h5readatt_octave')==0)
|
||||
warning('openEMS:ReadHDF5Attribute','function "h5readatt_octave" not found, trying to run "setup"');
|
||||
try
|
||||
setup
|
||||
catch
|
||||
error('openEMS:ReadHDF5Attribute','running "setup" failed...');
|
||||
end
|
||||
end
|
||||
attr = double(h5readatt_octave(file,groupname,attr_name));
|
||||
else
|
||||
%check for different matlab versions
|
||||
if verLessThan('matlab','7.9')
|
||||
attr = double(hdf5read(file,[groupname '/' attr_name]));
|
||||
elseif verLessThan('matlab','7.12')
|
||||
attr = double(hdf5read(file,groupname,attr_name));
|
||||
else
|
||||
attr = double(h5readatt(file,groupname,attr_name));
|
||||
end
|
||||
|
||||
end
|
|
@ -61,7 +61,7 @@ end
|
|||
|
||||
% extract FD data
|
||||
try
|
||||
hdf_fielddata.FD.frequency = double(hdf5read(file,'/FieldData/FD','frequency'));
|
||||
hdf_fielddata.FD.frequency = ReadHDF5Attribute(file,'/FieldData/FD','frequency');
|
||||
catch err
|
||||
% disp(err)
|
||||
return
|
||||
|
@ -81,12 +81,12 @@ if isfield(hdf.FieldData,'TD')
|
|||
for n=1:numel(hdf_fielddata_names)
|
||||
hdf_fielddata.TD.values{n} = hdf.FieldData.TD.(hdf_fielddata_names{n});
|
||||
hdf_fielddata.TD.names{n} = ['/FieldData/TD/' hdf_fielddata_names{n}(2:end)];
|
||||
hdf_fielddata.TD.time(n) = h5readatt_octave(file, hdf_fielddata.TD.names{n},'time');
|
||||
hdf_fielddata.TD.time(n) = ReadHDF5Attribute(file, hdf_fielddata.TD.names{n},'time');
|
||||
end
|
||||
end
|
||||
if isfield(hdf.FieldData,'FD')
|
||||
%read FD data
|
||||
hdf_fielddata.FD.frequency = h5readatt_octave(file,'/FieldData/FD/','frequency');
|
||||
hdf_fielddata.FD.frequency = ReadHDF5Attribute(file,'/FieldData/FD/','frequency');
|
||||
for n=1:numel(hdf_fielddata.FD.frequency)
|
||||
hdf_fielddata.FD.values{n} = double(hdf.FieldData.FD.(['f' int2str(n-1) '_real']) +1i*hdf.FieldData.FD.(['f' int2str(n-1) '_imag']) );
|
||||
end
|
||||
|
|
|
@ -18,10 +18,12 @@ nf2ff.r = double(hdf_mesh.lines{1});
|
|||
nf2ff.theta = double(hdf_mesh.lines{2});
|
||||
nf2ff.phi = double(hdf_mesh.lines{3});
|
||||
|
||||
% read attributes
|
||||
nf2ff.freq = ReadHDF5Attribute(file,'/nf2ff','Frequency');
|
||||
nf2ff.Prad = ReadHDF5Attribute(file,'/nf2ff','Prad');
|
||||
nf2ff.Dmax = ReadHDF5Attribute(file,'/nf2ff','Dmax');
|
||||
|
||||
if isOctave
|
||||
nf2ff.freq = double(h5readatt_octave(file,'/nf2ff','Frequency'));
|
||||
nf2ff.Prad = double(h5readatt_octave(file,'/nf2ff','Prad'));
|
||||
nf2ff.Dmax = double(h5readatt_octave(file,'/nf2ff','Dmax'));
|
||||
hdf = load( '-hdf5', file );
|
||||
for n=1:numel(nf2ff.freq)
|
||||
nf2ff.E_theta{n} = double(hdf.nf2ff.E_theta.FD.(['f' int2str(n-1) '_real']) +1i*hdf.nf2ff.E_theta.FD.(['f' int2str(n-1) '_imag']) );
|
||||
|
@ -33,17 +35,6 @@ else
|
|||
% matlab compatibility to older versions
|
||||
if verLessThan('matlab','7.12')
|
||||
|
||||
% read attributes
|
||||
if verLessThan('matlab','7.9')
|
||||
nf2ff.freq = double(hdf5read(file,'/nf2ff/Frequency'));
|
||||
nf2ff.Prad = double(hdf5read(file,'/nf2ff/Prad'));
|
||||
nf2ff.Dmax = double(hdf5read(file,'/nf2ff/Dmax'));
|
||||
else
|
||||
nf2ff.freq = double(hdf5read(file,'/nf2ff','Frequency'));
|
||||
nf2ff.Prad = double(hdf5read(file,'/nf2ff','Prad'));
|
||||
nf2ff.Dmax = double(hdf5read(file,'/nf2ff','Dmax'));
|
||||
end
|
||||
|
||||
% read data
|
||||
for n=1:numel(nf2ff.freq)
|
||||
nf2ff.E_theta{n} = double(hdf5read(file,['/nf2ff/E_theta/FD/f' int2str(n-1) '_real']) + 1i*hdf5read(file,['/nf2ff/E_theta/FD/f' int2str(n-1) '_imag']));
|
||||
|
@ -54,11 +45,6 @@ else
|
|||
return
|
||||
end
|
||||
|
||||
% read attributes
|
||||
nf2ff.freq = double(h5readatt(file,'/nf2ff','Frequency'));
|
||||
nf2ff.Prad = double(h5readatt(file,'/nf2ff','Prad'));
|
||||
nf2ff.Dmax = double(h5readatt(file,'/nf2ff','Dmax'));
|
||||
|
||||
% read data
|
||||
for n=1:numel(nf2ff.freq)
|
||||
nf2ff.E_theta{n} = double(h5read(file,['/nf2ff/E_theta/FD/f' int2str(n-1) '_real']) + 1i*h5read(file,['/nf2ff/E_theta/FD/f' int2str(n-1) '_imag']));
|
||||
|
|
Loading…
Reference in New Issue