load ~/NC/grid.mat
load ~/Aerosol_Variaiton/ERUN/SST/ncfile/ENSO_Month.mat
load ~/Aerosol_Variaiton/ERUN/SSLTSF/ncfile/SSLTSF_monthly.mat
month=1:1800;

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

SSLTSF_EN_month=zeros(144,96,a);
SSLTSF_LL_month=zeros(144,96,b);

n=0;
m=0;
for monthID=1:length(month)
    if EN_Month(monthID)==1
        n=n+1;
        SSLTSF_EN_month(:,:,n)=SSLTSF_MONTH(:,:,monthID);
    end
    if LL_Month(monthID)==1
        m=m+1;
        SSLTSF_LL_month(:,:,m)=SSLTSF_MONTH(:,:,monthID);
    end
end

SSLTSF_EN=mean(SSLTSF_EN_month,3);
SSLTSF_LL=mean(SSLTSF_LL_month,3);

SSLTSF_ENSO=SSLTSF_EN-SSLTSF_LL;


load ~/NC/area_1.9_2.5.mat
IR=sum(sum(SSLTSF_ENSO(37:59,37:60).*area(37:59,37:60),2),1)/sum(sum(area(37:59,37:60),1),2);
TP=sum(sum(SSLTSF_ENSO(59:97,37:60).*area(59:97,37:60),2),1)/sum(sum(area(59:97,37:60),1),2);
load ~/Aerosol_Variaiton/IRUN/SSLTSF/ncfile/SSLTSF.mat
temp_IR=sum(sum(mean(SSLTSF_ANN(37:59,37:60,:),3).*area(37:59,37:60),2),1)/sum(sum(area(37:59,37:60),1),2);
temp_TP=sum(sum(mean(SSLTSF_ANN(59:97,37:60,:),3).*area(59:97,37:60),2),1)/sum(sum(area(59:97,37:60),1),2);
IR_ratio=IR/temp_IR*100;
TP_ratio=TP/temp_TP*100;


save('SSLTSF_ENSO_composite_monthly.mat','SSLTSF_EN','SSLTSF_LL','SSLTSF_ENSO')

nccreate('SSLTSF_ENSO_composite_monthly.nc','lat','Dimensions',{'lat',96},'Format','classic')
ncwrite('SSLTSF_ENSO_composite_monthly.nc','lat', lat)
ncwriteatt('SSLTSF_ENSO_composite_monthly.nc','lat','units','degrees_north')
ncwriteatt('SSLTSF_ENSO_composite_monthly.nc','lat','long_name','Latitude')
nccreate('SSLTSF_ENSO_composite_monthly.nc','lon','Dimensions',{'lon',144},'Format','classic')
ncwrite('SSLTSF_ENSO_composite_monthly.nc','lon', lon)
ncwriteatt('SSLTSF_ENSO_composite_monthly.nc','lon','units','degrees_east')
ncwriteatt('SSLTSF_ENSO_composite_monthly.nc','lon','long_name','Longitude')
nccreate('SSLTSF_ENSO_composite_monthly.nc','SSLTSF_EN','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('SSLTSF_ENSO_composite_monthly.nc','SSLTSF_EN', SSLTSF_EN)
nccreate('SSLTSF_ENSO_composite_monthly.nc','SSLTSF_LL','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('SSLTSF_ENSO_composite_monthly.nc','SSLTSF_LL', SSLTSF_LL)
nccreate('SSLTSF_ENSO_composite_monthly.nc','SSLTSF_ENSO','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('SSLTSF_ENSO_composite_monthly.nc','SSLTSF_ENSO', SSLTSF_ENSO)
ncdisp('SSLTSF_ENSO_composite_monthly.nc')
