File: DumpFF2VTK.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 (105 lines) | stat: -rw-r--r-- 2,841 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
function DumpFF2VTK(filename, farfield, thetaRange, phiRange, varargin)
%  DumpFF2VTK(filename, farfield, thetaRange, phiRange, varargin)
%
%  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
%
%   example:
%       DumpFF2VTK(filename, farfield, thetaRange, phiRange, ...
%                    'scale', 2, 'logscale', -20, 'maxgain', 3)
%
%       see also examples/NF2FF/infDipol.m
%
% See also CreateNF2FFBox, CalcNF2FF
% 
% 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)
    farfield = 20*log10(farfield) + maxgain - logscale;
    ind = find(farfield<0);
    farfield(ind)=0;
else
    % force 0 for linear plot
    logscale = 0;
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);
dumpField = farfield(:) + logscale;
save('-ascii','-append',filename,'dumpField')