Matlab: major updates/fixes for Octave support handling hdf5 field dumps
Octave: to setup the full octave hdf5 support run setup.m to build all necessary octave files. Repeat this process any time you update openEMS or octave. Signed-off-by: Thorsten Liebig <Thorsten.Liebig@gmx.de>pull/1/head
parent
a9493f8138
commit
badad9cc3b
|
@ -40,11 +40,11 @@ end
|
|||
|
||||
% read time domain field data and transform into frequency domain
|
||||
for n=find(nf2ff.directions==1)
|
||||
[Ef{n}, E_mesh{n}] = ReadHDF5Dump( [Sim_Path '/' filenames_E{n}], 'Frequency', f );
|
||||
[Ef{n}, E_mesh{n}] = ReadHDF5Dump( [Sim_Path '/' filenames_E{n} '.h5'], 'Frequency', f );
|
||||
%clear out time domain data
|
||||
Ef{n} = rmfield(Ef{n},'TD');
|
||||
|
||||
[Hf{n}, H_mesh{n}] = ReadHDF5Dump( [Sim_Path '/' filenames_H{n}], 'Frequency', f );
|
||||
[Hf{n}, H_mesh{n}] = ReadHDF5Dump( [Sim_Path '/' filenames_H{n} '.h5'], 'Frequency', f );
|
||||
%clear out time domain data
|
||||
Hf{n} = rmfield(Hf{n},'TD');
|
||||
|
||||
|
|
|
@ -2,15 +2,21 @@ function hdf_fielddata = ReadHDF5FieldData(file)
|
|||
% function hdf_fielddata = ReadHDF5FieldData(file)
|
||||
%
|
||||
% returns:
|
||||
% hdf_fielddata.time
|
||||
% hdf_fielddata.names
|
||||
% hdf_fielddata.values
|
||||
% % time domain data (if exist)
|
||||
% hdf_fielddata.TD.time
|
||||
% hdf_fielddata.TD.names
|
||||
% hdf_fielddata.TD.values
|
||||
%
|
||||
% % frequency domain data (if exist)
|
||||
% hdf_fielddata.FD.time
|
||||
% hdf_fielddata.FD.names
|
||||
% hdf_fielddata.FD.values
|
||||
%
|
||||
% example: values of timestep 12:
|
||||
% hdf_fielddata.values{12}: array (x,y,z,polarization)
|
||||
% hdf_fielddata.TD.values{12}: array (x,y,z,polarization)
|
||||
%
|
||||
% plot z-field component along y-direction for timestep 12:
|
||||
% plot( hdf_fielddata.values{12}(1,:,1,3) )
|
||||
% plot( hdf_fielddata.TD.values{12}(1,:,1,3) )
|
||||
%
|
||||
% openEMS matlab interface
|
||||
% -----------------------
|
||||
|
@ -81,11 +87,26 @@ if (numel(FD.names)>0)
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
function hdf_fielddata = ReadHDF5FieldData_octave(file)
|
||||
hdf = load( '-hdf5', file );
|
||||
hdf_fielddata.names = fieldnames(hdf.FieldData);
|
||||
for n=1:numel(hdf_fielddata.names)
|
||||
hdf_fielddata.time(n) = str2double(hdf_fielddata.names{n}(2:end));
|
||||
hdf_fielddata.values{n} = hdf.FieldData.(hdf_fielddata.names{n});
|
||||
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) = h5readatt_octave(file, hdf_fielddata.TD.names{n},'time');
|
||||
end
|
||||
end
|
||||
if isfield(hdf.FieldData,'FD')
|
||||
%read FD data
|
||||
hdf_fielddata_names = fieldnames(hdf.FieldData.FD);
|
||||
for n=1:numel(hdf_fielddata_names)/2
|
||||
hdf_fielddata.FD.values{n} = hdf.FieldData.FD.(hdf_fielddata_names{2*n}) + 1j*hdf.FieldData.FD.(hdf_fielddata_names{2*n-1});
|
||||
hdf_fielddata.FD.names{n} = ['/FieldData/FD/' hdf_fielddata_names{2*n-1}(1:end-5)];
|
||||
hdf_fielddata.FD.freq(n) = h5readatt_octave(file,['/FieldData/FD/' hdf_fielddata_names{2*n}],'frequency');
|
||||
end
|
||||
end
|
||||
|
|
|
@ -57,3 +57,9 @@ for n=1:numel(hdf_mesh.names)
|
|||
hdf_mesh.type = 1; % cylindrical mesh
|
||||
end
|
||||
end
|
||||
|
||||
if (hdf_mesh.type==1)
|
||||
% alpha and rho are in the wrong order, flip to have rho, alpha, z
|
||||
hdf_mesh.names(1:2) = fliplr(hdf_mesh.names(1:2));
|
||||
hdf_mesh.lines(1:2) = fliplr(hdf_mesh.lines(1:2));
|
||||
end
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
#include <octave/oct.h>
|
||||
#include <octave/ov-struct.h>
|
||||
#include "hdf5.h"
|
||||
|
||||
DEFUN_DLD (h5readatt_octave, args, nargout, "h5readatt_octave(<File_Name>,<DataSet_Name>,<Attribute_Name>)")
|
||||
{
|
||||
octave_value retval;
|
||||
int nargin = args.length();
|
||||
if (nargin != 3)
|
||||
{
|
||||
print_usage();
|
||||
return retval;
|
||||
}
|
||||
if ((args(0).is_string()==false) || (args(1).is_string()==false) || (args(2).is_string()==false))
|
||||
{
|
||||
print_usage();
|
||||
return retval;
|
||||
}
|
||||
|
||||
//suppress hdf5 error output
|
||||
H5Eset_auto(NULL, NULL);
|
||||
|
||||
hid_t file = H5Fopen( args(0).string_value().c_str(), H5F_ACC_RDONLY, H5P_DEFAULT );
|
||||
if (file==-1)
|
||||
{
|
||||
error("h5readatt_octave: opening the given File failed");
|
||||
return retval;
|
||||
}
|
||||
|
||||
hid_t ds = H5Dopen(file, args(1).string_value().c_str());
|
||||
if (ds==-1)
|
||||
{
|
||||
error("h5readatt_octave: opening the given DataSet failed");
|
||||
return retval;
|
||||
}
|
||||
|
||||
hid_t attr = H5Aopen_name(ds, args(2).string_value().c_str());
|
||||
if (attr==-1)
|
||||
{
|
||||
error("h5readatt_octave: opening the given Attribute failed");
|
||||
return retval;
|
||||
}
|
||||
|
||||
float value;
|
||||
if (H5Aread(attr, H5T_NATIVE_FLOAT, &value)<0)
|
||||
{
|
||||
error("h5readatt_octave: reading the given Attribute failed");
|
||||
return retval;
|
||||
}
|
||||
|
||||
H5Aclose(attr);
|
||||
H5Dclose(ds);
|
||||
H5Fclose(file);
|
||||
retval = octave_value(value);
|
||||
return retval;
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
function setup()
|
||||
% function setup()
|
||||
%
|
||||
% setup openEMS Matlab/octave interface
|
||||
%
|
||||
% openEMS matlab/octave interface
|
||||
% -----------------------
|
||||
% author: Thorsten Liebig (2011)
|
||||
|
||||
disp('setting up openEMS matlab/octave interface')
|
||||
|
||||
% cd to directory of this file and restore current path at the end
|
||||
current_path = pwd;
|
||||
dir = fileparts( mfilename('fullpath') );
|
||||
cd(dir);
|
||||
|
||||
if isOctave()
|
||||
disp('compiling oct files')
|
||||
mkoctfile -lhdf5 h5readatt_octave.cc
|
||||
else
|
||||
end
|
||||
|
||||
cd(current_path);
|
Loading…
Reference in New Issue