load ~/NC/grid.mat
load ~/Aerosol_Variaiton/IRUN/Z500/ncfile/PNA_Month.mat
load ~/Aerosol_Variaiton/IRUN/SSLT/ncfile/SSLT_monthly.mat
month=1:1800;

a=sum(PO_Month);
b=sum(NE_Month);

SSLT_PO_month=zeros(144,96,a);
SSLT_NE_month=zeros(144,96,b);

n=0;
m=0;
for monthID=1:length(month)
    if PO_Month(monthID)==1
        n=n+1;
        SSLT_PO_month(:,:,n)=SSLT_MONTH(:,:,monthID);
    end
    if NE_Month(monthID)==1
        m=m+1;
        SSLT_NE_month(:,:,m)=SSLT_MONTH(:,:,monthID);
    end
end

SSLT_PO=mean(SSLT_PO_month,3);
SSLT_NE=mean(SSLT_NE_month,3);

SSLT_PNA=SSLT_PO-SSLT_NE;


save('SSLT_PNA_composite_monthly.mat','SSLT_PO','SSLT_NE','SSLT_PNA')

nccreate('SSLT_PNA_composite_monthly.nc','lat','Dimensions',{'lat',96},'Format','classic')
ncwrite('SSLT_PNA_composite_monthly.nc','lat', lat)
ncwriteatt('SSLT_PNA_composite_monthly.nc','lat','units','degrees_north')
ncwriteatt('SSLT_PNA_composite_monthly.nc','lat','long_name','Latitude')
nccreate('SSLT_PNA_composite_monthly.nc','lon','Dimensions',{'lon',144},'Format','classic')
ncwrite('SSLT_PNA_composite_monthly.nc','lon', lon)
ncwriteatt('SSLT_PNA_composite_monthly.nc','lon','units','degrees_east')
ncwriteatt('SSLT_PNA_composite_monthly.nc','lon','long_name','Longitude')
nccreate('SSLT_PNA_composite_monthly.nc','SSLT_PO','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('SSLT_PNA_composite_monthly.nc','SSLT_PO', SSLT_PO)
nccreate('SSLT_PNA_composite_monthly.nc','SSLT_NE','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('SSLT_PNA_composite_monthly.nc','SSLT_NE', SSLT_NE)
nccreate('SSLT_PNA_composite_monthly.nc','SSLT_PNA','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('SSLT_PNA_composite_monthly.nc','SSLT_PNA', SSLT_PNA)
ncdisp('SSLT_PNA_composite_monthly.nc')
