% ----------------------------------------------------------------------------
% function hfssExportToFileFC(fid, Name, PTS, Solution, Freq, [Phase = 0])
% 
% Description :
% -------------
% Evaluates the top stack element at a set of points specified in an
% external file (PTS) and exports the data to a file (Name).
%
% Parameters :
% ------------
% fid      - file identifier of the HFSS script file.
% Name     - name of the field where the stack element will be exported.
% PTS      - name of the PTS file containing the grid (with extension).
% Solution - solution being resolved.
% Freq     - frequency of the solution.
% Phase    - phase of the field in degrees.
% 
% Note :
% ------
% 1) This function is bad documented in scripting.pdf. It only indicates
%    two arguments while in reallity it requires more.
% 2) A grid can be generated by the function hfssCreatePTS.
%
% Example :
% ---------
% hfssCreatePTS(fid, 'MyGrid', [0 0 0], [1 1 1], [.1 .1 .1], 'mm');
% hfssEnterQty(fid, 'E');
% hfssExportToFileTC(fid, 'EField', 'MyGrid.pts', 'Solution', Freq);
% 
% ----------------------------------------------------------------------------

% ----------------------------------------------------------------------------
% CHANGELOG
%
% 06-Oct-2012: *Initial release.
% ----------------------------------------------------------------------------

% ----------------------------------------------------------------------------
% Written by Daniel R. Prado
% danysan@gmail.com / drprado@tsc.uniovi.es
% 06 October 2012
% ----------------------------------------------------------------------------
function hfssExportToFileFC(fid, Name, PTS, Solution, Freq, Phase)

% Arguments processor.
if (nargin < 5)
	error('Insufficient # of arguments !');
elseif (nargin < 6)
    Phase = [];
end

% Setup default arguments
if isempty(Phase)
    Phase = 0;
end

% Preamble
fprintf(fid, '\n');
fprintf(fid, 'Set oModule = oDesign.GetModule("FieldsReporter")\n');

% Command
fprintf(fid, 'oModule.ExportToFile "%s.fld", _\n', Name);
fprintf(fid, '"%s", _\n', PTS);
fprintf(fid, '"%s : LastAdaptive", _\n', Solution);
fprintf(fid, 'Array("Freq:=", "%fGHz", _\n', Freq);
fprintf(fid, '"Phase:=", "%fdeg"), true\n', Phase);