A new approach to automatic shimming