def write_output(matrix, base_fname=None, header='', suffix='', extension='dat'
    ):
    """
    Write output matrix with a nice format, to stdout and optionally a file.

    Parameters
    ----------

    matrix : encore.utils.TriangularMatrix
        Matrix containing the values to be printed

    base_fname : str
        Basic filename for output. If None, no files will be written, and
        the matrix will be just printed on standard output

    header : str
        Text to be written just before the matrix

    suffix : str
        String to be concatenated to basename, in order to get the final
        file name

    extension : str
        Extension for the output file

    """
    if base_fname is not None:
        fname = base_fname + '-' + suffix + '.' + extension
    else:
        fname = None
    matrix.square_print(header=header, fname=fname)
