load ~/NC/grid.mat
load ~/Aerosol_Variaiton/IRUN/AOD/ncfile/AOD_monthly.mat
month=1:1800;

EOF_AOD_MONTH=zeros(144,96);
AOD_ALL_MONTH=zeros(length(month),144*96);

n=1;
for i=41:105
    for j=59:81
%    for j=17:80
        AOD_ALL_MONTH(:,n)=AOD_MONTH(i,j,:);
        n=n+1;
    end
end

[e,PC_AOD_MONTH,expvar_MONTH] = caleof(AOD_ALL_MONTH,2,1);
n=1;
for i=41:105
    for j=59:81
%    for j=17:80
        EOF_AOD_MONTH(i,j)=e(n);
        n=n+1;
    end
end

save('AOD_EOF_monthly_NP.mat','EOF_AOD_MONTH','PC_AOD_MONTH','expvar_MONTH')

nccreate('AOD_EOF_monthly_NP.nc','lat','Dimensions',{'lat',96},'Format','classic')
ncwrite('AOD_EOF_monthly_NP.nc','lat', lat)
ncwriteatt('AOD_EOF_monthly_NP.nc','lat','units','degrees_north')
ncwriteatt('AOD_EOF_monthly_NP.nc','lat','long_name','Latitude')
nccreate('AOD_EOF_monthly_NP.nc','lon','Dimensions',{'lon',144},'Format','classic')
ncwrite('AOD_EOF_monthly_NP.nc','lon', lon)
ncwriteatt('AOD_EOF_monthly_NP.nc','lon','units','degrees_east')
ncwriteatt('AOD_EOF_monthly_NP.nc','lon','long_name','Longitude')
nccreate('AOD_EOF_monthly_NP.nc','EOF_AOD_MONTH','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('AOD_EOF_monthly_NP.nc','EOF_AOD_MONTH', EOF_AOD_MONTH)
nccreate('AOD_EOF_monthly_NP.nc','PC_AOD_MONTH','Dimensions',{'month',length(month)},'Format','classic')
ncwrite('AOD_EOF_monthly_NP.nc','PC_AOD_MONTH', PC_AOD_MONTH(2,:))
ncdisp('AOD_EOF_monthly_NP.nc')
