% -------------------------------------------------------------------------
% function HfssFastSweep(fid, HName, HSolutionName, HfStartGHz, ...
%                                HfStopGHz, [HnPoints = 1000])
% 
% Popis funkce :
% -------------
% Funkce potrebna pro vytvoreni krokovani v analyze.
% 
% Parametery :
% ------------
% fid          - soubor identifikujici HFSS script.
% Name         - name of the interpolating sweep. 
% SolutionName - name of the solution to which this interpolating sweep needs
%                to be added.
% fStartGHz    - starting frequency of sweep in GHz.
% fStopGHz     - stop frequency of sweep in GHz.
% nPoints      - # of output points (defaults to 1000).
% nMaxSols     - max # of interpolating points that need to be solved (more 
%                points will guarentee convergence) - defaults to 101.
% iTol         - interpolation tolerance (defaults to 0.5).
% 
%
% Priklad pouziti funkce :
% ---------
% fid = fopen('antenna.m', 'wt');
% ... 
% HfssFastSweep(fid, 'Interp600to900MHz', 'Solve750MHz', 0.6, 0.9, 1000);
%
% -------------------------------------------------------------------------

function HfssFastSweep(fid, HName, HSolutionName, HfStartGHz, ...
                                HfStopGHz, HnPoints)

 global Module Design                           
% arguments processor.
if (nargin < 5)
	error('Insufficient # of arguments');
elseif (nargin < 6)
	HnPoints = [];
end

% process default arguments.
if isempty(HnPoints)
	HnPoints = 1000;
end;

%zapis do souboru temp
fprintf(fid,'%% Nastaveni krokovani analyzy\n');
fprintf(fid,'Module = Design.GetModule(''AnalysisSetup'');\n');
fprintf(fid,['Module.InsertDrivenSweep(''',HSolutionName,''',...\n']);
fprintf(fid,['{''NAME:',HName,''',...\n']);
fprintf(fid,'''Type:='',''Fast'',...\n');
fprintf(fid,'''SetupType:='',''LinearCount'',...\n');
fprintf(fid,['''StartFreq:='',''',num2str(HfStartGHz),'GHz'',...\n']);
fprintf(fid,['''StopFreq:='',''',num2str(HfStopGHz),'GHz'',...\n']);
fprintf(fid,['''Count:='',',num2str(HnPoints),',...\n']);
fprintf(fid,'''SaveFields:='',true,...\n');
fprintf(fid,'''ExtrapToDC:='',false});\n\n');

% Prime vytvoreni funkce v programu HFSS. 
Module = Design.GetModule('AnalysisSetup');
Module.InsertDrivenSweep(HSolutionName,...
{['NAME:',HName],...
'Type:=','Fast',...
'SetupType:=','LinearCount',...
'StartFreq:=',[num2str(HfStartGHz),'GHz'],...
'StopFreq:=',[num2str(HfStopGHz),'GHz'],...
'Count:=',HnPoints,...
'SaveFields:=',true,...
'ExtrapToDC:=',false});
