How the Atmosphere Gets Heated and Cooled