%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% PURPOSE: Plot vehicle telemetry.
% AUTHOR:  MIT Seagrant, Rob McEwen
% DATE:    00/6/1
% NOTES:
%
% Type "review" to plot the basic set.  
% Type "plotSwLatLon=0;review" to see vehicle position in meters, UTM.
% Type "plotSwGNC=1;review" to see the Timing and Ahrs plots.
% Type "plotSwDvl=1;review" to see Dvl Ahrs data overlaid on the Ahrs plots. 
% Type "plotSwLBL=1;review" to see Lbl data
% Type "plotSwIce=1;review" if the Kearfott is pointed up.
% Type "plotSwOct=1;review" to turn on Octans plots
% Type "plotSwKft=1;review" to turn on Kearfott plots
% Type "plotSci=1;review" to also see science data.
% Type "plotSci=2;review" to see even more science data.
%
% NOTE: You may set any combination of the above switches.  The settings will
% persist until you exit Matlab, provided you don't clear them (as in "clear
% all"). 
%
% NOTE: Many of these can be left on, such as plotSwKft, and they still won't
% try to plot data unless the data is present on the stack.  The reason for 
% the switch is to turn off the plot when the data IS present.
%
%
%    $Id: review.m,v 1.40.2.1 2015/09/25 21:43:02 headley Exp $
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 global titleStr;
 global vehicleName;

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

 disp([vehicleName, ' Mission Review $Revision: 1.40.2.1 $']);
 disp(sprintf('Type "help review.m" (include the .m) for help.\n'));
 
 titleStr = ['; Data Set: ', DirName];

 m_present_time = 1;

 if( exist('fontsize') == 0 ) 
     fontsize=15;
 end
 
 if( exist('plotSwPublish') == 0 ) 
     plotSwPublish=0;
 else
     if( plotSwPublish == 1 ) fontsize = 30; end
 end

 
 units;      %Put unit conversions on the stack

 if( exist('pmeters')~=1 ) pmeters = 1;end
  
  co = [0 0 1;
        0 0.5 0;
        1 0 0;
        0 0.75 0.75;
        0.75 0 0.75;
        0.75 0.75 0;
        0.25 0.25 0.25];
  set(groot,'defaultAxesColorOrder',co)

 
% position = [4 32 815 658];
  position = get(0,'screensize');
  npposition(1:2) = position(1:2) + round([position(3)*.02 position(4)*.04]);
  npposition(3:4) = round([position(3)*.95 position(4)*.90]);
  position = npposition;
%
% 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
%
% Default plot switches:
%  
  if( exist('plotSwGNC') ~= 1 ) plotSwGNC = 0; end  %Additional GNC stuff
  if( exist('plotSwSci') ~= 1 ) plotSwSci = 0; end  %Science plots
  if( exist('plotSwLBL') ~= 1 ) plotSwLBL = 0; end  %LBL plots
  if( exist('plotSwIce') ~= 1 ) plotSwIce = 0; end  %Dvl flipped up
  if( exist('plotSwOct') ~= 1 ) plotSwOct = 0; end  %Octans data
  if( exist('plotSwDvl') ~= 1 ) plotSwDvl = 0; end  %Dvl Ahrs data
  if( exist('plotSwKft') ~= 1 ) plotSwKft = 0; end  %Kearfott data
  if( exist('plotSwShort') ~= 1 ) plotSwShort = 1; end  

  
%
% Setup for uust03 paper:
%
if( 0 )
  plotSwGNC = 1; 
  plotSwOct = 1; 
  plotSwDvl = 0; 
  plotSwKft = 1; 
end

% For the multibeam sea trials.
plotSwKft = 1;

%
% Now, start the plots.
%
  vplane
  pause(.5)
  heading
  pause(.5)
  navplot
  pause(.5)
  altp
  pause(.5)
  usbl
  figure(nav);
  if( plotSwShort ) return; end;
  pause(.5)
  battery
  pause(.5)
  bluefinBattery
  pause(.5)
  dvl
%  pause(.5)
%  cvtwf
  pause(.5)
  tailconePlot
  pause(.5)
  env

  
  if( plotSwGNC == 1 )
    timing
    pause(.5)
    ahrs
    pause(.5)
  end
  if( plotSwLBL == 1 )
    ps8000
    pause(.5)
    lblKalmanPlot
    pause(.5)
  end

  if( plotSwSci == 1 )
    ctdmultiPlot2
  elseif( plotSwSci == 2 )
    ctdmultiPlot1
    ctdmultiPlot2
    isusPlot3
  end


% fuelcell
% dutycycle
% pwrplots2

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