function [v,d,z]=eof(u)
%EOF  empirical orthogonal functions 
% [v,d,z]=eof(u)
% time series components stored as column vectors in u.
% v is the matrix of eigenvectors
% d is a diagonal matrix of eigenvalues
% z is the time series of mode amplitudes, stored as column vectors
%
[v,d]=eig(cov(u));
d=diag(d,0);
if abs(d(1))<abs(d(length(d))) 
      d=d(length(d):-1:1);
      v=v(:,length(d):-1:1);
end
z=u*v;
