%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%    REVIEW - DorOdyssey mission review script.  Plots vehicle telemetry.
%
%    MIT SeaGrant Lab
%
%    Copyright (C) 1995-1998
%    Massachussetts Institute of Technology
%    Sea Grant AUV Laboratory
%    $Id: review.m,v 1.6 2000/01/18 02:11:28 rob Exp $	
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

global RCS run_name

if isempty(RCS)
    disp( 'DorOdyssey Mission Review $Revision: 1.6 $' );
    RCS = 0;
end

run_name = 'DorOdyssey';
%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=[1:4 6 8 12]; 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 is by definition the first column of all log files.
%
m_present_time = 1;
%
% The following back difference is now done in logToMatlab.
%
%time = data(:,m_present_time) - data(1,m_present_time);

%if ( strcmp(computer,'SGI64') | strcmp(computer,'HP700') )
%   position = [120 525 560 420; 705 525 560 420; ...
%               120 115 560 420; 705 115 560 420];
%    position = [5 30 815 760; 5 30 815 760; ...
%		5 30 815 760; 5 30 815 760];
%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
    position = [5 30 815 760; 5 30 815 760; ...
		5 30 815 760; 5 30 815 760];
if ( strcmp(computer,'PCWIN'))
  position = [4 32 815 658];
end



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

%					% LBL fixes
if strcmp( opts, 'all' ) | any( opts == 5 )
    lblfixes
end
%
if strcmp( opts, 'all' ) | any( opts == 12 )
    if exist('mThrAmps') == 1, thrPlot, end
    pause(.5)
    ahrs1
end

%
% sonar plots
%
if strcmp( opts, 'all' ) | any( opts == 6 )
    if exist( 'h_alt' ) ~= 1
	h_alt = figure;
    else 
	figure( h_alt );
    end
    alt   = dataNav(:,mAltitude);
    range = dataNav(:,mPsaRange);
%    o2_altp( dataNav(:,1), dataNav(:,mDepth), range, dataNav(:,mTheta),...
%             dataNav(:,mPsi), off );
    altp
end

%
% Keithley Metrabyte units hooked to Copley thruster controller
%
if exist('m_km_current') == 1 & exist('m_km_voltage') == 1
    if strcmp(opts, 'all') | any(opts == 10)
	if exist( 'h_cop' ) ~= 1
	    h_km = figure;
	    winpos( position(3,:) );
	else
	    h_km = figure( h_km );
	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( 'conductivity' ) == 1 & exist( 'temperature' ) == 1)) 
    ctdPlot
  end



return


if (strcmp(opts, 'all') | any( opts == 8 )) ...
	& ((exist( 'conductivity' ) == 1 & exist( 'temperature' ) == 1) ...
	| (exist( 'cond_frequency' ) == 1 & exist( 'temp_frequency' ) == 1))

%    if exist('conductivity') & exist('temperature')
%	cond = ctdlog(:,conductivity);
%	temp = ctdlog(:,temperature);
%    else
%	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
%    end
%
    ctdlogA = ctdlog;
    sz = size(ctdlog);
    paroPres = sz(2)+1;
    ctdlogA(:,paroPres) = ...
           interp1(parosci(:,1), parosci(:,pressure), ctdlogA(:,1));

%   [sal,svel] = salsp( cond, temp, 10*ctdlogA(:,paroPres) );
    [sal,svel] = salsp(   ctdlogA(:,conductivity), ...
                          ctdlogA(:,temperature), ...
                       10*ctdlogA(:,paroPres) );

    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(data(:,m_depth),temp,sal,svel);
end
