Quantitative Rotational to Librational Transition in Dense H2 and D2