Contour binning code, http://www-xray.ast.cam.ac.uk/papers/contbin/