some first matlab hdf5 read/plot
This commit is contained in:
parent
924f0a6d40
commit
7d7e757923
60
matlab/PlotHDF5FieldData.m
Normal file
60
matlab/PlotHDF5FieldData.m
Normal file
@ -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
|
16
matlab/ReadHDF5FieldData.m
Normal file
16
matlab/ReadHDF5FieldData.m
Normal file
@ -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
|
16
matlab/ReadHDF5Mesh.m
Normal file
16
matlab/ReadHDF5Mesh.m
Normal file
@ -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
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user