  NASA's Interface Region Imaging Spectrograph (IRIS) small explorer mission
will study how the solar atmosphere is energized. IRIS contains an imaging
spectrograph that covers the Mg II h&k lines as well as a slit-jaw imager
centered at Mg II k. Understanding the observations requires forward modeling
of Mg II h&k line formation from 3D radiation-MHD models.
  We compute the vertically emergent h&k intensity from a snapshot of a dynamic
3D radiation-MHD model of the solar atmosphere, and investigate which
diagnostic information about the atmosphere is contained in the synthetic line
profiles. We find that the Doppler shift of the central line depression
correlates strongly with the vertical velocity at optical depth unity, which is
typically located less than 200 km below the transition region (TR). By
combining the Doppler shifts of the h and the k line we can retrieve the sign
of the velocity gradient just below the TR. The intensity in the central line
depression is anticorrelated with the formation height, especially in subfields
of a few square Mm. This intensity could thus be used to measure the spatial
variation of the height of the transition region. The intensity in the
line-core emission peaks correlates with the temperature at its formation
height, especially for strong emission peaks. The peaks can thus be exploited
as a temperature diagnostic. The wavelength difference between the blue and red
peaks provides a diagnostic of the velocity gradients in the upper
chromosphere. The intensity ratio of the blue and red peaks correlates strongly
with the average velocity in the upper chromosphere. We conclude that the Mg II
h&k lines are excellent probes of the very upper chromosphere just below the
transition region, a height regime that is impossible to probe with other
spectral lines.
