load ~/NC/grid
month=1:1800;

FSNS_temp=ncread('~/Aerosol_Variaiton/IRUN/read_nc/ncfile/read_nc_FSNS.nc','FSNS');

FSNS_MONTH=zeros(144,96,1800);

% Change size
for i=1:144
    for j=1:96
        n=0;
        for yearID=1:150
            for monthID=1:12
                n=n+1;
                FSNS_MONTH(i,j,n)=FSNS_temp(i,j,monthID,yearID);
            end
        end
    end
end

save('FSNS_monthly.mat','FSNS_MONTH')

nccreate('FSNS_monthly.nc','Month','Dimensions',{'time',Inf},'Format','classic')
ncwrite('FSNS_monthly.nc','Month', month)
ncwriteatt('FSNS_monthly.nc','Month','long_name','Month')
nccreate('FSNS_monthly.nc','lat','Dimensions',{'lat',96},'Format','classic')
ncwrite('FSNS_monthly.nc','lat', lat)
ncwriteatt('FSNS_monthly.nc','lat','units','degrees_north')
ncwriteatt('FSNS_monthly.nc','lat','long_name','Latitude')
nccreate('FSNS_monthly.nc','lon','Dimensions',{'lon',144},'Format','classic')
ncwrite('FSNS_monthly.nc','lon', lon)
ncwriteatt('FSNS_monthly.nc','lon','units','degrees_east')
ncwriteatt('FSNS_monthly.nc','lon','long_name','Longitude')
nccreate('FSNS_monthly.nc','FSNS_MONTH','Dimensions',{'lon',144,'lat',96,'month',length(month)},'Format','classic')
ncwrite('FSNS_monthly.nc','FSNS_MONTH', FSNS_MONTH)
ncdisp('FSNS_monthly.nc')