%    NAVPLOT - script to plot navigation data in one large window.
%
%    B. A. Moran, 16-Jun-1995

%    Copyright (C) 1995-1998
%    Massachussetts Institute of Technology
%    Sea Grant AUV Laboratory
%    $Id: navplot.m,v 1.6 1998/10/21 21:37:02 bamoran Exp $	

if exist( 'h_nav' ) ~= 1
    h_nav = figure;
    if strcmp( computer, 'SGI' )
	winpos( [100+200*rand 100+100*rand 800 600] );
    end
else
    h_nav = figure(h_nav);
end

set( h_nav, 'Name', 'Navigation Plot', 'DeleteFcn', 'clear h_nav' );

if exist( 'do_3d_plot' ) ~= 1, do_3d_plot = 0; end
if exist( 'm_pos_n' ) == 1
    pos = [m_pos_n m_pos_e];
elseif exist( 'm_lbl_est_north' ) == 1
    pos = [m_lbl_est_north m_lbl_est_east];
else
    pos = [m_dr_north m_dr_east];
end
    
if exist('lbl_fixstat') == 1
    ind = find( data(:,lbl_fixstat) == 1 );
elseif exist('m_lbl_fixstat') == 1
    ind = find( data(:,m_lbl_fixstat) == 1 );
else
    ind = [];
end

if do_3d_plot == 0

    plot( data(:,pos(2))/1000, data(:,pos(1))/1000, ...
	data(:,m_dr_east)/1000, data(:,m_dr_north)/1000 );
    title( ['Estimated Position (b), DR (g): ' run_name] );
    hold on;
    if ~isempty(ind)
	plot( data(ind,m_lbl_eastfix)/1000, ...
	    data(ind,m_lbl_northfix)/1000, 'ro' );
	Xb = o2_xpndr( start );
	o2_xpndr( Xb(:,1:2)/1000 );
    end

    if exist( 'c_wpt_e' ) == 1
	line( data(:,c_wpt_e)/1000, data(:,c_wpt_n)/1000, 'linewidth', 3 );
    end

else

    plot3( data(:,pos(2)), data(:,pos(1)), data(:,m_depth) );
    set( gca, 'ZDir', 'reverse' );

    if ~isempty(ind)   
	Xb = o2_xpndr( start );
	o2_xpndr( Xb(:,1:2) );
    end
end

xlabel( 'TM East (km)' )
ylabel( 'TM North (km)' )

set( gca, 'DataAspectRatio', [1 1 .25] );

zoom on;
hold off;
