%    LBLFIXES - script to plot lbl navigation fix stats and validation
%    results in one large window.
%
%    B. A. Moran, 16-Jun-1997

%    Copyright (C) 1995-1998, Massachussetts Institute of Technology
%    Sea Grant Autonomous Underwater Vehicles Laboratory
%    $Id: lblfixes.m,v 1.5 1998/09/19 18:48:57 bamoran Exp $	

if exist( 'm_lbl_sr1' )
    chn = [m_lbl_sr1 m_lbl_sr2 m_lbl_sr3 m_lbl_sr4];
elseif exist( 'm_lbl_1t' ) == 1
    chn = [m_lbl_1t m_lbl_2t m_lbl_3t m_lbl_4t];
else
    warning( 'No LBL channels parsed' );
    return
end

if exist( 'h_fxp' ) ~= 1
    h_fxp = figure;
    winpos( [100+100*rand 100+50*rand 800 800] );
else
    h_fxp = figure(h_fxp);
end

set( h_fxp, 'Name', 'LBL Fixes', 'DeleteFcn', 'clear h_fxp' );

if exist( 'm_lbl_valid1' ) == 1
    valid = [m_lbl_valid1 m_lbl_valid2 m_lbl_valid3 m_lbl_valid4];
elseif exist( 'm_lbl_t1_valid' ) == 1
    valid = [m_lbl_t1_valid m_lbl_t2_valid m_lbl_t3_valid m_lbl_t4_valid];
end

subplot( 4, 1, 1 );
lbltime( data(:,m_present_time), data(:,m_lbl_ping_time), ...
    data(:,chn), data(:, valid) );
zoom on


subplot( 4, 1, 2 );

if exist('m_lbl_num_used') == 1
    ind = find( finite(data(:,m_lbl_num_used)) );
    plot( data(ind,m_present_time), data(ind,m_lbl_num_used), 'o' );
elseif exist('m_lbl_num_returns_used') == 1
    plot( data(:,m_present_time), data(:,m_lbl_num_returns_used), 'o' ); 
end

ylabel( '# good' )
set( gca, 'YLim', [-.25 4.5], 'YTick', 0:4, 'XGrid', 'on', 'Box', 'on' );
zoom on

subplot( 4, 1, 3 );

if exist('lbl_fix_err') == 1
    ind = find( finite(data(:,lbl_fix_err)) );
    plot( data(ind,m_present_time), data(ind,lbl_fix_err), 'o' );
    ylabel( 'residual (m)' )
end

subplot( 4, 2, 7 )
cla
lblrate( data, m_lbl_ping_time, chn );
set( gca, 'HandleVisibility', 'off' )

subplot( 4, 2, 8 )
cla
lblhist( data, m_lbl_ping_time, chn );
set( gca, 'HandleVisibility', 'off' )
