load ~/NC/grid
load ~/NC/area_1.9_2.5.mat
year=1:150;

SSLT_temp=ncread('~/Aerosol_Variaiton/ERUN/read_nc/ncfile/read_nc_SSLT.nc','SSLT');

SSLT_ANN=zeros(144,96,150);

SSLT_ANN(:,:,:)=mean(SSLT_temp,3);

SSLT_GLOBAL_ANN=zeros(150,1);
for yearID=1:150
    SSLT_GLOBAL_ANN(yearID)=sum(sum(SSLT_ANN(:,:,yearID).*area,2),1)/sum(area(:));
end


save('SSLT.mat','SSLT_ANN','SSLT_GLOBAL_ANN')

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