def hdus_consistent(a_hdulist, b_hdulist):
    """Check that two HDUs are consistent

    Parameters
    ----------
        a_hdulist, b_hdulist: pyfits.HDUList

    Returns
    -------
    result : bool
        Return True

    Raises
    ------
    RuntimeError
        Will be raised if any of the following occur:
            - Different number of extensions
            - Corresponding extensions are of different types.

    """

    # Check that there are the same number of HDUs
    if len(a_hdulist) != len(b_hdulist):
        raise RuntimeError('HDUs have different lengths: FITS A = %d, FITS B = %d' % \
            (len(a_hdulist), len(b_hdulist)))

    # Loop through the HDUs and check types
    # If one is different, then abort.
    for index in range(len(a_hdulist)):
        if a_hdulist[index].header.get('XTENSION') != \
           b_hdulist[index].header.get('XTENSION'):
            raise RuntimeError('Extension %d different: FITS A = %s, FITS B = %s' % \
                                   (index, 
                                    a_hdulist[index].header.get('XTENSION'),
                                    b_hdulist[index].header.get('XTENSION')))

    return True