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

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

FSNS_EN_month=zeros(144,96,a);
FSNS_LL_month=zeros(144,96,b);

n=0;
m=0;
for monthID=1:length(month)
    if EN_Month(monthID)==1
        n=n+1;
        FSNS_EN_month(:,:,n)=FSNS_MONTH(:,:,monthID);
    end
    if LL_Month(monthID)==1
        m=m+1;
        FSNS_LL_month(:,:,m)=FSNS_MONTH(:,:,monthID);
    end
end

FSNS_EN=mean(FSNS_EN_month,3);
FSNS_LL=mean(FSNS_LL_month,3);

FSNS_ENSO=FSNS_EN-FSNS_LL;

save('FSNS_ENSO_composite_monthly.mat','FSNS_EN','FSNS_LL','FSNS_ENSO')

nccreate('FSNS_ENSO_composite_monthly.nc','lat','Dimensions',{'lat',96},'Format','classic')
ncwrite('FSNS_ENSO_composite_monthly.nc','lat', lat)
ncwriteatt('FSNS_ENSO_composite_monthly.nc','lat','units','degrees_north')
ncwriteatt('FSNS_ENSO_composite_monthly.nc','lat','long_name','Latitude')
nccreate('FSNS_ENSO_composite_monthly.nc','lon','Dimensions',{'lon',144},'Format','classic')
ncwrite('FSNS_ENSO_composite_monthly.nc','lon', lon)
ncwriteatt('FSNS_ENSO_composite_monthly.nc','lon','units','degrees_east')
ncwriteatt('FSNS_ENSO_composite_monthly.nc','lon','long_name','Longitude')
nccreate('FSNS_ENSO_composite_monthly.nc','FSNS_EN','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('FSNS_ENSO_composite_monthly.nc','FSNS_EN', FSNS_EN)
nccreate('FSNS_ENSO_composite_monthly.nc','FSNS_LL','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('FSNS_ENSO_composite_monthly.nc','FSNS_LL', FSNS_LL)
nccreate('FSNS_ENSO_composite_monthly.nc','FSNS_ENSO','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('FSNS_ENSO_composite_monthly.nc','FSNS_ENSO', FSNS_ENSO)
ncdisp('FSNS_ENSO_composite_monthly.nc')
