diff --git a/matlab/PlotHDF5FieldData.m b/matlab/PlotHDF5FieldData.m new file mode 100644 index 0000000..b26ca8b --- /dev/null +++ b/matlab/PlotHDF5FieldData.m @@ -0,0 +1,60 @@ +function PlotHDF5FieldData(file, PlotArgs) + +plane = PlotArgs.plane; +component = PlotArgs.component; + +if (isfield(PlotArgs,'pauseTime')) + pauseT = PlotArgs.pauseTime; +else + pauseT = 0.01; +end + +mesh = ReadHDF5Mesh(file); +fields = ReadHDF5FieldData(file); + +max_amp = 0; + +if (strcmp(plane,'zx')) + [X1 X2] = meshgrid(mesh.lines{3}, mesh.lines{1}); + + if (component>0) + for n=1:numel(fields.values) + Z{n} = squeeze(double(fields.values{n}(:,1,:,component))); + end + else + for n=1:numel(fields.values) + fx = squeeze(double(fields.values{n}(:,1,:,1))); + fy = squeeze(double(fields.values{n}(:,1,:,2))); + fz = squeeze(double(fields.values{n}(:,1,:,3))); + Z{n} = sqrt(fx.^2 + fy.^2 + fz.^2); + end + end +end + + + +for n=1:numel(Z) + amp = max(max(abs(Z{n}))); + if (amp>max_amp) + max_amp = amp; + end +end +if (max_amp==0) + disp('max found amplitude was 0 --> nothing to plot'); + return +end + +for n=1:numel(Z) + surf(X1,X2,Z{n}) + title(fields.names{n}); + + if (isfield(PlotArgs,'zlim')) + if ~ischar(PlotArgs.zlim) + zlim(PlotArgs.zlim); + elseif strcmp(PlotArgs.zlim,'auto') + zlim([-max_amp*(component>0) max_amp]); + end + end + + pause(pauseT) +end \ No newline at end of file diff --git a/matlab/ReadHDF5FieldData.m b/matlab/ReadHDF5FieldData.m new file mode 100644 index 0000000..0524a99 --- /dev/null +++ b/matlab/ReadHDF5FieldData.m @@ -0,0 +1,16 @@ +function hdf_fielddata = ReadHDF5FieldData(file) + +info = hdf5info(file); + +for n=1:numel(info.GroupHierarchy.Groups) + if strcmp(info.GroupHierarchy.Groups(n).Name,'/FieldData') + for m=1:numel(info.GroupHierarchy.Groups(n).Datasets) + names{m} = info.GroupHierarchy.Groups(n).Datasets(m).Name; + end + end +end + +hdf_fielddata.names = names; +for n=1:numel(names) + hdf_fielddata.values{n} = hdf5read(file,names{n}); +end \ No newline at end of file diff --git a/matlab/ReadHDF5Mesh.m b/matlab/ReadHDF5Mesh.m new file mode 100644 index 0000000..472b94b --- /dev/null +++ b/matlab/ReadHDF5Mesh.m @@ -0,0 +1,16 @@ +function hdf_mesh = ReadHDF5Mesh(file) + +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) + hdf_mesh.lines{n} = hdf5read(file,names{n}); +end \ No newline at end of file diff --git a/matlab/examples/PlaneWave.m b/matlab/examples/PlaneWave.m index 3717ec7..2e3259b 100644 --- a/matlab/examples/PlaneWave.m +++ b/matlab/examples/PlaneWave.m @@ -72,3 +72,11 @@ disp(command); system(command) cd(savePath); +% plotting +PlotArgs.plane='zx'; +PlotArgs.pauseTime=0.01; +PlotArgs.component=1; +PlotArgs.zlim='auto'; + +PlotHDF5FieldData('tmp/Ht_.h5',PlotArgs) +