load ~/NC/grid
year=1:150;
load ~/Aerosol_Variaiton/IRUN/SST/ncfile/SST_EOF.mat

PC_SST=-PC_SST;
PC_SST=zscore(PC_SST);
SST_90th=prctile(PC_SST,90);
SST_10th=prctile(PC_SST,10);
EN_Year=zeros(length(year),1);
LL_Year=zeros(length(year),1);

for yearID=1:length(year);
    if PC_SST(yearID)>SST_90th
        EN_Year(yearID)=1;
    end
    if PC_SST(yearID)<SST_10th
        LL_Year(yearID)=1;
    end
end


save('ENSO_Year.mat','EN_Year','LL_Year')

nccreate('ENSO_Year.nc','Year','Dimensions',{'time',Inf},'Format','classic')
ncwrite('ENSO_Year.nc','Year', year)
ncwriteatt('ENSO_Year.nc','Year','long_name','Year')
nccreate('ENSO_Year.nc','EN_Year','Dimensions',{'year',length(year)},'Format','classic')
ncwrite('ENSO_Year.nc','EN_Year', EN_Year)
nccreate('ENSO_Year.nc','LL_Year','Dimensions',{'year',length(year)},'Format','classic')
ncwrite('ENSO_Year.nc','LL_Year', LL_Year)
ncdisp('ENSO_Year.nc')