def f_computeVisibilityPeriodsWithPA(ephemeris, mjdmin, mjdmax, ra, dec, pa):
    """Returns two lists containing the start end end of each
    visibility period and a list containing a status flag

    flag = 0 visibility period fully in the search interval
    flag = -1 start of the visibility period truncated by
           the start of the search interval
    flag = -2 end of the visibility period truncated by
           the end of the search interval
    flag = +1 the search interval is fully included in
           the visibility period

    Parameters
    ----------
    ephemeris: Ephemeris
        The input ephemeris object.
    mjdmin: float
        The beginning of the search interval (modified
        Julian date). It must be covered by the ephemeris.
    mjdmax: float
        The end of the search interval (modified
        Julian date). It must be covered by the ephemeris.
    ra: float
        The input RA coordinate (equatorial coordinate, in rad).
    dec: float
        The input DEC coordinate (equatorial coordinate, in rad).
    pa: float
        The position angle.

    Example
    -------
    >>> f_computeVisibilityPeriodsWithPA(ephemeris, mjdmin, mjdmax, ra, dec,
    pa)

    Returns
    -------
    tuple
        The lists of visibility period starts and ends with flags
    """
    if ephemeris.amin > mjdmin:
        print(
            'f_computeVisibilityPeriodsWithPA(): the start of the search                 interval is not covered by the ephemeris.'
            )
        print(
            'Ephemeris start date (modified Julian date):                 {:8.5f}'
            .format(ephemeris.amin))
        print(
            'Search interval start date (modified Julian date):                 {:8.5f}'
            .format(mjdmin))
        raise ValueError
    if ephemeris.amax < mjdmax:
        print(
            'f_computeVisibilityPeriodsWithPA(): the end of the search                 interval is not covered by the ephemeris.'
            )
        print(
            'Ephemeris end date (modified Julian date):                 {:8.5f}'
            .format(ephemeris.amax))
        print(
            'Search interval end date (modified Julian date):                 {:8.5f}'
            .format(mjdmax))
        raise ValueError
    iflip = False
    wstart = mjdmin
    startList = []
    endList = []
    statusList = []
    scanningStepSize = 0.1
    span = int((mjdmax - mjdmin) / scanningStepSize)
    iflag_old = ephemeris.is_valid(mjdmin, ra, dec, pa)
    for i in range(span):
        currentdate = mjdmin + (i + 1) * scanningStepSize
        if currentdate >= mjdmax:
            currentdate = mjdmax
        iflag = ephemeris.is_valid(currentdate, ra, dec, pa)
        if iflag != iflag_old:
            if iflag:
                step = currentdate - scanningStepSize
                wstart = ephemeris.bisect_by_attitude(currentdate, step, ra,
                    dec, pa)
            else:
                step = currentdate - scanningStepSize
                wend = ephemeris.bisect_by_attitude(step, currentdate, ra,
                    dec, pa)
                startList.append(wstart)
                endList.append(wend)
                if iflip:
                    statusList.append(0)
                else:
                    statusList.append(-1)
            iflip = True
            iflag_old = iflag
    if iflag and iflip:
        startList.append(wstart)
        endList.append(currentdate)
        statusList.append(-2)
    if iflag and not iflip:
        startList.append(mjdmin)
        endList.append(mjdmax)
        statusList.append(1)
    return startList, endList, statusList
