% Load data for profile 2
% Extract the measurement depths, temp and salinity into a vector
% "Depths","Temp", and "Salt"
bin = 1; % bin size in meters
binDepth = (minDepth:bin:maxDepth)'; % Sequence of depth bins
bin_vec1 = round(minDepth):bin:round(maxDepth);
bin_vec2 = round(minDepth)+1:bin:round(maxDepth)+1;
M = length(Depth); % number of elements
binTemp = zeros(1,length(bin_vec1)); % zero vector
binSalt = zeros(1,length(bin_vec1)); % zero vector
for kk = 1:length(bin_vec1)
if (Depth(ii) >= bin_vec1(kk)) & (Depth(ii) < bin_vec2(kk)) % assign depth to bins
binTemp(kk) = mean(Temp(ii));
binSalt(kk) = mean(Salt(ii));
% Plot the original profile with the bin average profile
plot(Temp,Depth,'linewidth',2)
plot(binTemp(1:end-1),binDepth,'linewidth',2)
xlabel('Temperature [deg. C]')
legend('original','bin averaged','location','southwest')
set(gca,'ydir','reverse','linewidth',2,'fontsize',20)
plot(Salt,Depth,'linewidth',2)
plot(binSalt(1:end-1),binDepth,'linewidth',2)
set(gca,'ydir','reverse','linewidth',2,'fontsize',20)
% Estimate as a first metric the freshwater component
F = sum((S_r-binSalt)./S_r)