@staticmethod
def dtype_to_struct(dt, structname='mystruct', enums=None):
    """Convert a NumPy dtype object describing a record array to
        a typedef struct statement.

        The second argument is the name of the structure.
        If any of the columns are enum types, enums must
        be a dictionary with the keys the column names, and the values
        are a tuple containing the name of the enum type as the first item
        and a tuple or list of possible values as the second item.

        Parameters
        ----------
        dt : :class:`numpy.dtype`
            The dtype of a NumPy record array.
        structname : :class:`str`, optional
            The name to give the structure in the yanny file.  Defaults to
            'MYSTRUCT'.
        enums : :class:`dict`, optional
            A dictionary containing enum information.  See details above.

        Returns
        -------
        :class:`dict`
            A dictionary suitable for setting the 'symbols' dictionary of a
            new yanny object.

        Examples
        --------
        """
    dtmap = {'i2': 'short', 'i4': 'int', 'i8': 'long', 'f4': 'float', 'f8':
        'double'}
    returnenums = list()
    if enums is None:
        enums = dict()
    else:
        for e in enums:
            lines = list()
            lines.append('typedef enum {')
            for n in enums[e][1]:
                lines.append('    {0},'.format(n))
            lines[-1] = lines[-1].strip(',')
            lines.append('}} {0};'.format(enums[e][0].upper()))
            returnenums.append('\n'.join(lines))
    lines = list()
    lines.append('typedef struct {')
    for c in dt.names:
        if dt[c].kind == 'V':
            t = dt[c].subdtype[0].str[1:]
            l = dt[c].subdtype[1][0]
            s = dt[c].subdtype[0].itemsize
        else:
            t = dt[c].str[1:]
            l = 0
            s = dt[c].itemsize
        line = '    '
        if t[0] in 'SU':
            if c in enums:
                line += enums[c][0].upper()
            else:
                line += 'char'
        else:
            line += dtmap[t]
        line += ' {0}'.format(c)
        if l > 0:
            line += '[{0:d}]'.format(l)
        if t[0] in 'SU' and c not in enums:
            line += '[{0:d}]'.format(s)
        line += ';'
        lines.append(line)
    lines.append('}} {0};'.format(structname.upper()))
    return {structname.upper(): list(dt.names), 'enum': returnenums,
        'struct': ['\n'.join(lines)]}
