%-----------------------------------------------------------------------
% $Id: plotSVTrack.m,v 1.5 2008/01/04 20:48:29 vnadkar Exp $
% Copyright Trimble 2001
%
% From the output of PiLineMex.dll performs 
% produces a plot of all the double-difference ionospheric residuals on
% the same plot.
% 
% Stuart Riley
% 12/12/01
%-----------------------------------------------------------------------

function plotSVTrack(ElevL1,ElevL2,phaseDDiffL1,PlotPNG,L2Present,timeStr,system);

TRUE  = 1;
FALSE = 0;
% Get a colour map
colour_LUT = setColourCodes;

figure('Visible','off');
hold on
Yindex = 0;

if(system == 0)
  NumSV = 32;
else
  NumSV = 24;
end

for SV=1:NumSV

  i = find(isfinite(ElevL1(:,SV+1)));
  if(length(i) > 0)
    Yindex         = Yindex + 1;
    YValue(Yindex) = SV;
  
    ElevL1(i,SV+1) = ones(length(i),1).*0; 
    plot(ElevL1(:,1),ElevL1(:,SV+1) + 0.2 + Yindex, ...
         'color',colour_LUT(Yindex,:), ...
         'linewidth',2)

    if(L2Present == TRUE)
      % Now Test for L2
      i = find(isfinite(ElevL2(:,SV+1)));
      if(length(i) > 0)
  
        ElevL2(i,SV+1) = ones(length(i),1).*0; 
 
        plot(ElevL2(:,1),ElevL2(:,SV+1) - 0.2 + Yindex, ...
             'color',colour_LUT(Yindex,:), ...
             'linewidth',2)
      end
    end

    % Now figure out if this was the reference satellite. If it was then
    % there will no no double difference.

    j = find( ~isfinite(phaseDDiffL1(i,SV+1) ) );

    if(length(j) > 0)
      %
      % Make an array of NaNs, fill in zeros where this
      % satellite is the reference. If the data set is long and
      % the satellite is a reference more than once the NaNs will force
      % the plot to do a "pen-up" operation so a continuous black line
      % will not get displayed.
      % 
      s = size(phaseDDiffL1, 1);
      k = ones(s,1).*NaN;
      k(i(j)) = ones(length(j),1).*0;
      plot(ElevL1(:,1),k + Yindex, ...
           'k', 'linewidth',4)
    end
  end
end

% 
% Now sort out the y-axis labels
H = gca;
set(H,'YTick',[1:Yindex]);
set(H,'YTickLabel',YValue);
if(system == 0)
  ylabel('Satellite PRN');
else  
  ylabel('Satellite GLN');
end

xlabel(['Time [GPS Sec]    ',timeStr],'Interpreter','none');
title('Common Base/Rover Satellites - Thick Black Line = Reference SV');
labelAxes([],[],[],[],1);
if(PlotPNG == TRUE)
  if(system == 0)
    print('-dpng',['tracking.png']);
  else
    print('-dpng',['GLNtracking.png']);
  end
  disp('Tracking Plot created ...');
end  



