% The next step will be to use our bin average profile data of potential temperature, absolute salinity,
% and potential density to estimate the potential temperature maximum below the surface mixed layer (SML)
% as defined by the bin above the first stability maximum N2max
load /Users/fbenz/Desktop/PhD/courses/1sem/arctic_seminar/9HW/bin_av_data_profile31_binsize1_zSML.mat
plot(binSA,binDepth,'linewidth',2)
xlabel('Absolute Salinity [ppt]')
set(gca,'ydir','reverse','linewidth',2,'fontsize',15)
plot(binCT,binDepth,'linewidth',2)
xlabel('Conservative Temperature [deg. C]')
set(gca,'ydir','reverse','linewidth',2,'fontsize',15)
plot(binP,binDepth,'linewidth',2)
xlabel('Pressure [dbar]')
set(gca,'ydir','reverse','linewidth',2,'fontsize',15)
[N2, p_mid] = gsw_Nsquared(binSA,binCT,binP);
plot(N2(1,2:end),p_mid(1,2:end),'linewidth',2)
b = hline(zSML,'linewidth',2);
set(gca,'ydir','reverse','linewidth',2,'fontsize',15)
% What is the depth and salinity of the potential temperature maximum Tmax, below the depth of the first
ind_maxN2 = find(N2 == maxN2); % index of the first stability maximum
% Pot. temperature maximum (Tmax), below the first stability maximum
Tmax = max(binPT(ind_maxN2+1:end)) % +1 bin
ind_Tmax = find(binPT == Tmax);
% Depth and salinity at Tmax
depth_Tmax = binDepth(ind_Tmax)
SA_Tmax = binSA(ind_Tmax)