clc;clear all;close all;
addpath('/data3/yiwen/matlab_toolbox/colorbrewer')

%========== loading data ===========%
pathi='/data3/yiwen/cesm2/JGR_ocean/Model_output/'
filename="/data3/yiwen/cesm2/JGR_ocean/Model_output/G_JRA55_test1.pop.h.0031-04.nc"
depth=ncread(filename,'moc_z');lat_depth=ncread(filename,'lat_aux_grid');
lat_aux_edge=lat_depth;depth_km=depth./1e5;

%-----------------------------
%compute MOC [SV]
%----------------------------
file='/data3/yiwen/cesm2/JGR_ocean/Model_output/CTRL/MOCyr_018401-036612.nc'
MOC=ncread(file,'MOC');
MOC_tot=squeeze(MOC(:,:,1,2,:)+MOC(:,:,2,2,:));

load([pathi,'TOPO_mask'])
%==============================
%[method1]transfer lon &lat
%==============================
ny=395;nz=61;
meanMOC=nanmean(MOC_tot,3);

MOC=meanMOC.*mask;
s1=MOC;s2=MOC;s1(s1<0)=0;s2(s2>0)=0;
lat_loc=lat_depth>=-30;
[xx,yy]=meshgrid(lat_depth(lat_loc),depth_km);

cm=flipud(brewermap(25, 'RdYlBu'));
cm2=cm(8:end,:);

set(0,'defaultfigurecolor','w')
figure(1)
pcolor(xx,yy,MOC(lat_loc,:)');shading interp;hold on
[c1,h1]=contourf(xx,yy,s1(lat_loc,:)',[-25:2:25],'Showtext','on','fill','off','Linestyle','-','LabelSpacing',600);hold on
[c2,h2]=contourf(xx,yy,s2(lat_loc,:)',[-25:2:25],'Showtext','on','fill','off','Linestyle','--','LineWidth',2,'LabelSpacing',600);
clabel(c1,h1, 'FontSize', 24, 'FontWeight','bold');clabel(c2, h2, 'FontSize', 24, 'FontWeight','bold');

set(gca,'xtick',[-30:30:90])
title('CTRL : 4~6th cycle AMOC transport [SV]','Interpreter','none');
xlabel('latitude');ylabel('depth(km)')
cbar=colorbar('location','eastoutside',...
         'colormap', colormap(cm2))
c=colorbar;c.Title.String = "SV";
set(gca,'YDir','reverse');ytickformat('%.2f')
set(gca,'Fontsize',24,'Linewidth',3,'XMinorTick','on',...
    'YMinorTick','on','TickDir','out','fontweight', 'bold');



