%    REVIEW - Odyssey II mission review script.  Handles wide range of
%    different parameters in multiple windows.
%
%    B. A. Moran, 16-Jun-1995
%
%    Modifications by J. G. Bellingham,  19-Sept-1998
%
%    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 $	
%
%    Options:
%			opts = 1		timing 
%			opts = 2		vertical plane  (depth, pitch)
%			opts = 3		heading 
%			opts = 4		navigation 
%			opts = 5		LBL 
%			opts = 6		altimeter 
%			opts = 7		battery voltage, current draw 
%			opts = 8		CTS as function of time 
%			opts = 9		T, S, and SOS as function of depth 
%			opts = 10	fluorometer and optical backscatter 
%			opts = 11	RDI plots
%
%	Things to fix:
% 		figure positions
%      data conditioning...
%			depth
% 			temperature
%			conductivity
%			salinity
%			obs
%			fluorometer
%      clearing of variables

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;

fix_time;
fix_depth;

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


if strcmp(computer,'SGI')
   position = [120 575 560 420; 705 575 560 420; ...
         120 115 560 420; 705 115 560 420];
elseif strcmp(computer,'PCWIN')
   position = ['tl'; 'tr'; 'bl'; 'br'];
   %   position = [  4 304 392 273; 404 304 392 273; ...
   %        4   4 392 273; 404   4 392 273];
   %  [120 575 560 420; 705 575 560 420; ...
   %    120 115 560 420; 705 115 560 420];
   %
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 ))) & exist( 'm_lbl_eastfix' ) 
   lblfixes
end

% -----------------------------------------------------------------------------
% sonar plots
%
if strcmp( opts, 'all' ) | any( opts == 6 )
   if exist( 'h_alt' ) ~= 1
      h_alt = figure;
      winpos( position(1,:) );
   else 
      h_alt = figure( h_alt );
   end
   
   off = 0;				% pitch offset (rad) altimeter
   
   if exist( 'm_sonar_alt' ) == 1
      alt = data(:,m_sonar_alt);
   elseif exist( 'm_rdi_alt' ) == 1
      alt = data(:,m_rdi_alt);
   elseif exist( 'm_psa_range' ) == 1
      alt = data(:,m_psa_range);
      off = 20*pi/180;
   end
   
   if exist('alt')
      o2_altp( time, data(:,m_depth), alt, data(:,m_pitch), data(:,m_roll), ...
         off );
   end
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 == 7)
      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( 'water_temp' ) == 1 & exist( 'water_cond' ) == 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
   
   fix_ctd;
   
   if exist( 'h_ctd' ) ~= 1, 
      h_ctd = figure;
   else 
      h_ctd = figure( h_ctd ); 
   end;
   
   subplot( 3, 1, 1 )
   abc = data(:,water_temp);
   abc(going_down) = NaN;
   plot( time, abc, 'Color', [.6 0 0] ); 
   hold on
   abc = data(:,water_temp);
   abc(going_up) = NaN;
   plot( time, abc, 'Color', [1 0 0] ); 
   zoom on;
   title( ['Temperature and Salinity: ' run_name] );
   ylabel( 'temperature (^{o}C)' );
   
   subplot( 3, 1, 2 )
   abc = sal;
   abc(going_down) = NaN;
   plot( time, abc, 'color', [0 .6 0] ); 
   hold on;
   abc = sal;
   abc(going_up) = NaN;
   plot( time, abc, 'color', [0 1 0] ); 
   zoom on;
   ylabel( 'salinity (psu)' )
   xlabel( 'mission time (s)' );
   
   subplot( 3, 1, 3 )
   abc = data(:, water_cond);
   abc(going_down) = NaN;
   plot( time, abc, 'color', [0.4 0.4 1] ); zoom on;
   hold on;
   abc = data(:, water_cond);
   abc(going_up) = NaN;
   plot( time, abc, 'color', [0 0 0.5] );    
   ylabel( 'conductivity (?)' )
   xlabel( 'mission time (s)' );
   
end;

if strcmp(opts, 'all') | any( opts == 9 )
   tscast(data(:, m_depth), data(:, water_temp), sal, svel, going_up, going_down )
end

if strcmp(opts, 'all') | any( opts == 10 )
   optics_cast
end

if strcmp(opts, 'all') | any( opts == 11 )
%   depth_rate(time, data(:, m_rdi_x), data(:, m_rdi_z), data(:, m_depth), depth_rate, going_up, going_down);
end
