Gauge theory of Riemann ellipsoids