%--------------------------------------------------------------------------
%
% PURPOSE: Compute average speed U, prop speed omega, power, and
% related quantities on a specified time interval.
%
% Auv data must be present on the stack.
%
% AUTHOR:  Rob McEwen
% DATE:    02/3/27
%
% All units in mks.
%
%--------------------------------------------------------------------------
%
  units;
% 
% if( exist('spd.t0') ~=1 ) disp('spd.t0 not defined');end
% if( exist('spd.t1') ~=1 ) disp('spd.t1 not defined');end
%
% Find the specified interval
%
  indxD = find( dataDvl(:,1) > spd.t0 & dataDvl(:,1) < spd.t1 );
  indxT = find( dataTC(:,1)  > spd.t0 & dataTC(:,1)  < spd.t1 );
%
% Fit a line with the least-square error:
%
  coefDvl = polyfit( dataDvl(indxD,1),WatVelMag(indxD),1);
%
% Compute the stats
%
  spd.Ubar = mean(WatVelMag(indxD));
  spd.Usig =  std(WatVelMag(indxD));
  spd.omega= mean(dataTC(indxT,propRpm))/rpm2rps;
  spd.ratio= spd.omega/spd.Ubar;
  spd.PropPower= mean(Powp(indxT));
  spd
%
  figure(15);
  subplot(3,1,1)
% plot(dataDvl(indxD,1),...
%      [WatVelMag(indxD) dataDvl(indxD,1)*coefDvl(1)+coefDvl(2) ...
%      ones(dataDvl(indxD),1)*spd.Ubar])
  plot(dataDvl(indxD,1),...
       [WatVelMag(indxD), dataDvl(indxD,1)*coefDvl(1)+coefDvl(2), ...
	ones(size(dataDvl(indxD,1)))*spd.Ubar])
  grid on
  xlabel('Seconds')
  ylabel('Speed, meters/sec')
  subplot(3,1,2)
  plot(dataTC(indxT,1), dataTC(indxT,propRpm)/rpm2rps)
  xlabel('Seconds')
  ylabel('Propeller Speed, Rev/Min')
  grid on
  subplot(3,1,3)
  plot(dataTC(indxT,1), ...
       [Powp(indxT) Powh(indxT) ones(length(indxT))*spd.PropPower])
  xlabel('Seconds')
  ylabel('Watts, P & H')
  grid on
  return
