load ~/NC/grid.mat
load ~/Aerosol_Variaiton/IRUN/RH/ncfile/RH.mat
year=1:150;

EOF_RH_ANN=zeros(144,96);

RH_ANN_ALL=zeros(150,144*96);

n=1;
for i=1:144
    for j=1:96
        RH_ANN_ALL(:,n)=RH_ANN(i,j,:);

        n=n+1;
    end
end

[e,PC_RH_ANN,expvar_ANN] = caleof(RH_ANN_ALL,1,1);
n=1;
for i=1:144
    for j=1:96
        EOF_RH_ANN(i,j)=e(n);
        n=n+1;
    end
end


save('RH_EOF.mat','EOF_RH_ANN','PC_RH_ANN','expvar_ANN')

nccreate('RH_EOF.nc','lat','Dimensions',{'lat',96},'Format','classic')
ncwrite('RH_EOF.nc','lat', lat)
ncwriteatt('RH_EOF.nc','lat','units','degrees_north')
ncwriteatt('RH_EOF.nc','lat','long_name','Latitude')
nccreate('RH_EOF.nc','lon','Dimensions',{'lon',144},'Format','classic')
ncwrite('RH_EOF.nc','lon', lon)
ncwriteatt('RH_EOF.nc','lon','units','degrees_east')
ncwriteatt('RH_EOF.nc','lon','long_name','Longitude')
nccreate('RH_EOF.nc','EOF_RH_ANN','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('RH_EOF.nc','EOF_RH_ANN', EOF_RH_ANN)
nccreate('RH_EOF.nc','PC_RH_ANN','Dimensions',{'year',length(year)},'Format','classic')
ncwrite('RH_EOF.nc','PC_RH_ANN', PC_RH_ANN)
ncdisp('RH_EOF.nc')
