def replaceSuffix(rawname, suffix, new_suffix):
    """Replace the suffix in a raw file name.

    Parameters
    ----------
    rawname: str
        Name of a raw input file.

    suffix: str
        Suffix (last part of root name) that is expected to be found in
        the raw file name.

    new_suffix: str
        String to replace suffix to create an output file name.

    Returns
    -------
    newname: str
        rawname with suffix replaced by new_suffix.

    Examples
    --------
    >>> print replaceSuffix("rootname_rawtag.fits", "_rawtag", "_flt")
    rootname_flt.fits

    >>> print replaceSuffix("rootname_rawtag_a.fits", "_rawtag", "_flt")
    rootname_flt_a.fits
    """
    lenraw = len(rawname)
    lensuffix = len(suffix)
    i = rawname.rfind(suffix)
    if i >= 0:
        newname = rawname[0:i] + new_suffix + rawname[i + lensuffix:]
    else:
        raise RuntimeError('File name ' + rawname +
            ' was expected to have suffix ' + suffix)
    return newname
