Hamiltonian formulation of Riemann ellipsoid dynamics