%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% PURPOSE: Plot items related to the tailcone.
% AUTHOR:  rsm
% DATE:    00/5/20
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%

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( 'lrTailFigPtr' ) ~= 1
  lrTailFigPtr= figure;
  set( lrTailFigPtr, 'Name', 'LR Thruster', 'DeleteFcn', 'clear lrTailFigPtr' );
  set(gcf,'position',position)
  if(exist('fontsize')) 
    lrTailFontsize=fontsize;
  else
    lrTailFontsize=20;
  end
  lrTailFontweight='normal';
  set(gca,'fontsize',lrTailFontsize,'fontweigh',lrTailFontweight)
  set(gcf,'defaultaxesfontsize',lrTailFontsize,'defaulttextfontsize', ...
      lrTailFontsize)
  lrTailAxesPtr = gca;
else
 figure(lrTailFigPtr);
end
  
  subplot(2,1,1)
  if( isfield(data,'ThrusterHE'))
    omega = data.ThrusterHE.platform_propeller_rotation_rate.value;
    time  = data.ThrusterHE.platform_propeller_rotation_rate.time;
    current = data.ThrusterHE.component_avgCurrent.value;
    ctime   = data.ThrusterHE.component_avgCurrent.time;
    voltage = data.ThrusterHE.component_avgVoltage.value;
    vtime   = data.ThrusterHE.component_avgVoltage.time;
  elseif( isfield(data,'ThrusterServo'))
    omega = data.ThrusterServo.platform_propeller_rotation_rate.value;
    time  = data.ThrusterServo.platform_propeller_rotation_rate.time;
    current = data.ThrusterServo.component_avgCurrent.value;
    ctime   = data.ThrusterServo.component_avgCurrent.time;
    voltage = data.ThrusterServo.component_avgVoltage.value;
    vtime   = data.ThrusterServo.component_avgVoltage.time;
  else
    fprintf('Error.  Cant''t find thruster log.')
    return
  end
  plot(ctime, current, vtime, voltage);
  ylabel('Averaged milli-Amps');
  xlabel('Elapsed Time');
  title(['Thruster Current']);
  grid on;
  zoom on;
  dynamicDateTicks

%
% Propeller speed is logged in radians/sec.
%
  subplot(2,1,2)
  plot(time, omega*60/2/pi);
  ylabel('Rev/Min')
  title(['Propeller Speed']);
  xlabel('Elapsed Time');
  grid on;
  zoom on;


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

  if exist( 'ActFig' ) ~= 1
    ActFig = figure;
    figure(ActFig);
    winpos( position(1,:) );
  else
    figure(ActFig);
  end
  set( ActFig, 'Name', 'Tailcone Plot', 'DeleteFcn', 'clear ActFig' );
  set(gca,'fontsize',fontsize,'fontweigh',fontweight)

  subplot(2,1,1)
  stairs(dataTC(:,1), dataTC(:,rudderAngle)*r2d );
  hold on
  if exist('dataDC'), stairs(dataDC(:,1), dataDC(:,cDeltaR)*r2d,'Color','r');end
  ylabel('Degrees')
  title(['Rudder Angle',str]);
  xlabel('Elapsed Time (s)');
  grid on;
  zoom on;
  set(gca,'fontsize',fontsize,'fontweigh',fontweight)

  subplot(2,1,2)
  stairs(dataTC(:,1), -dataTC(:,elevatorAngle)*r2d, 'Color','b');
  hold on
  if exist('dataDC'), stairs(dataDC(:,1), dataDC(:,cDeltaE)*r2d, 'Color','r');end
  ylabel('Degrees')
  title(['Elevator Angle',str]);
  xlabel('Elapsed Time (s)');
  grid on;
  set(gca,'fontsize',fontsize,'fontweigh',fontweight)
  set( gca, 'ydir', 'reverse' );


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


