%    LBLRATE - Function that plots the percent reply rate of the LBL
%    navigation transceiver channels.
%
%        lblrate( data, ping, channels, pos );
%
%    B. A. Moran, 13-Mar-1996

%    Copyright (C) 1996-1998
%    Massachussetts Institute of Technology
%    Sea Grant AUV Laboratory
%    $Id: lblrate.m,v 1.2 1998/05/15 15:01:41 bamoran Exp $	

function lblrate( data, ping, channels, pos )

				% position of window
if nargin > 3, winpos( pos ); end

				% count pings (pre/post Haro styles)
if finite(mean(data(:,ping)))
    np = sum( data(:,ping) > 0 )
else
%    np = sum( finite(data(:,ping)) );
    np = sum( data(:,ping) >= 0 );
end

if np < 1
    text( 0.5, 0.5, 'No data available', ...
        'Units', 'normal', 'HorizontalAlignment', 'Center' );
else
				% calculate reply rate
    nr = 100*sum( data(:,channels) > 0.02 )./np;
				% display bar graph
    bar( 1:length(channels), nr, 'g' )
    set( gca, 'YLim', [0 10*min(10,floor(1+max(nr)/10))], 'XGrid', 'off', ...
	'YGrid', 'on' );
				% label the bars with value, make text
				% fall within borders of plot
    for i=1:length(channels)
        h = text( i, nr(i), sprintf('%.1f', nr(i)) );
        if nr(i) > 0.9*max(nr)
            set( h, 'horizontal', 'center', 'vertical', 'top' );
        else
            set( h, 'horizontal', 'center', 'vertical', 'bottom' );
        end
    end
end
				% basic formatting
set( gca, 'Box', 'on', 'XLim', [0 length(channels)+1], ...
    'XTick', 1:length(channels) );

title( 'Channel Reply Rates' )
ylabel( 'reply rate (%)' )
xlabel( 'channel number' )
