'Write out `distortion paper`_ keywords to the given
`fits.HDUList`.'

def _write_distortion_kw(self, hdulist, dist=u'CPDIS'):

    if ((self.cpdis1 is None) and (self.cpdis2 is None)):
        return
    if (dist == u'CPDIS'):
        d_kw = str(u'DP')
        err_kw = str(u'CPERR')
    else:
        d_kw = str(u'DQ')
        err_kw = str(u'CQERR')
    def write_dist(num, cpdis):
        if (cpdis is None):
            return
        hdulist[0].header[str(u'{0}{1:d}').format(dist, num)] = (u'LOOKUP', u'Prior    distortion    function    type')
        hdulist[0].header[str(u'{0}{1:d}.EXTVER').format(d_kw, num)] = (num, u'Version    number    of    WCSDVARR    extension')
        hdulist[0].header[str(u'{0}{1:d}.NAXES').format(d_kw, num)] = (len(cpdis.data.shape), u'Number    of    independent    variables    in    distortion    function')
        for i in range(cpdis.data.ndim):
            hdulist[0].header[str(u'{0}{1:d}.AXIS.{2:d}').format(d_kw, num, (i + 1))] = ((i + 1), u'Axis    number    of    the    jth    independent    variable    in    a    distortion    function')
        image = fits.ImageHDU(cpdis.data, name=str(u'WCSDVARR'))
        header = image.header
        header[str(u'CRPIX1')] = (cpdis.crpix[0], u'Coordinate    system    reference    pixel')
        header[str(u'CRPIX2')] = (cpdis.crpix[1], u'Coordinate    system    reference    pixel')
        header[str(u'CRVAL1')] = (cpdis.crval[0], u'Coordinate    system    value    at    reference    pixel')
        header[str(u'CRVAL2')] = (cpdis.crval[1], u'Coordinate    system    value    at    reference    pixel')
        header[str(u'CDELT1')] = (cpdis.cdelt[0], u'Coordinate    increment    along    axis')
        header[str(u'CDELT2')] = (cpdis.cdelt[1], u'Coordinate    increment    along    axis')
        image.ver = int(hdulist[0].header[str(u'{0}{1:d}.EXTVER').format(d_kw, num)])
        hdulist.append(image)
    write_dist(1, self.cpdis1)
    write_dist(2, self.cpdis2)
