openEMS/matlab/DumpFF2VTK.m

106 lines
2.8 KiB
Matlab
Raw Normal View History

function DumpFF2VTK2(filename, farfield, thetaRange, phiRange, varargin)
% DumpFF2VTK(filename, farfield, thetaRange, phiRange, varargin)
2011-11-28 12:14:44 +00:00
%
% Dump 3D far field pattern to a vtk file
%
% input:
% filename: filename of VTK file, existing file will be overwritten
% farfield: farfield in V/m
% thetaRange: theta range in deg
% phiRange: phi range in deg
%
% variable input:
% 'scale': - linear scale of plot, doesn't affect gain values
% 'logscale': - if set, show farfield with logarithmic scale
% - set the dB value for point of origin
% - values below will be clamped
% 'maxgain': - add max gain in dB to normalized farfield
% - only valid if logscale is set
% - default is 0dB
%
2011-11-28 12:14:44 +00:00
% example:
% DumpFF2VTK(filename, farfield, thetaRange, phiRange, ...
% 'scale', 2, 'logscale', -20, 'maxgain', 3)
%
% see also examples/NF2FF/infDipol.m
2011-11-28 12:14:44 +00:00
%
2013-06-04 22:45:55 +00:00
% See also CreateNF2FFBox, CalcNF2FF
2011-11-28 12:14:44 +00:00
%
% openEMS matlab interface
% -----------------------
% author: Thorsten Liebig
% defaults
scale = 1;
maxgain = 0;
logscale = [];
for n=1:2:numel(varargin)
if (strcmp(varargin{n},'maxgain')==1);
maxgain = varargin{n+1};
elseif (strcmp(varargin{n},'logscale')==1);
logscale = varargin{n+1};
elseif (strcmp(varargin{n},'scale')==1);
scale = varargin{n+1};
end
end
if ~isempty(logscale)
2013-05-29 13:05:51 +00:00
farfield = 20*log10(farfield) + maxgain - logscale;
ind = find(farfield<0);
farfield(ind)=0;
else
2013-05-29 13:05:51 +00:00
% force 0 for linear plot
logscale = 0;
2011-11-28 12:14:44 +00:00
end
t = thetaRange*pi/180;
a = phiRange*pi/180;
fid = fopen(filename,'w+');
% set nan values to zero
ind = find(isnan(farfield));
if (~isempty(ind))
warning('openEMS:Dump2VTK','field contains nan, setting to zero');
farfield(ind)=0;
end
% set inf values to zero
ind = find(isinf(farfield));
if (~isempty(ind))
warning('openEMS:Dump2VTK','field contains inf, setting to zero');
farfield(ind)=0;
end
fprintf(fid,'# vtk DataFile Version 3.0\n');
fprintf(fid,'Structured Grid by matlab-interface of openEMS\n');
fprintf(fid,'ASCII\n');
fprintf(fid,'DATASET STRUCTURED_GRID\n');
fprintf(fid,'DIMENSIONS %d %d %d\n',1,numel(t),numel(a));
fprintf(fid,'POINTS %d double\n',numel(t)*numel(a));
for na=1:numel(phiRange)
for nt=1:numel(thetaRange)
fprintf(fid,'%e %e %e\n',...
scale*farfield(nt,na)*sin(t(nt))*cos(a(na)),...
scale*farfield(nt,na)*sin(t(nt))*sin(a(na)),...
scale*farfield(nt,na)*cos(t(nt)));
end
end
fprintf(fid,'\n\n');
fprintf(fid,'POINT_DATA %d\n',numel(t)*numel(a));
fprintf(fid,['SCALARS gain double 1\nLOOKUP_TABLE default\n']);
fclose(fid);
2013-05-29 13:05:51 +00:00
dumpField = farfield(:) + logscale;
2011-11-28 12:14:44 +00:00
save('-ascii','-append',filename,'dumpField')