import re


def trtype(dtype):
    """
    Translation function for data types: SQL to recarray
    RecArray dtypes:
      bytes                = b<n>, e.g. b1
      ints                 = i<n>, e.g. i2, i4, i8,
      unsigned ints        = u<n>, e.g. u1, u2, u4, u8
      floats               = f<n>, e.g. f2, f4, f8
      complex              = c<n>, e.g. c8, c16
      fixed length strings = a<n>, e.g. a10, a100
    where <n> is the number of bytes / chars, so float32=f4, float64=f8
    """

    floatRe = re.compile('^float')
    doubleRe = re.compile('^double')
    intRe = re.compile('^int')
    charRe = re.compile('^varchar\((\d+)\)')
    if floatRe.match(dtype):
        return 'f4'
    if doubleRe.match(dtype):
        return 'f8'
    if intRe.match(dtype):
        return 'i8'
    mch = charRe.match(dtype)
    if mch:
         return 'a' + mch.group(1)
    return 'f8'    # default to float64