def jd2gpst(jd):
    """
    Julian date to GPS time (GPS week, GPS day of week, GPS seconds of week)
    """
    mjd = jd - 2400000.5
    gps_start_mjd = 44243
    gps_week = (int(mjd) - gps_start_mjd - 1)//7
    if mjd - gps_start_mjd - 1 < 0:
        gps_week -= 1
    gps_sow = (mjd - (gps_start_mjd + gps_week*7 + 1))*86400
    if mjd - gps_start_mjd < 0 and gps_sow >= 604800:
        gps_sow = gps_sow - 604800
    gps_dow = int(gps_sow // 86400)
    return gps_week, gps_dow, gps_sow