File: WriteHDF5.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 (73 lines) | stat: -rw-r--r-- 2,465 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
function WriteHDF5(filename,hdf_fielddata,hdf_mesh)
% function WriteHDF5(filename,hdf_fielddata,hdf_mesh)
%
% input:
%   hdf_fielddata.time
%   hdf_fielddata.names
%   hdf_fielddata.values
%   hdf_mesh.type
%   hdf_mesh.names
%   hdf_mesh.lines
%
% openEMS matlab interface
% -----------------------
% (C) 2010 Sebastian Held <sebastian.held@uni-due.de>
% See also ReadHDF5FieldData ReadHDF5Mesh

isOctave = exist('OCTAVE_VERSION','builtin') ~= 0;
if isOctave
    WriteHDF5_octave(filename,hdf_fielddata,hdf_mesh);
    return
end

writemode = 'overwrite';
if isfield( hdf_fielddata, 'TD' )
    % this is a time domain data set
    time = hdf_fielddata.TD.time;
    for n=1:numel(time)
        name = ['/FieldData/TD/' int2str(n)];
        [details.Location, details.Name] = fileparts(name);
        attribute_details.AttachedTo = name;
        attribute_details.AttachType = 'dataset';
        attribute_details.Name = 'time';
        hdf5write( filename, details, hdf_fielddata.TD.values{n}, ...
                   attribute_details, time(n), ...
                   'WriteMode', writemode );
        writemode = 'append';
    end
end
if isfield( hdf_fielddata, 'FD' )
    % this is a frequency domain data set
    freq = hdf_fielddata.FD.frequency;
    for n=1:numel(freq)
        name = ['/FieldData/FD/f' int2str(n-1) '_real'];
        [details.Location, details.Name] = fileparts(name);
        hdf5write( filename, details, real(hdf_fielddata.FD.values{n}), ...
                   'WriteMode', writemode );
        name = ['/FieldData/FD/f' int2str(n-1) '_imag'];
        [details.Location, details.Name] = fileparts(name);
        hdf5write( filename, details, imag(hdf_fielddata.FD.values{n}), ...
                   'WriteMode', 'append' );
        writemode = 'append';
    end
    name = '/FieldData/FD';
    [details.Location, details.Name] = fileparts(name);
    attribute_details.AttachedTo = name;
    attribute_details.AttachType = 'group';
    attribute_details.Name = 'frequency';
    hdf5write( filename, attribute_details, freq, ...
                   'WriteMode', 'append' );
end

names = hdf_mesh.names; % names is a cell array
for n=1:numel(names)
    [details.Location, details.Name, ext] = fileparts(names{n});
    details.Name = [details.Name ext];
    hdf5write( filename, details, hdf_mesh.lines{n}, ...
               'WriteMode', 'append' );
end



function WriteHDF5_octave(filename,hdf_fielddata,hdf_mesh)
error 'not yet implemented'