2011-12-22 12:48:46 +00:00
|
|
|
function ConvertHDF5_VTK(hdf_file, vtk_prefix, varargin)
|
|
|
|
% ConvertHDF5_VTK(hdf_file, vtk_prefix, varargin)
|
|
|
|
%
|
|
|
|
% Convert openEMS field data stored in the given hdf5 file to a vtk file.
|
|
|
|
%
|
|
|
|
% arguments:
|
|
|
|
% hdf_file: source hdf5 file
|
|
|
|
% vtk_prefix: output vtk files prefix
|
|
|
|
%
|
|
|
|
% optional arguments:
|
|
|
|
% 'TD_Dump': activate dump for time-domain data (default is off)
|
|
|
|
% 'FD_Dump': activate dump for frequency-domain data (default is on)
|
|
|
|
% 'NumPhase': number of phase to dump frequency domain data animation
|
|
|
|
% (default is 36 --> 10°)
|
2012-01-16 08:59:54 +00:00
|
|
|
% 'FieldName': field name written to vtk, e.g. 'E-Field'
|
2012-10-10 20:00:51 +00:00
|
|
|
% 'weight': field weighting
|
2011-12-22 12:48:46 +00:00
|
|
|
%
|
2019-05-19 20:09:04 +00:00
|
|
|
% for more optional augments have a look at ReadHDF5Dump
|
2012-11-06 14:55:41 +00:00
|
|
|
%
|
2011-12-22 12:48:46 +00:00
|
|
|
% example:
|
|
|
|
% % read time-domian data from hdf5, perform dft and dump as vtk
|
|
|
|
% ConvertHDF5_VTK('Et.h5','Ef','NumPhase',18,'Frequency',1e9)
|
|
|
|
%
|
|
|
|
% openEMS matlab interface
|
|
|
|
% -----------------------
|
|
|
|
% author: Thorsten Liebig
|
|
|
|
%
|
|
|
|
% See also ReadHDF5Dump Dump2VTK
|
|
|
|
|
|
|
|
do_FD_dump = 1;
|
|
|
|
do_TD_dump = 0;
|
|
|
|
phase_N = 36;
|
2012-10-10 20:00:51 +00:00
|
|
|
weight = 1;
|
2011-12-22 12:48:46 +00:00
|
|
|
|
2012-01-16 08:59:54 +00:00
|
|
|
fieldname = 'unknown';
|
|
|
|
|
2011-12-22 12:48:46 +00:00
|
|
|
for n=1:2:numel(varargin)
|
2012-01-16 08:59:54 +00:00
|
|
|
if (strcmp(varargin{n},'TD_Dump')==1);
|
|
|
|
do_TD_dump = varargin{n+1};
|
2012-12-12 13:45:26 +00:00
|
|
|
elseif (strcmp(varargin{n},'FD_Dump')==1);
|
2012-01-16 08:59:54 +00:00
|
|
|
do_FD_dump = varargin{n+1};
|
2012-12-12 13:45:26 +00:00
|
|
|
elseif (strcmp(varargin{n},'NumPhase')==1);
|
2012-01-16 08:59:54 +00:00
|
|
|
phase_N = varargin{n+1};
|
2012-12-12 13:45:26 +00:00
|
|
|
elseif (strcmp(varargin{n},'FieldName')==1);
|
2012-01-16 08:59:54 +00:00
|
|
|
fieldname = varargin{n+1};
|
2012-12-12 13:45:26 +00:00
|
|
|
elseif (strcmp(varargin{n},'weight')==1);
|
2012-10-10 20:00:51 +00:00
|
|
|
weight = varargin{n+1};
|
|
|
|
end
|
2011-12-22 12:48:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
[field mesh] = ReadHDF5Dump(hdf_file, varargin{:});
|
|
|
|
|
2012-01-16 08:59:54 +00:00
|
|
|
if ((do_TD_dump==0) && (do_FD_dump==0))
|
|
|
|
warning('openEMS:ConvertHDF5_VTK','FD and TD dump disabled, nothing to be done...');
|
|
|
|
end
|
|
|
|
|
2011-12-22 12:48:46 +00:00
|
|
|
if (do_FD_dump)
|
2012-01-16 08:59:54 +00:00
|
|
|
if (~isfield(field,'FD'))
|
|
|
|
warning('openEMS:ConvertHDF5_VTK','no FD data found skipping frequency domian vtk dump...');
|
|
|
|
else
|
2012-10-10 20:00:51 +00:00
|
|
|
%set weighting
|
|
|
|
if (numel(weight)~=numel(field.FD.frequency))
|
|
|
|
FD_weight = ones(size(field.FD.frequency))*weight(1);
|
|
|
|
else
|
|
|
|
FD_weight = weight;
|
|
|
|
end
|
2012-09-21 12:18:47 +00:00
|
|
|
if (field.FD.DataType==1) % dump complex value FD data
|
|
|
|
ph = linspace(0,360,phase_N+1);
|
|
|
|
ph = ph(1:end-1);
|
|
|
|
for n = 1:numel(field.FD.frequency)
|
|
|
|
for p = ph
|
|
|
|
filename = [vtk_prefix '_' num2str(field.FD.frequency(n)) '_' num2str(p,'%03d') '.vtk' ];
|
2012-10-10 20:00:51 +00:00
|
|
|
Dump2VTK(filename, real(FD_weight(n)*field.FD.values{n}*exp(1j*p*pi/180)), mesh, fieldname, varargin{:});
|
2012-09-21 12:18:47 +00:00
|
|
|
end
|
|
|
|
filename = [vtk_prefix '_' num2str(field.FD.frequency(n)) '_abs.vtk' ];
|
2012-10-10 20:00:51 +00:00
|
|
|
Dump2VTK(filename, abs(FD_weight(n)*field.FD.values{n}), mesh, fieldname, varargin{:});
|
2012-09-21 12:18:47 +00:00
|
|
|
filename = [vtk_prefix '_' num2str(field.FD.frequency(n)) '_ang.vtk' ];
|
2012-10-10 20:00:51 +00:00
|
|
|
Dump2VTK(filename, angle(FD_weight(n)*field.FD.values{n}), mesh, fieldname, varargin{:});
|
2012-09-21 12:18:47 +00:00
|
|
|
end
|
|
|
|
else % dump real value FD data
|
|
|
|
for n = 1:numel(field.FD.frequency)
|
|
|
|
filename = [vtk_prefix '_' num2str(field.FD.frequency(n)) '.vtk' ];
|
2012-10-10 20:00:51 +00:00
|
|
|
Dump2VTK(filename, real(FD_weight(n)*field.FD.values{n}), mesh, fieldname, varargin{:});
|
2012-01-16 08:59:54 +00:00
|
|
|
end
|
2011-12-22 12:48:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if (do_TD_dump)
|
2012-01-16 08:59:54 +00:00
|
|
|
if (~isfield(field,'TD'))
|
|
|
|
warning('openEMS:ConvertHDF5_VTK','no TD data found skipping time domian vtk dump...');
|
|
|
|
else
|
|
|
|
disp('dumping time domain data...')
|
|
|
|
acc = ['%0' int2str(ceil(log10(numel(field.TD.time)+1))) 'd'];
|
|
|
|
for n = 1:numel(field.TD.time)
|
|
|
|
filename = [vtk_prefix '_TD_' num2str(n,acc) '.vtk' ];
|
2012-10-10 20:00:51 +00:00
|
|
|
Dump2VTK(filename, abs(weight(1))*field.TD.values{n}, mesh, fieldname, varargin{:});
|
2012-01-16 08:59:54 +00:00
|
|
|
end
|
2011-12-22 12:48:46 +00:00
|
|
|
end
|
|
|
|
end
|