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

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

SSLTSF_PO_month=zeros(144,96,a);
SSLTSF_NE_month=zeros(144,96,b);

n=0;
m=0;
for monthID=1:length(month)
    if PO_Month(monthID)==1
        n=n+1;
        SSLTSF_PO_month(:,:,n)=SSLTSF_MONTH(:,:,monthID);
    end
    if NE_Month(monthID)==1
        m=m+1;
        SSLTSF_NE_month(:,:,m)=SSLTSF_MONTH(:,:,monthID);
    end
end

SSLTSF_PO=mean(SSLTSF_PO_month,3);
SSLTSF_NE=mean(SSLTSF_NE_month,3);

SSLTSF_PNA=SSLTSF_PO-SSLTSF_NE;

SSLTSF_PNA(SSLTSF_PNA==0)=-999;


save('SSLTSF_PNA_composite_monthly.mat','SSLTSF_PO','SSLTSF_NE','SSLTSF_PNA')

nccreate('SSLTSF_PNA_composite_monthly.nc','lat','Dimensions',{'lat',96},'Format','classic')
ncwrite('SSLTSF_PNA_composite_monthly.nc','lat', lat)
ncwriteatt('SSLTSF_PNA_composite_monthly.nc','lat','units','degrees_north')
ncwriteatt('SSLTSF_PNA_composite_monthly.nc','lat','long_name','Latitude')
nccreate('SSLTSF_PNA_composite_monthly.nc','lon','Dimensions',{'lon',144},'Format','classic')
ncwrite('SSLTSF_PNA_composite_monthly.nc','lon', lon)
ncwriteatt('SSLTSF_PNA_composite_monthly.nc','lon','units','degrees_east')
ncwriteatt('SSLTSF_PNA_composite_monthly.nc','lon','long_name','Longitude')
nccreate('SSLTSF_PNA_composite_monthly.nc','SSLTSF_PO','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('SSLTSF_PNA_composite_monthly.nc','SSLTSF_PO', SSLTSF_PO)
nccreate('SSLTSF_PNA_composite_monthly.nc','SSLTSF_NE','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('SSLTSF_PNA_composite_monthly.nc','SSLTSF_NE', SSLTSF_NE)
nccreate('SSLTSF_PNA_composite_monthly.nc','SSLTSF_PNA','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('SSLTSF_PNA_composite_monthly.nc','SSLTSF_PNA', SSLTSF_PNA)
ncdisp('SSLTSF_PNA_composite_monthly.nc')
