close all
clear all

path = 'X:\707976 EPBuoyPrototypeAndTesting\Deployments\Nov2011 Deployment\SurfaceData\R00000\';
matfiles = dir([path 'D*.mat']);

filenums = [1 20 27 46];
filenums = 20;
for matfilenum = filenums  %1:length(matfiles)
    matfilenum
    load([path matfiles(matfilenum).name])
    LoadDumpCurrent = LoadDumpCurrent/10;
    
    disp(['Filename = ' matfiles(matfilenum).name]);
    disp(['Mean PTO Power = ' num2str(mean(LoadDumpVoltage.*LoadDumpCurrent)) ' W']);
    
    for j = 1:length(names)
    
        if (matfilenum == filenums(1))
          eval(['Cat_' names{j} ' = ' names{j} ';']); 
        else
          eval(['Cat_' names{j} ' = [Cat_' names{j} '  ' names{j} '];']); 
        end
    end 
end


%path = 'X:\707976 EPBuoyPrototypeAndTesting\Deployments\Nov2011 Deployment\SurfaceData\R00000\';
%matfiles = dir([path 'D*.mat']);

%for matfilenum = 1:length(matfiles)
 %   load([path matfiles(matfilenum).name])
  %  LoadDumpCurrent = LoadDumpCurrent/10;
    
   % disp(matfiles(matfilenum).name);
    
   % for j = 1:length(names)
    %      eval(['Cat_' names{j} ' = [Cat_' names{j} '  ' names{j} '];']); 
   % end 
%end


for j = 1:length(names)
              eval([names{j} ' = Cat_' names{j} ';']); 
              eval(['clear Cat_' names{j} ';']); 
end 



LoadDumpPower = LoadDumpVoltage.*LoadDumpCurrent;

mean(LoadDumpPower)

windowSize = 900;
MovingAveragePower = filtfilt(ones(1,windowSize)/windowSize,1,LoadDumpPower);
max(MovingAveragePower)

figure
ah1 = subplot(3,1,1);
plot(time-time(1),LoadDumpVoltage);
ah2 = subplot(3,1,2);
plot(time-time(1),LoadDumpCurrent);
ah3 = subplot(3,1,3);
plot(time-time(1),LoadDumpPower,time-time(1),MovingAveragePower,'r');

linkaxes([ah1 ah2 ah3],'x');


figure
plot(time-time(1),LoadDumpPower,time-time(1),MovingAveragePower,'r');
xlabel('time (s)');
ylabel('Electrical Power (W)');

save([path 'Nov10_0900_PowerD'],'time','LoadDumpPower','MovingAveragePower');

