def get_periodic_interval(current_time, cycle_length, rec_spacing, n_rec):
    """Used for linear interpolation between periodic time intervals.

    One common application is the interpolation of external forcings that are defined
    at discrete times (e.g. one value per month of a standard year) to the current
    time step.

    Arguments:
       current_time (float): Time to interpolate to.
       cycle_length (float): Total length of one periodic cycle.
       rec_spacing (float): Time spacing between each data record.
       n_rec (int): Total number of records available.

    Returns:
       :obj:`tuple` containing (n1, f1), (n2, f2): Indices and weights for the interpolated
       record array.

    Example:
       The following interpolates a record array ``data`` containing 12 monthly values
       to the current time step:

       >>> year_in_seconds = 60. * 60. * 24. * 365.
       >>> current_time = 60. * 60. * 24. * 45. # mid-february
       >>> print(data.shape)
       (360, 180, 12)
       >>> (n1, f1), (n2, f2) = get_periodic_interval(current_time, year_in_seconds, year_in_seconds / 12, 12)
       >>> data_at_current_time = f1 * data[..., n1] + f2 * data[..., n2]

    """
    locTime = current_time - rec_spacing * 0.5 + \
        cycle_length * (2 - round(current_time / cycle_length))
    tmpTime = locTime % cycle_length
    tRec1 = 1 + int(tmpTime / rec_spacing)
    tRec2 = 1 + tRec1 % int(n_rec)
    wght2 = (tmpTime - rec_spacing * (tRec1 - 1)) / rec_spacing
    wght1 = 1.0 - wght2
    return (tRec1 - 1, wght1), (tRec2 - 1, wght2)