%******************************************************************
% $Id: plotRTKInits.m,v 1.3 2002/02/13 01:47:14 stuart Exp $
%
% Routine to take data from the "antenna" on/off RTK test system 
% and produce some performance plots.
%
% Note - this script has been quickly hacked so that it could be
%        compiled and provided to Terrasat from a series scripts I 
%        had. Consequently the flow and structure is not how I would
%        do it again if I had some time to start from scratch!
%
% Stuart Riley
%
% Copyright Trimble Navigation 1/16/2002
%******************************************************************


function PlotRTK(titleString,String1,String2,String3,String4,String5);


if( (nargin < 2) | (nargin >6) )
  disp(' ')
  disp('Usage:')
  disp('PlotRTKInits TitleString Legend1 Legend2 Legend3 Legend4 Legend5')
  disp(' ')
  disp('Where:')
  disp('TitleString = The global title applied to the plots, no spaces')
  disp('              are allowed!')
  disp('Legend1     = Legend applied to the first data set')
  disp('Legend2     = Legend applied to the second data set')
  disp('....')
  disp(' ')
  disp('The number of legend strings must match the number of different')
  disp('receivers compared. i.e. if 2 receivers are used in the analysis for')
  disp('comparison Legend1 & Legend2 must be present.')
  disp(' ')
  disp('Example usage:')
  disp('  Two receivers are tested in the RTK initialization tests and')
  disp('  inits.txt created. The syntax for forming the plots is then')
  disp(' ')
  disp('PlotRTKInits TerrasatRTKTest V1.00 V0.64')
  return;
elseif(nargin==2)
  DataSetStrings = [{String1}];
elseif(nargin==3)
  DataSetStrings = [{String1} {String2}];
elseif(nargin==4)
  DataSetStrings = [{String1} {String2} {String3}];
elseif(nargin==5)
  DataSetStrings = [{String1} {String2} {String3} {String4}];
else
  DataSetStrings = [{String1} {String2} {String3} {String4} {String5}];
end

NumDataSets = nargin - 1;
 
  
%titleString = 'Terrasat_Baseline';
%NumDataSets = 2; % Number of data sets we have to analyze
%DataSetStrings = [{'V1.00'} {'V0.64'}];


%********************************************************************
%                   Start of constant Defines 
%********************************************************************

FALSE = 0;
TRUE  = 1;

%********************************************************************
%                   Start of the program
%********************************************************************



% The following does not compile with the Matlab compiler, and is
% replaced by the alternative technique below.
%inits = load('inits.txt');

[ fid, errorMessage ] = fopen( 'inits.txt', 'rt' ) ;

if length( errorMessage ) > 0
  fprintf( 'Cannot open file inits.txt' ) ;
  exit ;
end ;

% Load N by inf matrix. Each N values per line read into a matrix column.
% N depends upon the number of receivers the input file has data for and is
% determined by the number of input arguments to this program.
inits = fscanf( fid, '%f', [(NumDataSets*4) + 1, inf] ) ;

fclose( fid ) ;

if ~isempty( inits ) % In case no data is available.
  inits = inits' ;  % Transpose as fscanf() fills by column.
end


doRTKInitPlot(inits,NumDataSets,DataSetStrings,titleString);

% close all
