def _get_read_limits(start, end, interval, info):
    """
    Given start time, end time and interval
    for reading data, determines limits to use.
    info is the dict returned by rdhdr
    end of -1 means end of record.
    If both end and interval are given, choose
    earlier limit of two.
    start and end are returned as samples.
    Example:
    >>> _get_read_limits(0, 2, -1, {'samp_count':100, 'samp_freq':10})
    (0, 20)
    >>> _get_read_limits(0, 2, 3, {'samp_count':100, 'samp_freq':10})
    (0, 20)
    >>> _get_read_limits(0, 4, 2, {'samp_count':100, 'samp_freq':10})
    (0, 20)
    >>> _get_read_limits(0, 105, -1, {'samp_count':100, 'samp_freq':10})
    (0, 100)
    >>> _get_read_limits(-1, -1, -1, {'samp_count':100, 'samp_freq':10})
    (0, 100)
    """
    start *= info['samp_freq']
    end *= info['samp_freq']
    
    if start < 0:         # If start is negative, start at 0
        start = 0
    if end < 0:           # if end is negative, use end of record
        end = info['samp_count']
    if end < start:       # if end is before start, swap them
        start, end = end, start
    interval_end = start + interval * info['samp_freq'] # end det by interval
    if interval_end < start:
        interval_end = info['samp_count']
    end = min(end, interval_end, info['samp_count']) # use earlier end
    return int(start), int(end)