File: PlotHDF5FieldData.m

package info (click to toggle)
openems 0.0.35+dfsg.1-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 6,288 kB
  • sloc: cpp: 40,259; yacc: 580; lex: 350; makefile: 258; sh: 169; ruby: 19
file content (94 lines) | stat: -rw-r--r-- 2,283 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
function PlotHDF5FieldData(file, PlotArgs)
% function PlotHDF5FieldData(file, PlotArgs)
%
% e.g.
% PlotArgs.slice = {0 [10 20] 0};
% PlotArgs.pauseTime=0.01;
% PlotArgs.component=2;
% PlotArgs.Limit = 'auto';
% 
% PlotHDF5FieldData('tmp/Et.h5',PlotArgs)
%
% openEMS matlab interface
% -----------------------
% author: Thorsten Liebig

component = PlotArgs.component;

if (isfield(PlotArgs,'pauseTime'))
    pauseT = PlotArgs.pauseTime;
else
    pauseT = 0.01;
end

mesh = ReadHDF5Mesh(file);
fields = ReadHDF5FieldData(file);

if (mesh.type==0)
    % cartesian mesh
    [X Y Z] = meshgrid(mesh.lines{1},mesh.lines{2},mesh.lines{3});
    for n=1:numel(fields.TD.values)
        % since Matlab 7.1SP3 the field needs to be reordered
        fields.TD.values{n} = permute(fields.TD.values{n},[2 1 3 4]); % reorder: y,x,z (or y,x)
    end
else
    disp(['PlotHDF5FieldData:: Error: unknown mesh type ' num2str(mesh.type)]);
end

max_amp = 0;

if (component>0)
    for n=1:numel(fields.TD.values)
        Field{n} = fields.TD.values{n}(:,:,:,component);
    end
else 
    for n=1:numel(fields.TD.values)
        fx = fields.TD.values{n}(:,:,:,1);
        fy = fields.TD.values{n}(:,:,:,2);
        fz = fields.TD.values{n}(:,:,:,3);
        Field{n} = sqrt(fx.^2 + fy.^2 + fz.^2);
    end        
end

for n=1:numel(Field)
    amp = max(max(max(abs(Field{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(Field)
    if size(Field{n},3) > 1
        % Field is a volume
        hsurfaces = slice(X,Y,Z, Field{n} , PlotArgs.slice{:});
        set(hsurfaces,'FaceColor','interp','EdgeColor','none');
    else
        % Field is already a 2D cut
        pcolor(X,Y,Field{n});
        shading( 'interp' );
        xlabel( 'x' );
        ylabel( 'y' );
    end
    title(fields.TD.names{n});
    %view(3)
    axis equal
    if (isfield(PlotArgs,'Limit'))
        if ~ischar(PlotArgs.Limit)
            caxis(PlotArgs.Limit);
        elseif strcmp(PlotArgs.Limit,'auto')    
            if (component>0)
                caxis([-max_amp,max_amp]);
            else
                caxis([0,max_amp]);
            end
        end
    end
    
    drawnow
    pause(pauseT)
end