close all
clear all

path = 'X:\707976 EPBuoyPrototypeAndTesting\Deployments\Nov2011 Deployment\SurfaceData\R00003\';
matfiles = dir([path 'D*.mat']);

%filenums = [1 20 27 46];
filenums = 1:length(matfiles);
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']);
    LoadDumpPower = LoadDumpCurrent.*LoadDumpVoltage;
    for j = 1:length(names)
    
        if (matfilenum == filenums(1))
            Cat_time = time;
            Cat_LoadDumpPower = LoadDumpPower;
          %eval(['Cat_' names{j} ' = ' names{j} ';']); 
        else
            Cat_time = [Cat_time time];
            Cat_LoadDumpPower = [Cat_LoadDumpPower LoadDumpPower];
          %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;
    LoadDumpPower = LoadDumpCurrent.*LoadDumpVoltage;
     disp(matfiles(matfilenum).name);
    
    %for j = 1:length(names)
       %   eval(['Cat_' names{j} ' = [Cat_' names{j} '  ' names{j} '];']); 
    %end 
    Cat_time = [Cat_time time];
    Cat_LoadDumpPower = [Cat_LoadDumpPower LoadDumpPower];

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 'Nov11_1100_PowerData'],'time','LoadDumpPower','MovingAveragePower');

