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

QRS_temp=ncread('~/Aerosol_Variaiton/DRUN/read_nc/ncfile/read_nc_DTSF.nc','QRS');
QRS_DJF=zeros(144,96,150);
QRS_DJF(:,:,1)=mean(QRS_temp(:,:,[1,2],1),3);
for yearID=2:150
    QRS_DJF(:,:,yearID)=(QRS_temp(:,:,12,yearID-1)+QRS_temp(:,:,1,yearID)+QRS_temp(:,:,2,yearID))/3;
end

QRL_temp=ncread('~/Aerosol_Variaiton/DRUN/read_nc/ncfile/read_nc_DTSF.nc','QRL');
QRL_DJF=zeros(144,96,150);
QRL_DJF(:,:,1)=mean(QRL_temp(:,:,[1,2],1),3);
for yearID=2:150
    QRL_DJF(:,:,yearID)=(QRL_temp(:,:,12,yearID-1)+QRL_temp(:,:,1,yearID)+QRL_temp(:,:,2,yearID))/3;
end

DTV_temp=ncread('~/Aerosol_Variaiton/DRUN/read_nc/ncfile/read_nc_DTSF.nc','DTV');
DTV_DJF=zeros(144,96,150);
DTV_DJF(:,:,1)=mean(DTV_temp(:,:,[1,2],1),3);
for yearID=2:150
    DTV_DJF(:,:,yearID)=(DTV_temp(:,:,12,yearID-1)+DTV_temp(:,:,1,yearID)+DTV_temp(:,:,2,yearID))/3;
end

DTCOND_temp=ncread('~/Aerosol_Variaiton/DRUN/read_nc/ncfile/read_nc_DTSF.nc','DTCOND');
DTCOND_DJF=zeros(144,96,150);
DTCOND_DJF(:,:,1)=mean(DTCOND_temp(:,:,[1,2],1),3);
for yearID=2:150
    DTCOND_DJF(:,:,yearID)=(DTCOND_temp(:,:,12,yearID-1)+DTCOND_temp(:,:,1,yearID)+DTCOND_temp(:,:,2,yearID))/3;
end


save('DTSF.mat','QRS_DJF','QRL_DJF','DTV_DJF','DTCOND_DJF')

nccreate('DTSF.nc','Year','Dimensions',{'time',Inf},'Format','classic')
ncwrite('DTSF.nc','Year', year)
ncwriteatt('DTSF.nc','Year','long_name','Year')
nccreate('DTSF.nc','lat','Dimensions',{'lat',96},'Format','classic')
ncwrite('DTSF.nc','lat', lat)
ncwriteatt('DTSF.nc','lat','units','degrees_north')
ncwriteatt('DTSF.nc','lat','long_name','Latitude')
nccreate('DTSF.nc','lon','Dimensions',{'lon',144},'Format','classic')
ncwrite('DTSF.nc','lon', lon)
ncwriteatt('DTSF.nc','lon','units','degrees_east')
ncwriteatt('DTSF.nc','lon','long_name','Longitude')
nccreate('DTSF.nc','QRS_DJF','Dimensions',{'lon',144,'lat',96,'year',length(year)},'Format','classic')
ncwrite('DTSF.nc','QRS_DJF', QRS_DJF)
nccreate('DTSF.nc','QRL_DJF','Dimensions',{'lon',144,'lat',96,'year',length(year)},'Format','classic')
ncwrite('DTSF.nc','QRL_DJF', QRL_DJF)
nccreate('DTSF.nc','DTV_DJF','Dimensions',{'lon',144,'lat',96,'year',length(year)},'Format','classic')
ncwrite('DTSF.nc','DTV_DJF', DTV_DJF)
nccreate('DTSF.nc','DTCOND_DJF','Dimensions',{'lon',144,'lat',96,'year',length(year)},'Format','classic')
ncwrite('DTSF.nc','DTCOND_DJF', DTCOND_DJF)
ncdisp('DTSF.nc')