%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% PURPOSE: Plot vehicle telemetry.
% AUTHOR:  MIT Seagrant, Rob McEwen
% DATE:    00/6/1
% NOTES:
%
%    $Id: review.m,v 1.14 2000/06/14 22:28:30 rob Exp $	
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

global titleStr;
global vehicleName;

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

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

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

m_present_time = 1;

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
%
% Now, start the plots.
%
navplot

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
   %
   
   % First compute depth in time-base of CTD data
   
   ctd_depth = ctd_depth_prep(dataNav(:,1), dataNav(:,mDepth), ctdlog(:,1));
   
   % Now compute pressure in dB from depth
   
   dBar = sw_pres(ctd_depth, 36.8);  % Use 36.8 as latitude....
   
   % Now compute temperature and conductivity using the correct coefficients
   
   if exist(fix_ctd)
      if fix_ctd == 1
         [temp,cond,mask] = ctd_freq_conv(dBar, ctdlog(:,cond_frequency), ctdlog(:,temp_frequency), 'night' );
      end;
   end;
   
   % Compute salinity from conductivity, temperature, and pressure
   
   sal = sw_salt(10*cond/sw_c3515,temp,dBar);
   
   % Compute density from salinity, temperature, and pressure.
   
   dens = sw_dens(sal, temp, dBar);
   
   %   [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(ctd_depth,temp,sal,dens);
end
