%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% PURPOSE: Plot vehicle telemetry.
% AUTHOR:  MIT Seagrant, Rob McEwen
% DATE:    00/6/1
% NOTES:
%
%    $Id: review.m,v 1.20 2001/04/09 00:45:01 rob Exp $
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 global titleStr;
 global vehicleName;

 vehicleName = 'Dorado';
 %vehicleName = 'DorOdyssey';

 disp([vehicleName, ' Mission Review $Revision: 1.20 $']);

 titleStr = ['; Data Set: ', DirName];

 m_present_time = 1;

 units;      %Put unit conversions on the stack
 
 position = [4 32 815 658];
%
% if ( strcmp(computer,'PCWIN'))  position = [4 32 815 658]; end
%
% Check to make sure the data is resident in Matlab memory:
%
  if ( exist('dataNav') ~= 1 )
    disp ' Navigation Data Not Present.'
    return
  end
  if ( exist('dataDC') ~= 1 )
    disp ' Dynamic Control Data Not Present.'
    return
  end
%
% Now, start the plots.
%
  if( exist('Nicole') ~= 1 ), Nicole = 0; end;
  timing
  vplane
  heading
  navplot
  ps8000
  lblKalmanPlot
  ahrs
  altp
  tailconePlot
  battery
  fuelcell
  dvl
  cvtwf
  if( Nicole == 1 )
    dutycycle
    pwrplots2
  end
%
% Require the user to specify the lbl grid array, if desired, each time.
%
  clear lblgrid;
  return









                                        % 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 )
%  if exist('gps') == 1
%    gpsPlot
%  else
%    navplot
%  end
   navplot
    pause(.5)
end

%                                       % LBL fixes
if strcmp( opts, 'all' ) | any( opts == 5 )
    lblfixes
end
%
if strcmp( opts, 'all' ) | any( opts == 12 ) %Tailcone AND Crossbow
%   if exist('mThrAmps') == 1, thrPlot, end
end

%
% sonar plots
%
 alt   = dataNav(:,mAltitude);
 range = dataNav(:,mPsaRange);

%
% 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
