dump farfield pattern into a vtk file

pull/1/head
Thorsten Liebig 2011-11-28 13:14:44 +01:00
parent eb4c271980
commit eca5501c98
1 changed files with 68 additions and 0 deletions

68
matlab/DumpFF2VTK.m Normal file
View File

@ -0,0 +1,68 @@
function DumpFF2VTK(filename, farfield, thetaRange, phiRange, scale)
% DumpFF2VTK(filename, farfield, thetaRange, phiRange, scale)
%
% Dump 3D far field pattern to a vtk file
%
% example:
% see examples/NF2FF/infDipol.m
%
% See also CreateNF2FFBox, AnalyzeNF2FF
%
% openEMS matlab interface
% -----------------------
% author: Thorsten Liebig
if (nargin<5)
scale = 1;
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(:);
save('-ascii','-append',filename,'dumpField')