%    REVIEW - Odyssey II mission review script.  Handles wide range of
%    different parameters in multiple windows.
%
%    B. A. Moran, 16-Jun-1995

%    Copyright (C) 1995-1998
%    Massachussetts Institute of Technology
%    Sea Grant AUV Laboratory
%    $Id: vplane.m,v 1.3 1998/01/07 20:10:55 bamoran Exp $	

global RCS run_name

if isempty(RCS)
    disp( 'Odyssey II Mission Review $Revision: 1.1 $' );
    RCS = 0;
end

run_name = upper(run_name);
jj = find( run_name == '_' );
if ~isempty(jj)
    run_name(jj) = '.';
end
clear jj;

				% default is depth, yaw
if exist( 'opts' ) ~= 1, opts=2:3; end
if exist( 'ctdcal' ) ~= 1, ctdcal = 'xan0895'; end

if exist( 'time0' ) == 1 & exist( 'o2_time0' ) == 3
    start = o2_time0( time0 );
    disp( ['OS-9 start time: ' sprintf('%d',start) ' (ANSI time)'] );
end

time = data(:,m_present_time) - data(1,m_present_time);

if strcmp(computer,'SGI')
    position = [120 525 560 420; 705 525 560 420; ...
	        120 115 560 420; 705 115 560 420];
elseif strcmp(computer,'PCWIN')
    position = [  4 304 392 273; 404 304 392 273; ...
	          4   4 392 273; 404   4 392 273];
else
    position = ['tl'; 'tr'; 'bl'; 'br'];
end

%
% Now start the plots
%
                                     	% timing plots
if strcmp( opts, 'all' ) | any( opts == 1 )
    timing
end
                                     	% vertical plane
if strcmp( opts, 'all' ) | any( opts == 2 )
    vplane
end
                                     	% heading
if strcmp( opts, 'all' ) | any( opts == 3 )
    heading
end
					% navigation plot
if strcmp( opts, 'all' ) | any( opts == 4 )
    navplot
end

%					% LBL fixes
if strcmp( opts, 'all' ) | any( opts == 5 )
    lblfixes
end

%
% sonar plots
%
if strcmp( opts, 'all' ) | any( opts == 6 )
    if exist( 'h_alt' ) ~= 1
	h_alt = figure;
    else 
	h_alt = figure( h_alt );
    end
    alt = [];
    off = 0;				% pitch offset (rad) altimeter
    if exist( 'm_sonar_alt' ) == 1
	alt = data(:,m_sonar_alt);
    end
    if exist( 'm_psa_range' ) == 1
	alt = data(:,m_psa_range);
	off = 0*pi/180;
    end
    o2_altp( time, data(:,m_depth), alt, data(:,m_pitch), data(:,m_roll), ...
	off );
end

%
% Keithley Metrabyte units hooked to Copley thruster controller
%
if exist('m_copley_current') == 1 & exist('m_copley_voltage') == 1
    if strcmp(opts, 'all') | any(opts == 10)
	if exist( 'h_cop' ) ~= 1
	    h_cop = figure;
	    winpos( position(3,:) );
	else
	    h_cop = figure( h_cop );
	end
	o2_power
    end
end

if strcmp( opts, 'all' ) | any( opts == 11 )
    if exist( 'h_spd' ) ~= 1
	h_spd = figure;
	winpos( position(3,:) );
    else
	h_spd = figure( h_spd );
    end
    o2_speed
end
%
% CTD profiles
%
if (strcmp(opts, 'all') | any( opts == 8 )) ...
	& ((exist( 'm_cond' ) == 1 & exist( 'm_temp' ) == 1) ...
	| (exist( 'sbe_cond_freq' ) == 1 & exist( 'sbe_temp_freq' ) == 1))

    if run_name(1) == 'A' | run_name(1) == 'W'
	[temp,cond]=o2_ctpc( data(:,m_pressure), data(:,sbe_cond_freq), ...
	    data(:,sbe_temp_freq), 'aph0396' );
    else
				% cond and temp reversed for Xanthos due
                                % to wiring mixup, repaired by JWB while
                                % aboard R/V Cape Hatteras 14-Apr-97
	if start <= 863613417
	    [temp,cond] = o2_ctpc( data(:,m_pressure), data(:,m_temp), ...
		data(:,m_cond), 'xan0895' );
	else
	    [temp,cond] = o2_ctpc( data(:,m_pressure), data(:,sbe_cond_freq), ...
		data(:,sbe_temp_freq), 'xan0895' );
	end
    end

    [sal,svel] = salsp( cond, temp, 10*data(:,m_pressure) );

    if strcmp(opts, 'all') | any( opts == 8 )
	if exist( 'h_ctd' ) ~= 1, h_ctd = figure;
	else h_ctd = figure( h_ctd ); end
	subplot( 2, 1, 1 )
	plot( time, temp, 'r' ); zoom on;
	title( ['Temperature and Salinity: ' run_name] );
	ylabel( 'temperature (^{o}C)' )
	subplot( 2, 1, 2 )
	plot( time, sal, 'color', [0 .7 0] ); zoom on;
	ylabel( 'salinity (psu)' )
	xlabel( 'mission time (s)' );
    end

end

if strcmp(opts, 'all') | any( opts == 9 )
    tscast
end
