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_DTVERT.nc','QRS');
QRS_DJF=zeros(96,30,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_DTVERT.nc','QRL');
QRL_DJF=zeros(96,30,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_DTVERT.nc','DTV');
DTV_DJF=zeros(96,30,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_DTVERT.nc','DTCOND');
DTCOND_DJF=zeros(96,30,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('DTVERT.mat','QRS_DJF','QRL_DJF','DTV_DJF','DTCOND_DJF')

nccreate('DTVERT.nc','Year','Dimensions',{'time',Inf},'Format','classic')
ncwrite('DTVERT.nc','Year', year)
ncwriteatt('DTVERT.nc','Year','long_name','Year')
nccreate('DTVERT.nc','lat','Dimensions',{'lat',96},'Format','classic')
ncwrite('DTVERT.nc','lat', lat)
ncwriteatt('DTVERT.nc','lat','units','degrees_north')
ncwriteatt('DTVERT.nc','lat','long_name','Latitude')
nccreate('DTVERT.nc','lev','Dimensions',{'lev',30},'Format','classic')
ncwrite('DTVERT.nc','lev', lev)
nccreate('DTVERT.nc','QRS_DJF','Dimensions',{'lat',96,'lev',30,'year',length(year)},'Format','classic')
ncwrite('DTVERT.nc','QRS_DJF', QRS_DJF)
nccreate('DTVERT.nc','QRL_DJF','Dimensions',{'lat',96,'lev',30,'year',length(year)},'Format','classic')
ncwrite('DTVERT.nc','QRL_DJF', QRL_DJF)
nccreate('DTVERT.nc','DTV_DJF','Dimensions',{'lat',96,'lev',30,'year',length(year)},'Format','classic')
ncwrite('DTVERT.nc','DTV_DJF', DTV_DJF)
nccreate('DTVERT.nc','DTCOND_DJF','Dimensions',{'lat',96,'lev',30,'year',length(year)},'Format','classic')
ncwrite('DTVERT.nc','DTCOND_DJF', DTCOND_DJF)
ncdisp('DTVERT.nc')