%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% PURPOSE: Plot items related to the Bluefin Li polymer batteries.
% AUTHOR:  dg, 2/18/2003
% MODS:    rsm, 4/27/2004.  Generalized this code so it works with less than
%          three batteries.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%

  if exist('bluefinBattLog') ~= 1, return, end

  nbatts = fix((size(bluefinBattLog,2)-1)/8);
  
  str = [' ',titleStr,' Plotted on ',myDate];
  PaperPosn = [.5 .5 3.75 2.5];
  FigurePosn = [5 30 815 760];
  i = 0;

  if exist( 'battFig' ) ~= 1
    battFig = figure;
  else
    figure(battFig);
  end
  set( battFig, 'Name', 'Bluefin Battery Plot', 'DeleteFcn', 'clear battFig' );
  set(gcf,'position',position)

  %nstrips = 2;
  %if exist('dataTC') == 1, nstrips = 3; end
  nstrips = 3;

  if( nbatts == 1 ) 
    bf.voltage = '[voltage_0 ]';
    bf.current = '[current_0 ]';
    bf.power   = '[Power_0 ]';
    bf.colors = 'r';

  elseif( nbatts == 2 ) 
    bf.voltage = '[voltage_0 voltage_1]';
    bf.current = '[current_0 current_1]';
    bf.power   = '[Power_0 Power_1]';
    bf.colors = 'rg';
  elseif( nbatts == 3 ) 
    bf.voltage = '[voltage_0 voltage_1 voltage_2]';
    bf.current = '[current_0 current_1 current_2]';
    bf.power   = '[Power_0 Power_1 Power_2]';
    bf.colors = 'rgb';
  end
  
  subplot(nstrips,1,1)
  plot(bluefinBattLog(:,1), bluefinBattLog(:, eval(bf.voltage) ) );
%    bf.colors ); 
  ylabel('Volts')
% xlabel('Seconds');
  title(['Bluefin Battery Voltages ',str]);
  grid on
  zoom on

  subplot(nstrips,1,2)
  plot(bluefinBattLog(:,1), bluefinBattLog(:, eval(bf.current) ));
%    bf.colors);
  ylabel('Amperes')
  title(['Bluefin Battery Currents',str]);
%  xlabel('Seconds');
  grid on;
  zoom on;
  subplot(nstrips,1,3)

  Power_0 = bluefinBattLog(:,current_0).*bluefinBattLog(:,voltage_0);
  if(nbatts >= 2)
    Power_1 = bluefinBattLog(:,current_1).*bluefinBattLog(:,voltage_1);
  end	  
  if(nbatts == 3) 
    Power_2 = bluefinBattLog(:,current_2).*bluefinBattLog(:,voltage_2);
  elseif(nbatts == 2)
    Power_2 = zeros( size(bluefinBattLog(:,current_0)) );
  elseif(nbatts == 1)
    Power_2 = zeros( size(bluefinBattLog(:,current_0)) );
    Power_1 = zeros( size(bluefinBattLog(:,current_0)) );
  end
  totalPower = Power_0+Power_1+Power_2;
  plot(bluefinBattLog(:,1), [eval(bf.power) totalPower]);
  %bf.colors); 
  ylabel('Watts')
  title(['Bluefin Batteries Power',str]);
  xlabel('Elapsed Time (s)');
  grid on;
  zoom on;



return




