def grab_data(data_file, col_name, time_slice, col_name_row=3,
    time_slice_col=0, header_rows=4, record_sep='\t', min_max=False):
    """
    pulls data from a file and returns the average of a data item over a time slice
    
    data_file = text file with the data.  One row per data record
    col_name = text that identifies the column with the desired data.  This text must exactly match what is in the data file.
    time_slice is a tuple with start and end times.  The format of the times must exactly match that of the times in the data.
    time_slice_col = the column number that has the time slice data
    col_name_row = the row number that has the column names to be matched to col_name, with the row numbers starting at 1
    header_rows = the number of header rows before the data starts
    record_sep = the character(s) that separate the data items in the data record
    """
    DATA = open(data_file)
    for i in range(col_name_row - 1):
        DATA.readline()
    col_names = DATA.readline().split(record_sep)
    col_index = col_names.index(col_name)
    for i in range(header_rows - col_name_row):
        DATA.readline()
    data_items = DATA.readline().split(record_sep)
    count, data_sum = 0, 0
    while data_items[time_slice_col] < time_slice[0]:
        data_items = DATA.readline().split(record_sep)
        try:
            value = float(data_items[col_index])
            min_val = value
            max_val = value
        except ValueError:
            pass
    while data_items[time_slice_col] <= time_slice[1]:
        try:
            value = float(data_items[col_index])
            data_sum += value
            count += 1
            min_val = min(min_val, value)
            max_val = max(max_val, value)
        except ValueError:
            pass
        data_items = DATA.readline().split(record_sep)
        data_ave = data_sum / count
    if min_max:
        return data_ave, min_val, max_val
    else:
        return data_ave
