import codecs


def get_dict(modfile):
    """
    Return dictionary from file produced by make_dict

    It return dictionary with module names as keys and filenames as values.

    Parameters
    ----------
    modfile : str
        File with entries such as
        .. code-block::

           FortranFile: mo_mod1 mo_mod2

    Returns
    -------
    dict
        Dictionary with module names as keys and filenames as values,
        e.g. dict['mo_kind'] = '/path/mo_kind.f90'

    """

    odict = dict()
    of = codecs.open(modfile, 'r', encoding='utf-8')
    for line in of:
        # Dictionary lines should be like:
        # /path/filename.suffix: mo_mod1 mo_mod2
        ll = line.rstrip().split(':')
        fname = ll[0]
        mods = ll[1].strip().split(' ')
        for m in mods:
            odict[m] = fname
    of.close()

    return odict