%    O2_ALTP - Altitude plots
%
%    function o2_altp( time, depth_m, alt_m, pitch, roll, poffset, pos )
%
%    B. A. Moran

%    Copyright (C) 1995-1998, Massachussetts Institute of Technology
%    Sea Grant Autonomous Underwater Vehicles Laboratory
%    $Id: o2_altp.m,v 1.1 2000/01/10 19:08:12 rob Exp $	

function o2_altp( time, depth_m, alt_m, pitch, roll, poffset, pos )

global run_name;

if nargin < 6, poffset = 0; end
if ( nargin > 6 ), winpos( pos ); end

set( gcf, 'name', 'DorOdyssey Altimeter' );

mask = find( alt_m > 0 & alt_m < 99 );
if exist( 'medfilt1' ) == 2 & ~isempty(mask)
    alt_c = medfilt1( alt_m(mask), 5 );
else
    alt_c = alt_m(mask);
end

if ( nargin < 5 )
    cr = 1;
else
    cr = cos(roll(mask));
end

if ( nargin < 4 )
    cp = 1;
else
    cp = cos(pitch(mask)+poffset);
end

alt_c = alt_c.*cr.*cp;

    position = [5 30 815 760; 5 30 815 760; ...
		5 30 815 760; 5 30 815 760];
    winpos( position(1,:) );

subplot( 2, 1, 1 )

plot( time, depth_m, 'm', time(mask), depth_m(mask) + alt_c, 'b' );
area( time(mask), depth_m(mask) + alt_c, 'facecolor', [0 .75 .5] );
set( gca, 'YDir', 'reverse' );
line( time, depth_m, 'color', [1 0.5 0], 'linewidth', 3 );
title( ['Measured Depth and Calculated Bottom: ' run_name] );
ylabel( 'Depth, Meters' );
zoom on
grid on

subplot( 2, 1, 2 )
plot( time, alt_m, 'ro' );
title( 'Raw Altimeter' );
xlabel( 'Elapsed Time, Sec.' );
ylabel( 'Range, Meters' );
zoom on
grid on