def read_array(filename):
    """Reads an array from a file.

    The first line must be a header with labels and units in a particular
    format. 
    """
    unused_, filetype = os.path.splitext(filename)
    fo = open(filename, "rU")
    try:
        if filetype == ".txt":
            header = map(eval, fo.readline().split("\t"))
            a = numpy.fromfile(fo, dtype="f8", sep="\n\t")
        elif filetype == ".csv":
            header = map(str.strip, fo.readline().split(","))
            a = numpy.fromiter(_ReadCSV(fo), numpy.float64)
        elif filetype == ".dat": # gnuplot style data
            line1 = fo.readline()[2:].split("\t")
            try:
                header = map(eval, line1)
            except (__HOLE__, SyntaxError): # assume no header line
                header = line1
                fo.seek(0)
            a = numpy.fromfile(fo, dtype="f8", sep="\n")
        else:
            raise ValueError(
                "read_array: Invalid file type. need .txt, .csv, or .dat (got %r)." % 
                filetype)
    finally:
        fo.close()
    # Data may have SCPI NAN or INF values in it. Convert to numpy
    # equivalents.
    a = numpy.fromiter(itertools.imap(check_value, a), numpy.float64)
    a.shape = (-1, len(header))
    return header, a
dataset/ETHPy150Open kdart/pycopia/QA/pycopia/dataset.py/read_array