%
% PURPOSE: Plot altitude and related  data.
%
% LOG:     23 Feb 2021 rsm.
%
lstr={};
lrDatPtr=[];
lrUsblPtr=[];

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)
%global titleStr;
titleStr = [' Data Set: ', replace(DirName2,'_','-'), ' / ', replace(filepath,'_','-')];
if exist( 'position' ) ~= 1
  MonitorPositions = get(0,'MonitorPositions');
  position = MonitorPositions(end,:);
  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;
end
if exist( 'lrAltpFigPtr' ) ~= 1
  lrAltpFigPtr= figure;
  set( lrAltpFigPtr, 'Name', 'LR Altitude', 'DeleteFcn', 'clear lrAltpFigPtr' );
  set(gcf,'position',position)
  set(gcf,'colormap',jet);
  if(exist('fontsize1')) 
    lrNavFontsize=fontsize1;
  else
    lrNavFontsize=20;
  end
  lrNavFontweight='normal';
  set(gca,'fontsize',lrNavFontsize,'fontweigh',lrNavFontweight)
  set(gcf,'defaultaxesfontsize',lrNavFontsize,'defaulttextfontsize', ...
      lrNavFontsize)
  lrNavAxesPtr = gca;
else
 figure(lrAltpFigPtr);
end

vehicleDataAvail = 0;
%
% Check to see if we've got vehicle data.  If so, plot it.
if( exist( 'data' ) && isfield( data, 'RDI_Pathfinder') )
  vehicleDataAvail = 1;
  fprintf('Plotting vehicle data.\n');
  subplot(2,1,1)

  % Interpolate RDI beam ranges to depth time, so depth time is common.
  altInterp = interp1(data.RDI_Pathfinder.height_above_sea_floor.time, ...
      data.RDI_Pathfinder.height_above_sea_floor.value,...
      data.depth.time);
  plot(data.depth.time', data.depth.value'+altInterp')
  lstr(length(lstr)+1,1) = {'Water Depth'};
  hold on
  grid on
  area(data.depth.time', data.depth.value'+altInterp','facecolor',[ 0 .75 .85]);
  lstr(length(lstr)+1,1) = {'Water'};
  plot(data.depth.time', data.depth.value','m')
  lstr(length(lstr)+1,1) = {'Vehicle Depth'};
  set(gca,'ydir','reverse')
  dynamicDateTicks
  title('Depth')
  ylabel('Meters')
  legend(lstr,'location','best');

  lstr={};
  subplot(2,1,2)
  plot(data.RDI_Pathfinder.Beam1Range.time, ...
       data.RDI_Pathfinder.Beam1Range.value);
  lstr(length(lstr)+1,1) = {'Beam 1'};
  hold on
  grid on
  dynamicDateTicks
  title('Beam Ranges')
  ylabel('Meters')

  plot(data.RDI_Pathfinder.Beam2Range.time, ...
      data.RDI_Pathfinder.Beam2Range.value);
  lstr(length(lstr)+1,1) = {'Beam 2'};
  plot(data.RDI_Pathfinder.Beam3Range.time, ...
       data.RDI_Pathfinder.Beam3Range.value);
  lstr(length(lstr)+1,1) = {'Beam 3'};
  plot(data.RDI_Pathfinder.Beam4Range.time, ...
       data.RDI_Pathfinder.Beam4Range.value);
  lstr(length(lstr)+1,1) = {'Beam 4'};

  plot(data.RDI_Pathfinder.height_above_sea_floor.time,...
      data.RDI_Pathfinder.height_above_sea_floor.value,'linewidth',3);
  lstr(length(lstr)+1,1) = {'Dvl Altitude'};
  legend(lstr,'location','best');

  linkaxes(get(gcf,'children'),'x')


else
  fprintf('No data found.  Assuming orignal vehicle data (not replay) is in struct ''data''.\n');
  return
end














