%-----------------------------------------------------------------------
% $Id: PlotCNRDiffElev.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 base 
% minus rover C/No difference 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 PlotCNRDiffElev(CNRBase,CNRRover,Elev,dropLegend,svs);

% Get a colour map
colour_LUT = setColourCodes;

figure('Visible', 'off');
hold on

%*******************************************************************
% Plot the Base-Rover C/No difference for each satellite in a unique
% colour.
%*******************************************************************
SVindex = 0;
for SV=1:svs
  i = find(isfinite(Elev(:,SV)));
  if(length(i) > 0)
    SVindex          = SVindex + 1;
    SVValue(SVindex) = SV;
    plot(Elev(:,SV),CNRBase(:,SV) - CNRRover(:,SV), ...
             'x', 'color',colour_LUT(SVindex,:)) 
  end
end

%*******************************************************************
% Now form the mean C/No difference as a function of elevation angle 
%*******************************************************************
for el=0:1:90
  i = find( (Elev >= (el-0.5)) & (Elev < (el+0.5)) );
  if(length(i) > 0)
    j = find(isfinite(CNRBase(i)));
    if(length(j) > 0)
      k = find(isfinite(CNRRover(i(j))));
      if(length(k) > 0)
        elMean(el+1) = sum(  CNRBase(i(j(k))) - CNRRover(i(j(k)))  ) / length(k);
      else
        elMean(el+1) = NaN;
      end
    else
      elMean(el+1) = NaN;
    end
  else
    elMean(el+1) = NaN;
  end
end
% Plot the mean C/No difference
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

  
% labelAxes;
