From 138c094a4429c2a3782d989e51fd416d51fb055e Mon Sep 17 00:00:00 2001 From: Thorsten Liebig Date: Wed, 6 Feb 2013 16:45:09 +0100 Subject: [PATCH] ReadHDF5Dump: new sup-sampling for file reading Signed-off-by: Thorsten Liebig --- matlab/GetField_SubSampling.m | 54 +++++++++++++++++++++++++++++++++++ matlab/ReadHDF5Dump.m | 9 +++++- 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 matlab/GetField_SubSampling.m diff --git a/matlab/GetField_SubSampling.m b/matlab/GetField_SubSampling.m new file mode 100644 index 0000000..6a4572a --- /dev/null +++ b/matlab/GetField_SubSampling.m @@ -0,0 +1,54 @@ +function [field_i mesh_i] = GetField_SubSampling(field, mesh, subsampling, varargin) +% [field_i mesh_i] = GetField_SubSampling(field, mesh, subsampling, varargin) +% +% Get a sub-sampled field, e.g. read by ReadHDF5Dump +% +% sub-sampling e.g. skipping every second line in x/r direction: [2 1 1] +% +% openEMS matlab interface +% ----------------------- +% author: Thorsten Liebig +% +% See also ReadHDF5Dump ReadHDF5FieldData ReadHDF5Mesh + +if (~isnumeric(subsampling) || numel(subsampling)~=3) + error('openEMS:GetField_Interpolation: numLines for interpolation must be a vector...'); +end + +x = mesh.lines{1}; +y = mesh.lines{2}; +z = mesh.lines{3}; + +ss_idx{1} = 1:subsampling(1):numel(x); +ss_idx{2} = 1:subsampling(2):numel(y); +ss_idx{3} = 1:subsampling(3):numel(z); + +x_i = x(ss_idx{1}); +y_i = y(ss_idx{2}); +z_i = z(ss_idx{3}); + +field_i = field; +mesh_i = mesh; +mesh_i.lines{1} = x_i; +mesh_i.lines{2} = y_i; +mesh_i.lines{3} = z_i; + +if (isfield(field,'TD')) + field_i.TD = subsample_fields(field.TD,ss_idx); + field_i.TD.time = field.TD.time; + field_i.TD.names= field.TD.names; +end + +if (isfield(field,'FD')) + field_i.FD = subsample_fields(field.FD,ss_idx); + field_i.FD.frequency = field.FD.frequency; + field_i.FD.DataType = field.FD.DataType; +end + +return + +function field_i = subsample_fields(field, ss_idx) + +for n=1:numel(field.values) + field_i.values{n} = field.values{n}(ss_idx{1},ss_idx{2},ss_idx{3},:); +end diff --git a/matlab/ReadHDF5Dump.m b/matlab/ReadHDF5Dump.m index 7939e42..eb13c67 100644 --- a/matlab/ReadHDF5Dump.m +++ b/matlab/ReadHDF5Dump.m @@ -10,6 +10,7 @@ function [field mesh] = ReadHDF5Dump(file, varargin) % possible arguments: % 'Range' see GetField_Range % 'Interpolation' see GetField_Interpolation +% 'SubSampling' see GetField_SubSampling % 'Frequency' see GetField_TD2FD % 'CloseAlpha': 0 (default) / 1 % @@ -24,7 +25,7 @@ function [field mesh] = ReadHDF5Dump(file, varargin) % ----------------------- % author: Thorsten Liebig % -% See also ReadHDF5Mesh ReadHDF5FieldData GetField_Interpolation +% See also ReadHDF5Mesh ReadHDF5FieldData GetField_Interpolation GetField_SubSampling % GetField_TD2FD GetField_Range field = ReadHDF5FieldData(file); @@ -41,6 +42,12 @@ for n=1:2:(nargin-1) end end +for n=1:2:(nargin-1) + if (strcmp(varargin{n},'SubSampling')==1); + [field mesh] = GetField_SubSampling(field,mesh,varargin{n+1}); + end +end + for n=1:2:(nargin-1) if (strcmp(varargin{n},'Interpolation')==1); [field mesh] = GetField_Interpolation(field,mesh,varargin{n+1});