%% sst
clear all;close all;
sst0=ncread('~/tools/grids/tnx1v1/relax/PHC3.0/20111117/sst_clim_phc3.0.nc','sst');
sst1=ncread('~/output/20CR/NOI20C_sr10m60d28/sim-clm/sst/NOI20C_sr10m60d28_micom_hm_sst_YR_0634-0693_MM_all.nc','sst');
sst2=ncread('~/output/20CR/NOIIA_T62_tn11_sr10m60d_01/sim-clm/sst/NOIIA_T62_tn11_sr10m60d_01_micom_hm_sst_YR_0241-0300_MM_all.nc','sst');
sst0=mean(sst0,3);
sst1=sst1-sst0;
sst2=sst2-sst0;

[kx ky]=size(sst1);
sst1=reshape(sst1,kx*ky,[]);
sst2=reshape(sst2,kx*ky,[]);

sst1(isnan(sst1))=[];
sst2(isnan(sst2))=[];

display('corr sst');
corr(sst1,sst2)

%% sss
% clear all;close all;
sss0=ncread('~/tools/inputdata/ocn/micom/tnx1v1/20120120/sss_clim_core.nc','sss');
sss1=ncread('~/output/20CR/NOI20C_sr10m60d28/sim-clm/sss/NOI20C_sr10m60d28_micom_hm_sss_YR_0634-0693_MM_all.nc','sss');
sss2=ncread('~/output/20CR/NOIIA_T62_tn11_sr10m60d_01/sim-clm/sss/NOIIA_T62_tn11_sr10m60d_01_micom_hm_sss_YR_0241-0300_MM_all.nc','sss');
sss0=mean(sss0,3);
sss1=sss1-sss0;
sss2=sss2-sss0;

[kx ky]=size(sss1);
sss1=reshape(sss1,kx*ky,[]);
sss2=reshape(sss2,kx*ky,[]);

sss1(isnan(sss1))=[];
sss2(isnan(sss2))=[];
display('corr sss');
corr(sss1,sss2)

%% ssh
% clear all;close all;
ssh10=ncread('~/output/20CR/NOI20C_sr10m60d28/sim-clm/sealv/NOI20C_sr10m60d28_micom_hm_sealv_YR_0634_MM_all.nc','sealv');
ssh1=ncread('~/output/20CR/NOI20C_sr10m60d28/sim-clm/sealv/NOI20C_sr10m60d28_micom_hm_sealv_YR_0634-0693_MM_all.nc','sealv');

ssh20=ncread('~/output/20CR/NOIIA_T62_tn11_sr10m60d_01/sim-clm/sealv/NOIIA_T62_tn11_sr10m60d_01_micom_hm_sealv_YR_0241_MM_all.nc','sealv');
ssh2=ncread('~/output/20CR/NOIIA_T62_tn11_sr10m60d_01/sim-clm/sealv/NOIIA_T62_tn11_sr10m60d_01_micom_hm_sealv_YR_0241-0300_MM_all.nc','sealv');

nanidx=find(ssh1>3);
ssh1(nanidx)=NaN;
ssh2(nanidx)=NaN;

ssh1=ssh1-ssh10;
ssh2=ssh2-ssh20;

[kx ky]=size(ssh1);
ssh1=reshape(ssh1,kx*ky,[]);
ssh2=reshape(ssh2,kx*ky,[]);

ssh1(isnan(ssh1))=[];
ssh2(isnan(ssh2))=[];
display('corr ssh');
corr(ssh1,ssh2)