%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% PURPOSE: Plot Voltage and Power Data in an Alternate Manner
% AUTHOR:  Nicole Tervalon
% DATE:    00/11/15
% NOTES:
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

  if exist('metrabyte') ~= 1, return, end
  str = [' ',titleStr,' Plotted on ',myDate];
  PaperPosn = [.5 .5 3.75 2.5];
  FigurePosn = [5 30 815 900];
  i = 0;
  hold off


  if exist( 'pwrFig1' ) ~= 1
    pwrFig1 = figure;
    winpos( position(1,:) );
  else
    figure(pwrFig1);
  end
  set(pwrFig1,'Name','Detailed Power Consumption','DeleteFcn','clear pwrFig1');

  subplot(4,1,1)
  cla
  plot(metrabyte(:,1), metrabyte(:,voltage));
  ylabel('Volts')
  title(['Bus Voltage ',str]);
  grid on
  zoom on

  for ii = 1:length(dutyR)
     if dutyR(ii)>1
        dutyR1(ii) = 1;
     else
        dutyR1(ii) = dutyR(ii);
     end
     if dutyE(ii)>1
        dutyE1(ii) = 1;
     else
        dutyE1(ii) = dutyE(ii);
     end
  end

  intcurrent1=interp1(metrabyte(:,1),metrabyte(:,current),dataDC(:,1),'linear');
  intvolt1=interp1(metrabyte(:,1),metrabyte(:,voltage),dataDC(:,1),'spline');
  intcurrent2=interp1(dataTC(:,1),dataTC(:,propCurrent1),dataDC(:,1),'linear');
  [xx5, yy5] = stairs(dataDC(:,1),dutyR1*1.2);
  [xx6, yy6] = stairs(dataDC(:,1),dutyE1*1.2);


  subplot(4,1,2)
  cla
  plot(metrabyte(:,1),metrabyte(:,current),'b',dataTC(:,1), ...
      dataTC(:,propCurrent1),'g');
  hold on
  plot(dataDC(:,1), intcurrent1,'r');
  hold off
  ylabel('Amperes')
  title(['Currents: Bus-Red; Thruster-Green',str]);
  grid on;
  zoom on;

  subplot(4,1,3)
  cla
  plot(xx5,yy5,'r',xx6,yy6,'g');
  ylabel('Amps')
  title(['Avg. Actuator Currents',str]);
  legend('rudder','elevator');
  grid on;
  zoom on;

  subplot(4,1,4)
  cla
  plot(dataDC(:,1),intcurrent1-intcurrent2-(dutyR1'*1.2)-(dutyE1'*1.2));
  ylabel('Amps')
  xlabel('Elapsed Time (s)');
  title(['All Other Current',str]);
  grid on;
  zoom on;



  if exist( 'pwrFig' ) ~= 1
    pwrFig = figure;
    winpos( position(1,:) );
  else
    figure(pwrFig);
  end
  set(pwrFig,'Name','Power Consumption Plot','DeleteFcn','clear pwrFig');


  subplot(3,1,1)
  cla
  [xx,yy] = stairs( dataNav(:,m_present_time), dataNav(:,mDepth) );
  [xx1,yy1] = stairs( dataDC(:,m_present_time), dataDC(:,cDepth) );
  plot( xx, yy, xx1, yy1 );
  if exist( 'tDepth' ) == 1
    colors = get( gca, 'ColorOrder' );
    [xx,yy] = stairs( dataDC(:,m_present_time), dataDC(:,tDepth) );
    line( xx, yy, 'Color', colors(3,:) );
  end
  set( gca, 'ydir', 'reverse' );
  title( ['Depth: Commanded-Green; Smoothed Command-Red; Measured-Blue, ' ...
        titleStr] );
%  xlabel( 'Elapsed Time (s)' );
  ylabel( 'Depth (m)' );
%legend('Meas. Depth', 'Cmded. Depth', 'Smooth Depth',0)
  zoom on
  grid on

  subplot(3,1,2)
  cla
  plot(metrabyte(:,1), metrabyte(:,current).*metrabyte(:,voltage),'r');
  hold on
  plot(dataDC(:,1),(intcurrent1-intcurrent2-(dutyR1'*1.2)- ...
     dutyE1'*1.2).*intvolt1);
  hold off
  ylabel('Watts')
  title(['Bus Power & Hotel Load',str]);
%  xlabel('Elapsed Time (s)');
  grid on;
  zoom on;

  subplot(3,1,3)
  cla
  plot(dataTC(:,1), dataTC(:,propRpm).*60/(pi*2));
%  if exist('dataSim')
%    line(dataSim(:,1), [dataSim(:,sOmega_P)*60/2/pi],'color','r');
%    legend('Nav', 'SimCmd');
%  end
  ylabel('Rev/Min')
  title(['Propeller Speed',str]);
  xlabel('Elapsed Time (s)');
  grid on;
  zoom on;


  return