Uniform semiclassical theory of avoided crossings