% ----------------------------------------------------------------------------
% function HfssAssignLumpedPort(fid, HName, HObjectName, HStart, HEnd, HUnits, 
%                               [HResistance = 50.0], [HReactance = 0.0])
% 
% Popis funkce :
% -------------
% Funkce potrebna k vytvoreni portu (Lumped Port) na vybranem objektu.
%
% Parametery :
% ------------
% fid          - soubor identifikujici HFSS script.
% HPortName    - jmeno vlnoveho portu.
% HObjectName  - 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.
% HResistance  - skalarni hodnota rezistance, je prednastavena na 50 Ohmu 
% HReactance   -skalarni hodnota reactance, je prednastavena na 0 Ohmu 
% 
% Poznamka :
% ------
% 1. LumpedPort je dobre napriklad umistit na objekt (kruh,krychle).
%
% Priklad pouziti funkce :
% ---------
% fid = fopen('antenna.m', 'wt');
% ... 
% HfssAssignLumpedPort(fid, 'LumpedPort', 'GapSource', [-gapL/2, 0, 0], ...
%	                 [gapL/2, 0, 0], 'meter', 75, 0);
%
% ----------------------------------------------------------------------------

function HfssAssignLumpedPort(fid,HName,HObjectName,HStart,HEnd,HUnits,...
                              HResistance,HReactance)
global Module Design
% kontrolni cast funkce.
if (nargin < 6)
	error('Nedostatek parametru!');
elseif (nargin < 7)
	HResistance = [];
	HReactance = [];
elseif (nargin < 8)
	HReactance = [];
end

% Prednastaveni parametru.
if isempty(HResistance)
	HResistance = 50.0;
end

if isempty(HReactance)
	HReactance = 0.0;
end

%Zapis do souboru temp
fprintf(fid, 'Module = Design.GetModule(''BoundarySetup'');\n');
fprintf(fid, ['Module.AssignLumpedPort({''NAME:',HName,''',...\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, ['''Resistance:='',''',num2str(HResistance),'Ohm'',...\n']);
fprintf(fid, ['''Reactance:='',''',num2str(HReactance),'Ohm'',...\n']);
fprintf(fid, ['''Objects:='',{''',HObjectName,'''}});\n\n']);


%Prime vykonani v programu HFSS
Module = Design.GetModule('BoundarySetup');
Module.AssignLumpedPort({['NAME:',HName],...
    {'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'}},...
    'Resistance:=',[num2str(HResistance),'Ohm'],...
    'Reactance:=',[num2str(HReactance),'Ohm'],...
    'Objects:=',{HObjectName}});

end