File: ReadHDF5FieldData.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 (119 lines) | stat: -rw-r--r-- 4,282 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
function hdf_fielddata = ReadHDF5FieldData(file)
% function hdf_fielddata = ReadHDF5FieldData(file)
%
% returns:
% % time domain data (if exist)
% hdf_fielddata.TD.time
% hdf_fielddata.TD.names
% hdf_fielddata.TD.values
% hdf_fielddata.TD.DataType (0 --> real value data)
%
% % frequency domain data (if exist)
% hdf_fielddata.FD.frequency
% hdf_fielddata.FD.values
% hdf_fielddata.FD.DataType (0 / 1 --> real / complex value data)
%
% example: values of timestep 12:
% hdf_fielddata.TD.values{12}: array (x,y,z,polarization)
%
% plot z-field component along y-direction for timestep 12:
% plot( hdf_fielddata.TD.values{12}(1,:,1,3) )
%
% openEMS matlab interface
% -----------------------
% author: Thorsten Liebig
%
% See also ReadHDF5Mesh ReadHDF5Dump

if isOctave
    hdf_fielddata = ReadHDF5FieldData_octave(file);
    return
end

info = hdf5info(file);
TD.names = {};
hdf_fielddata = [];

for n=1:numel(info.GroupHierarchy.Groups)
    if strcmp(info.GroupHierarchy.Groups(n).Name,'/FieldData')
        %found /FieldData, look for either TD or FD data
        for nGroup=1:numel(info.GroupHierarchy.Groups(n).Groups)
            %search and read TD data
            if strcmp(info.GroupHierarchy.Groups(n).Groups(nGroup).Name,'/FieldData/TD')
                for m=1:numel(info.GroupHierarchy.Groups(n).Groups(nGroup).Datasets)
                    TD.names{m} = info.GroupHierarchy.Groups(n).Groups(nGroup).Datasets(m).Name;
                    for a = 1:numel(info.GroupHierarchy.Groups(n).Groups(nGroup).Datasets(m).Attributes)
                        str = regexp(info.GroupHierarchy.Groups(n).Groups(nGroup).Datasets(m).Attributes(a).Name,'\w/*\w*','match');
                        TD.(str{end})(m) = double(info.GroupHierarchy.Groups(n).Groups(nGroup).Datasets(m).Attributes(a).Value);
                    end
                end
            end
        end
        
    end
end

if (numel(TD.names)>0)
    hdf_fielddata.TD=TD;
    hdf_fielddata.TD.DataType = 0; %real value data
    for n=1:numel(hdf_fielddata.TD.names)
        hdf_fielddata.TD.values{n} = double(hdf5read(file,hdf_fielddata.TD.names{n}));
    end
end

% extract FD data
try
    hdf_fielddata.FD.frequency = ReadHDF5Attribute(file,'/FieldData/FD','frequency');
catch err
%     disp(err)
    return
end

for n=1:numel(hdf_fielddata.FD.frequency)
    try
        hdf_fielddata.FD.values{n} = double(hdf5read(file,['/FieldData/FD/f' int2str(n-1) '_real']) + 1i*hdf5read(file,['/FieldData/FD/f' int2str(n-1) '_imag']));
        hdf_fielddata.FD.DataType = 1; %complex value data
    catch
        try
            hdf_fielddata.FD.values{n} = double(hdf5read(file,['/FieldData/FD/f' int2str(n-1)]));
            hdf_fielddata.FD.DataType = 0; %real value data
        catch
            error('openEMS:ReadHDF5FieldData','FD data invalid...')
        end
    end
end

function hdf_fielddata = ReadHDF5FieldData_octave(file)
hdf = load( '-hdf5', file );
if ~isfield(hdf,'FieldData')
    error('no field data found')
end
if isfield(hdf.FieldData,'TD')
    %read TD data
    hdf_fielddata_names = fieldnames(hdf.FieldData.TD);
    for n=1:numel(hdf_fielddata_names)
        hdf_fielddata.TD.values{n} = hdf.FieldData.TD.(hdf_fielddata_names{n});
        hdf_fielddata.TD.names{n} = ['/FieldData/TD/' hdf_fielddata_names{n}(2:end)];
        hdf_fielddata.TD.time(n) = ReadHDF5Attribute(file, hdf_fielddata.TD.names{n},'time');
    end
    hdf_fielddata.TD.DataType = 0; %real value data
end
if isfield(hdf.FieldData,'FD')
    %read FD data
    hdf_fielddata.FD.frequency = ReadHDF5Attribute(file,'/FieldData/FD/','frequency');
    try %try reading complex data
        for n=1:numel(hdf_fielddata.FD.frequency)
            hdf_fielddata.FD.values{n} = double(hdf.FieldData.FD.(['f' int2str(n-1) '_real']) +1i*hdf.FieldData.FD.(['f' int2str(n-1) '_imag']) );
        end
        hdf_fielddata.FD.DataType = 1; %complex value data
    catch
         try %try reading real value data
            for n=1:numel(hdf_fielddata.FD.frequency)
                hdf_fielddata.FD.values{n} = double(hdf.FieldData.FD.(['f' int2str(n-1)]));
            end
            hdf_fielddata.FD.DataType = 0; %real value data
         catch
             error('openEMS:ReadHDF5FieldData','FD data invalid...')
         end
    end
end