load ~/NC/grid.mat
load ~/Aerosol_Variaiton/IRUN/SST/ncfile/ENSO_Month_10th.mat
load ~/Aerosol_Variaiton/IRUN/PRECT/ncfile/PRECT_monthly.mat
month=1:1800;

a=sum(EN_Month);
b=sum(LL_Month);

PRECT_EN_month=zeros(144,96,a);
PRECT_LL_month=zeros(144,96,b);

n=0;
m=0;
for monthID=1:length(month)
    if EN_Month(monthID)==1
        n=n+1;
        PRECT_EN_month(:,:,n)=PRECT_MONTH(:,:,monthID);
    end
    if LL_Month(monthID)==1
        m=m+1;
        PRECT_LL_month(:,:,m)=PRECT_MONTH(:,:,monthID);
    end
end

PRECT_EN=mean(PRECT_EN_month,3);
PRECT_LL=mean(PRECT_LL_month,3);

H=zeros(length(lon),length(lat));
for i=1:length(lon)
    for j=1:length(lat)
        H(i,j)=ttest2(PRECT_EN_month(i,j,:),PRECT_LL_month(i,j,:),0.05);
    end
end

PRECT_ENSO=PRECT_EN-PRECT_LL;

save('PRECT_ENSO_composite_monthly_10th.mat','PRECT_EN','PRECT_LL','PRECT_ENSO')

nccreate('PRECT_ENSO_composite_monthly_10th.nc','lat','Dimensions',{'lat',96},'Format','classic')
ncwrite('PRECT_ENSO_composite_monthly_10th.nc','lat', lat)
ncwriteatt('PRECT_ENSO_composite_monthly_10th.nc','lat','units','degrees_north')
ncwriteatt('PRECT_ENSO_composite_monthly_10th.nc','lat','long_name','Latitude')
nccreate('PRECT_ENSO_composite_monthly_10th.nc','lon','Dimensions',{'lon',144},'Format','classic')
ncwrite('PRECT_ENSO_composite_monthly_10th.nc','lon', lon)
ncwriteatt('PRECT_ENSO_composite_monthly_10th.nc','lon','units','degrees_east')
ncwriteatt('PRECT_ENSO_composite_monthly_10th.nc','lon','long_name','Longitude')
nccreate('PRECT_ENSO_composite_monthly_10th.nc','PRECT_EN','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('PRECT_ENSO_composite_monthly_10th.nc','PRECT_EN', PRECT_EN)
nccreate('PRECT_ENSO_composite_monthly_10th.nc','PRECT_LL','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('PRECT_ENSO_composite_monthly_10th.nc','PRECT_LL', PRECT_LL)
nccreate('PRECT_ENSO_composite_monthly_10th.nc','PRECT_ENSO','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('PRECT_ENSO_composite_monthly_10th.nc','PRECT_ENSO', PRECT_ENSO)
nccreate('PRECT_ENSO_composite_monthly_10th.nc','H','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('PRECT_ENSO_composite_monthly_10th.nc','H', H)
ncdisp('PRECT_ENSO_composite_monthly_10th.nc')
