load('../data/OMG_data_Nares')
profi_num = size(output,1);
depth = cell(profi_num,1);
% NOTE: a small percentage of probes do not have salinity or density data!
% for these who have salinity or density data
% Quality control (step1): remove -99 data values
flag = find(T_vec==-99|S_vec==-99|rho_vec==-99);
% Quality control (step2): binning
% binning is performed by fun_binning (see the appendix)
[T_vec,S_vec,rho_vec,depth_vec] = fun_binning(T_vec,S_vec,rho_vec,depth_vec);
depth{n} = depth_vec; % m
rho{n} = rho_vec; % kg/m3
% for these who do not have salinity or density data
% Quality control (step1): remove -99 data values
% Quality control (step2): binning
% binning is performed by fun_binning (see the appendix)
[T_vec,S_vec,rho_vec,depth_vec] = fun_binning(T_vec,S_vec,rho_vec,depth_vec);
flag = find(T_org==-99|S_org==-99);
set(f,'units','centimeters','position',[1,1,9*1.2,12*1.2],'color','w')
plot(T_org,-depth_org,'linewidth',1.5)
plot(T(n,:),-depth(n,:),'linewidth',1.5)
xlabel('Temperature (^{o}C)','FontWeight','bold')
ylabel('Depth (m)','FontWeight','bold')
legend({'original','binned'},'Location','southwest')
set(gca,'FontSize',FontSize,'tickdir','out','xaxislocation','top')
set(f,'units','centimeters','position',[1,1,9*1.2,12*1.2],'color','w')
plot(S_org,-depth_org,'linewidth',1.5)
plot(S(n,:),-depth(n,:),'linewidth',1.5)
xlabel('Salinity (ppt)','FontWeight','bold')
ylabel('Depth (m)','FontWeight','bold')
legend({'original','binned'},'Location','southwest')
set(gca,'FontSize',FontSize,'tickdir','out','xaxislocation','top')
function [T_out,S_out,rho_out,depth_out] = fun_binning(T_in,S_in,rho_in,depth_in)
% Created by Tianyu Zhou, 10/27/2021, at UDel
depth_bin = 2:dz:depth_max;
nbin = size(depth_bin,2);
T_out = ones(size(depth_bin));
S_out = ones(size(depth_bin));
rho_out = ones(size(depth_bin));
T_out(n) = mean(T_in(depth_in>=low & depth_in<=high),'omitnan');
S_out(n) = mean(S_in(depth_in>=low & depth_in<=high),'omitnan');
rho_out(n) = mean(rho_in(depth_in>=low & depth_in<=high),'omitnan');