load ~/NC/grid.mat
load ~/Aerosol_Variaiton/IRUN/SST/ncfile/ENSO_Month.mat
load ~/Aerosol_Variaiton/IRUN/FSNTC/ncfile/FSNTC_monthly.mat
month=1:1800;

FSNTC_EN_month=zeros(144,96,180);
FSNTC_LL_month=zeros(144,96,180);

n=0;
m=0;
for monthID=1:length(month)
    if EN_Month(monthID)==1
        n=n+1;
        FSNTC_EN_month(:,:,n)=FSNTC_MONTH(:,:,monthID);
    end
    if LL_Month(monthID)==1
        m=m+1;
        FSNTC_LL_month(:,:,m)=FSNTC_MONTH(:,:,monthID);
    end
end

FSNTC_EN=mean(FSNTC_EN_month,3);
FSNTC_LL=mean(FSNTC_LL_month,3);

H=zeros(144,96);
for i=1:144
    for j=1:96
        H(i,j)=ttest2(FSNTC_EN_month(i,j,:),FSNTC_LL_month(i,j,:),0.05);
    end
end

FSNTC_ENSO=FSNTC_EN-FSNTC_LL;

save('FSNTC_ENSO_composite_monthly.mat','FSNTC_EN','FSNTC_LL','FSNTC_ENSO')

nccreate('FSNTC_ENSO_composite_monthly.nc','lat','Dimensions',{'lat',96},'Format','classic')
ncwrite('FSNTC_ENSO_composite_monthly.nc','lat', lat)
ncwriteatt('FSNTC_ENSO_composite_monthly.nc','lat','units','degrees_north')
ncwriteatt('FSNTC_ENSO_composite_monthly.nc','lat','long_name','Latitude')
nccreate('FSNTC_ENSO_composite_monthly.nc','lon','Dimensions',{'lon',144},'Format','classic')
ncwrite('FSNTC_ENSO_composite_monthly.nc','lon', lon)
ncwriteatt('FSNTC_ENSO_composite_monthly.nc','lon','units','degrees_east')
ncwriteatt('FSNTC_ENSO_composite_monthly.nc','lon','long_name','Longitude')
nccreate('FSNTC_ENSO_composite_monthly.nc','FSNTC_EN','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('FSNTC_ENSO_composite_monthly.nc','FSNTC_EN', FSNTC_EN)
nccreate('FSNTC_ENSO_composite_monthly.nc','FSNTC_LL','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('FSNTC_ENSO_composite_monthly.nc','FSNTC_LL', FSNTC_LL)
nccreate('FSNTC_ENSO_composite_monthly.nc','FSNTC_ENSO','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('FSNTC_ENSO_composite_monthly.nc','FSNTC_ENSO', FSNTC_ENSO)
nccreate('FSNTC_ENSO_composite_monthly.nc','H','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('FSNTC_ENSO_composite_monthly.nc','H', H)
ncdisp('FSNTC_ENSO_composite_monthly.nc')
