close all
clear all

path = 'X:\707976_EPBuoyPrototypeAndTesting\Deployments\2019-02-05-Deployment\DecodedResults\';

files = dir([path '2019.03.*raw.mat']);

figure

for i = 1:length(files)
    load([path files(i).name])
    idx = find(SC_Time > datenum('29-Feb-2019 00:00:00'));
    ah1 = subplot(3,1,1);
    plot(SC_Time(idx),SC_Range(idx),'b-');
    hold all

    HourlyMeanTime(i) = mean(SC_Time(idx));
    HourlyMeanPos(i) = nanmean(SC_Range(idx)); 
    HourlyMeanLoadCell(i) = nanmean(SC_LoadCell(idx));
    

    idx = find((SC_Range > 30) & (SC_Range < 30.2));
    HourlyMeanTimeAtThirty(i) = mean(SC_Time(idx));
    HourlyMeanLowerPressure(i) = mean(SC_LowerPressure(idx));
    HourlyMeanUpperPressure(i) = mean(SC_UpperPressure(idx));

    
    disp(num2str(i));
end

ah1 = subplot(3,1,1);
datetick('x');
grid on
ylabel('Piston Position (in)');
ah2 = subplot(3,1,2);
plot(HourlyMeanTime,HourlyMeanPos);
datetick('x');
grid on
ylabel('Hourly Mean Piston Position (in)');
ah3 = subplot(3,1,3);
datetick('x');
plot(HourlyMeanTime,HourlyMeanLoadCell);
ylabel('Hourly Mean Load Cell (lbs)');
grid on
ylabel('differential pressue (psi)');



linkaxes([ah1 ah2 ah3],'x');


Al = 0.25*pi*(5^2-1.5^2);
Au = 0.25*pi*(5^2);
figure
ah1 = subplot(3,1,1)
plot(HourlyMeanTimeAtThirty,HourlyMeanLowerPressure);
datetick('x');
grid on;
ah2 = subplot(3,1,2);
plot(HourlyMeanTimeAtThirty,HourlyMeanUpperPressure);
datetick('x');
grid on;
ah3 = subplot(3,1,3);
plot(HourlyMeanTimeAtThirty,HourlyMeanUpperPressure*Al-HourlyMeanLowerPressure*Au);
datetick('x');
ylabel('Net Pneumatic Force at 30"');
grid on;

linkaxes([ah1 ah2 ah3],'x');

