% -------------------------------------------------------------------------
% function HfssAssignWavePort(fid,HPortName,HObject,HStart,HEnd,HUnits)
% 
% Popis funkce :
% -------------
% Funkce k vytvoreni portu (waveport).
%
% Parametery :
% ------------
% fid          - soubor identifikujici HFSS script.
% HPortName    - jmeno vlnoveho portu.
% HObject      - jmeno objektu na kterem bude umisten port. 
% HStart       - vektor umisteni startovniho mista portu [x,y,z]
% HEnd         - vektor umisteni koncoveho mista portu [x,y,z]
% HUnits       - specifikovane jednotky 'in', 'meter', 'mm' nebo dalsi
%                definovane jednotky pouzivane v HFSS.
%
% Poznamka :
% ------
% 1. Waveport je dobre napriklad umistit na objekt (kruh).
%
% Priklad pouziti funkce :
% ---------
% fid = fopen('antenna.m', 'wt');
% ... 
% HfssAssignWavePort(fid, Name, ObjectName, [0,0,0], [0,0,0], Units);
% 
% -------------------------------------------------------------------------

function HfssAssignWavePort(fid,HPortName,HObject,HStart,HEnd,HUnits)
global Module Design

%Zapis do souboru temp
fprintf(fid, 'Module = Design.GetModule(''BoundarySetup'');\n');
fprintf(fid, ['Module.AssignWavePort({''NAME:',HPortName,''',...\n']);
fprintf(fid, '''NumModes:='',1,...\n');
fprintf(fid, '''PolarizeEField:='',false,...\n');
fprintf(fid, '''DoDeembed:='',false,...\n');
fprintf(fid, '''DoRenorm:='',true,...\n');
fprintf(fid, '''RenormValue:='',''50Ohm'',...\n');
fprintf(fid, '{''NAME:Modes'',...\n');
fprintf(fid, '{''NAME:Mode1'',...\n');
fprintf(fid, '''ModeNum:='',1,...\n');
fprintf(fid, '''UseIntLine:='',true,...\n');
fprintf(fid, '{''NAME:IntLine'',...\n');
fprintf(fid, ['''Start:='',{''',num2str(HStart(1)),HUnits,''',']);
fprintf(fid,              ['''',num2str(HStart(2)),HUnits,''',']);
fprintf(fid,              ['''',num2str(HStart(3)),HUnits,'''},...\n']);
fprintf(fid, ['''End:='',{''',num2str(HEnd(1)),HUnits,''',']);
fprintf(fid,            ['''',num2str(HEnd(2)),HUnits,''',']);
fprintf(fid,            ['''',num2str(HEnd(3)),HUnits,'''}},...\n']);
fprintf(fid, '''CharImp:='',''Zpi''}},...\n');
fprintf(fid, ['''Objects:='',{''',HObject,'''}});\n\n']);

%Prime vykonani v programu HFSS
Module = Design.GetModule('BoundarySetup');
Module.AssignWavePort({['NAME:',HPortName],...
    'NumModes:=',1,...
    'PolarizeEField:=',false,...
    'DoDeembed:=',false,...
    'DoRenorm:=',true,...
    'RenormValue:=','50Ohm',...
    {'NAME:Modes',...
    {'NAME:Mode1',...
    'ModeNum:=',1,...
    'UseIntLine:=',true,...
    {'NAME:IntLine',...
    'Start:=',{[num2str(HStart(1)),HUnits],...
               [num2str(HStart(2)),HUnits],...
               [num2str(HStart(3)),HUnits]},...
    'End:=',{[num2str(HEnd(1)),HUnits],...
             [num2str(HEnd(2)),HUnits],...
             [num2str(HEnd(3)),HUnits]}},...
    'CharImp:=','Zpi'}},...
    'Objects:=',{HObject}});
                         
end
