%
% PURPOSE: Plot horizontal plane data.
%
% LOG:     22 Feb 2021 rsm.
%
lstr={};
lrDatPtr=[];
lrUsblPtr=[];
%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( 'lrBuoyFigPtr' ) ~= 1
  lrBuoyFigPtr= figure;
  set( lrBuoyFigPtr, 'Name', 'LR Vertical Plane', 'DeleteFcn', 'clear lrBuoyFigPtr' );
  set(gcf,'position',position)
  if(exist('fontsize')) 
    lrNavFontsize=fontsize;
  else
    lrNavFontsize=20;
  end
  lrNavFontweight='normal';
  set(gca,'fontsize',lrNavFontsize,'fontweigh',lrNavFontweight)
  set(gcf,'defaultaxesfontsize',lrNavFontsize,'defaulttextfontsize', ...
      lrNavFontsize)
  lrNavAxesPtr = gca;
else
 figure(lrBuoyFigPtr);
end

vehicleDataAvail = 0;
%
% Check to see if we've got vehicle data.  If so, plot it.
if( exist( 'data' ) && isfield( data, 'depth') )
  vehicleDataAvail = 1;
  fprintf('Plotting vehicle data.\n');
  plot(data.depth.time,-data.depth.value,'b');
  grid on;
  hold on;
  dynamicDateTicks
% plot(data.VerticalControl.buoyancyAction.time,data.VerticalControl.buoyancyAction.value/100,'g');
plot(data.VerticalControl.smoothDepthInternal.time, ...
    -data.VerticalControl.smoothDepthInternal.value,'r')
plot(data.VerticalControl.depth2buoyIntInternal.time, data.VerticalControl.depth2buoyIntInternal.value/10,'g');
  plot(data.platform_buoyancy_position.time,data.platform_buoyancy_position.value*10000,'m');
  legend('Meas Depth,m','Smoothed Depth Cmd,m.','Integrator, cc','Meas. ExternalOil,cc');

  if( isempty(data.VerticalControl.kpDepthBuoy.value)) 
    temp.kp = 0;
  else
    temp.kp = data.VerticalControl.kpDepthBuoy.value(end);
  end

  if( isempty(data.VerticalControl.kiDepthBuoy.value)) 
    temp.ki = 0;
  else
    temp.ki = data.VerticalControl.kiDepthBuoy.value(end);
  end

  if( isempty(data.VerticalControl.kdDepthBuoy.value)) 
    temp.kd = 0;
  else
    temp.kd = data.VerticalControl.kdDepthBuoy.value(end);
  end
  txtstr = sprintf('  K_p = %d cc/m K_i = %.3f cc/m/sec K_d = %d cc/(m/sec)',...
      temp.kp, temp.ki, temp.kd);

  title([ titleStr txtstr]);
end


