def getGTI(ifd):
    """Find the most up-to-date GTI table in the input file.

    Parameters
    ----------
    ifd: pyfits HDUList object
        The pyfits file handle for the input file

    Returns
    -------
    pyfits BinTableHDU object, or None
        The GTI extension from the input file, or None if there isn't one
    """
    last_extver = 0
    hdunum = 0
    for i in range(1, len(ifd)):
        hdu = ifd[i]
        extname = hdu.header.get('extname', 'MISSING')
        if extname.upper() == 'GTI':
            extver = hdu.header.get('extver', 1)
            if extver > last_extver:
                last_extver = extver
                hdunum = i
    if hdunum < 1:
        gti_hdu = None
    else:
        gti_hdu = ifd[hdunum]
    return gti_hdu
