year=2001:2014;
lon=ncread('/Users/yangyang/Aerosol_Variaiton/IRUN/SST/dat/air.mon.mean.nc','lon');
lat=ncread('/Users/yangyang/Aerosol_Variaiton/IRUN/SST/dat/air.mon.mean.nc','lat');

SST_temp=ncread('/Users/yangyang/Aerosol_Variaiton/IRUN/SST/dat/air.mon.mean.nc','air');

OCNFRAC=ncread('/Users/yangyang/Aerosol_Variaiton/IRUN/SST/dat/land.nc','land');

for i=1:length(lon)
    for j=1:length(lat)
        if OCNFRAC(i,j)==1
            SST_temp(i,j,:)=-999;
        end
    end
end

SST_temp(:,1:13,:)=-999;
SST_temp(:,61:73,:)=-999;

SST_ANN=zeros(144,73,length(year));

for yearID=1:length(year)
    SST_ANN(:,:,yearID)=mean(SST_temp(:,:,(yearID-1+2001-1948)*12+1:(yearID-1+2001-1948)*12+12),3);
end


save('SST_NCEP.mat','SST_ANN')

nccreate('SST_NCEP.nc','Year','Dimensions',{'time',Inf},'Format','classic')
ncwrite('SST_NCEP.nc','Year', year)
ncwriteatt('SST_NCEP.nc','Year','long_name','Year')
nccreate('SST_NCEP.nc','lat','Dimensions',{'lat',length(lat)},'Format','classic')
ncwrite('SST_NCEP.nc','lat', lat)
ncwriteatt('SST_NCEP.nc','lat','units','degrees_north')
ncwriteatt('SST_NCEP.nc','lat','long_name','Latitude')
nccreate('SST_NCEP.nc','lon','Dimensions',{'lon',length(lon)},'Format','classic')
ncwrite('SST_NCEP.nc','lon', lon)
ncwriteatt('SST_NCEP.nc','lon','units','degrees_east')
ncwriteatt('SST_NCEP.nc','lon','long_name','Longitude')
nccreate('SST_NCEP.nc','SST_ANN','Dimensions',{'lon',length(lon),'lat',length(lat),'year',length(year)},'Format','classic')
ncwrite('SST_NCEP.nc','SST_ANN', SST_ANN)
ncdisp('SST_NCEP.nc')