%% get 1000m base of WOA 2018
clear
% load WOA2018 data
name=importdata('D:\southern_ocean\WOA2018\name.txt');
ylat_h=zeros(360,6);
thetao_hk1=zeros(19,102,6);
for nn=1:6
    tmp=ncread(['D:\southern_ocean\WOA2018\' name{nn}],'t_an');
%     lat=ncread(['D:\southern_ocean\WOA2018\' name{nn}],'lat');
%     lon=ncread(['D:\southern_ocean\WOA2018\' name{nn}],'lon');
    depth=ncread(['D:\southern_ocean\WOA2018\' name{nn}],'depth');

    yy=zeros(1,360);
    for ii=1:360
        aa=squeeze(tmp(ii,:,47));  % 47 is 1000m
        y=find(~isnan(aa));
        if ~isempty(y)
            yy(ii)=y(1);
        end
        clear y aa
    end
    yy(yy==0)=nan;


    thetao_hk=zeros(360,180,102);
    for ii=1:360
        if ~isnan(yy(ii))
            
            bb=yy(ii)-yy(2);
            if bb>=0
                thetao_hk(ii,1:end-bb,:)=tmp(ii,bb+1:end,:);
            else
                thetao_hk(ii,abs(bb)+1:end,:)=tmp(ii,1:end-abs(bb),:);
            end
            clear bb
        end
    end

    ylat_h(:,nn)=yy;

    thetao_hk(thetao_hk==0)=nan;
    tt1=squeeze(nanmean(thetao_hk,1));
    thetao_hk1(:,:,nn)=tt1(yy(2)-8:yy(2)+10,:);

    disp(nn)
end
