%-----------------------------------------------------------------------
% $Id: plotCNR.m,v 1.5 2005/04/18 22:02:34 stuart Exp $
% Copyright Trimble 2001
%
% Takes the elevation and CNR data from load_pi and plots the C/No as a
% function of elevation angle by binning the data into 1 degree steps.
% It also computes the mean C/No for each bin and plots it.
% 
% Stuart Riley
% 12/13/01
%-----------------------------------------------------------------------

function plotCNR(CNR,Elev,dropLegend,svs);

% Get a colour map
colour_LUT = setColourCodes;

%********************************************************************
% Plot data from each satellite as a function of elevation angle in a
% different colour.
%********************************************************************
figure('Visible','off');
hold on
SVindex = 0;
for SV=1:svs
  i = find(isfinite(Elev(:,SV)));
  if(length(i) > 0)
    SVindex          = SVindex + 1;
    SVValue(SVindex) = SV;
      
    plot(Elev(:,SV),CNR(:,SV), ...
             'x', 'color',colour_LUT(SVindex,:)) 
  end
end

%********************************************************************
% Compute the mean C/No for each elevation bin.
%********************************************************************
for el=0:1:90
  i = find( (Elev >= (el-0.5)) & (Elev < (el+0.5)) );

  if(length(i) > 0)
    j = find(isfinite(CNR(i)));
    if(length(j) > 0)
      elMean(el+1) = sum(CNR(i(j))) / length(j);
    else
      elMean(el+1) = NaN;
    end
  else
    elMean(el+1) = NaN;
  end
end

% Plot the Mean C/No data
plot(0:1:90,elMean,'r-x','linewidth',2);

xlabel('Elevation Angle [Degrees]');
grid;

% Form the legend
if(dropLegend == 0)
  for i=1:SVindex
    if(svs == 32)
      StringMatrix(i) = {['PRN ',int2str(SVValue(i))]};
    else
      StringMatrix(i) = {['GLN ',int2str(SVValue(i))]};
    end
  end
  StringMatrix(i+1) = {'Mean'};
  legend(StringMatrix,4);
end
 
% Tidy the labeling of the X-axis
% labelAxes;


