def _format_cell(val, colkeywords):
    """
    Format a cell of the table. Colkeywords can add units.
    :param val: A plain value (not a quantum)
    :param colkeywords:
    :return: A HTML representation of this cell.
    """
    out=""

    # String arrays are returned as dict, undo that for printing
    if isinstance(val, dict):
        tmpdict=numpy.array(val['array'])
        tmpdict.reshape(val['shape'])
        # Leave out quotes around strings
        numpy.set_printoptions(formatter={'all':lambda x: str(x)})
        out+=numpy.array2string(tmpdict, separator=', ')
        # Revert previous numpy print options
        numpy.set_printoptions(formatter=None)
    else:
        valtype='other'

        # Check if the column unit is like 'm' or ['m','m','m']
        singleUnit=('QuantumUnits' in colkeywords and
                    (numpy.array(colkeywords['QuantumUnits'])==numpy.array(colkeywords['QuantumUnits'])[0]).all())
        if colkeywords.get('MEASINFO',{}).get('type')=='epoch' and singleUnit:
            # Format a date/time. Use quanta for scalars, use numpy for array logic around it
            # (quanta does not support higher dimensional arrays)
            valtype='epoch'
            if isinstance(val, numpy.ndarray):
                numpy.set_printoptions(formatter={'all':lambda x: _format_date(x,colkeywords['QuantumUnits'][0])})
                out+=numpy.array2string(val,separator=', ')
                numpy.set_printoptions(formatter=None)
            else:
                out+=_format_date(val,colkeywords['QuantumUnits'][0])
        elif colkeywords.get('MEASINFO',{}).get('type')=='direction' and singleUnit and val.shape==(1,2):
                # Format one direction. TODO: extend to array of directions
                valtype='direction'
                out+="["
                part=quantity(val[0,0],'rad').formatted("TIME",precision=9)
                part=re.sub(r'(\d+):(\d+):(.*)',r'\1h\2m\3',part)
                out+=part+", "
                part=quantity(val[0,1],'rad').formatted("ANGLE",precision=9)
                part=re.sub(r'(\d+)\.(\d+)\.(.*)',r'\1d\2m\3',part)
                out+=part+"]"
        elif isinstance(val, numpy.ndarray) and singleUnit:
            # Format any array with units
            valtype='quanta'
            numpy.set_printoptions(formatter={'all':lambda x: _format_quantum(x, colkeywords['QuantumUnits'][0])})
            out+=numpy.array2string(val,separator=', ')
            numpy.set_printoptions(formatter=None)
        elif isinstance(val, numpy.ndarray):
            valtype='other'
            # Undo quotes around strings
            numpy.set_printoptions(formatter={'all':lambda x: str(x)})
            out+=numpy.array2string(val,separator=', ')
            numpy.set_printoptions(formatter=None)
        elif singleUnit:
            valtype='onequantum'
            out+=_format_quantum(val, colkeywords['QuantumUnits'][0])
        else:
            valtype='other'
            out+=str(val)

    if 'QuantumUnits' in colkeywords and valtype=='other':
        # Print units if they haven't been taken care of
        if not (numpy.array(colkeywords['QuantumUnits'])==numpy.array(colkeywords['QuantumUnits'])[0]).all():
            # Multiple different units for element in an array.
            # For now, just print the units and let the user figure out what it means
            out+=" "+str(colkeywords['QuantumUnits'])
        else:
            out+=" "+colkeywords['QuantumUnits'][0]

    # Numpy sometimes adds double newlines, don't do that
    out=out.replace('\n\n','\n')
    return out
Format a cell of the table. Colkeywords can add units.
    :param val: A plain value (not a quantum)
    :param colkeywords:
    :return: A HTML representation of this cell.