clear all
close all

fileName(1) = "\\atlas\ProjectLibrary\CPF\ICM\Calcs\M1 Buoy_deep water\Extreme Currents\1998_Feb_17_NorthSouth.csv";
fileName(2) = "\\atlas\ProjectLibrary\CPF\ICM\Calcs\M1 Buoy_deep water\Extreme Currents\1998_Feb_17_EastWest.csv";
fileName(3) = "\\atlas\ProjectLibrary\CPF\ICM\Calcs\M1 Buoy_deep water\Extreme Currents\1998_Jul_7_NorthSouth.csv";
fileName(4) = "\\atlas\ProjectLibrary\CPF\ICM\Calcs\M1 Buoy_deep water\Extreme Currents\1998_Jul_7_EastWest.csv";

allAccels = [];

profileIndex = 1;
for i=1:length(fileName)
    disp(['Processing file: ' fileName(i)])
        
    t = readtable(string(fileName(i)));
    temp = cell2mat(t.Var1(9,:));
    temp = replace(temp, ',', ' ');
    depths = sscanf(temp, '%f');
    profilerVeloc = 0.1;     %10 cm/sec
    sampleTimes = depths ./ profilerVeloc;
    
    for j=10:11
        profile(profileIndex).depths = depths;
        if(contains(fileName(i), 'NorthSouth'))
            profile(profileIndex).direction = 'NorthSouth';
        elseif(contains(fileName(i), 'EastWest'))
            profile(profileIndex).direction = 'EastWest';
        else
            profile(profileIndex).direction = 'Unknown';
        end
        
        temp = t.Var1(j,:);
        a = replace(temp, '-1.E+34', 'NaN');
        b = split(a, ',');
        profile(profileIndex).date = cellstr(b(1));
        c = b(2:length(b));
        profile(profileIndex).vel = str2double(c) ./ 100.0; %convert to m/sec
        
        dT = diff(sampleTimes);
        dVel = diff(profile(profileIndex).vel);
        accel = dVel ./ dT;
        profile(profileIndex).acc = accel;
        allAccels = [allAccels accel'];
        figure
        plotyy(sampleTimes, profile(profileIndex).vel, ...
            sampleTimes(1:(length(sampleTimes) - 1)), profile(profileIndex).acc)
        title(string(fileName(i)))
        legend('Velocity (m/sec)', 'Acceleration ( m/sec^2)')
        grid on
        profileIndex = profileIndex + 1;
    end
end

figure
histogram(allAccels, 51)


