def parseMargeStatsFile(fileName):
    """Parse getdist *.margestats file.

    Args:
        fileName (str): Name of getdist produced *.margestats file

    Returns:
        Dictionary, indexed by parameter name.

    """

    with open(fileName, "r") as inFile:
        lines=inFile.readlines()

    parKeyNames=lines[2].split()
    fitDict={}
    for line in lines[3:]:
        bits=line.split()
        parName=bits[0]
        fitDict[parName]={}
        for b, p in zip(bits[1:], parKeyNames[1:]):
            try:
                fitDict[parName][p]=float(b)
            except:
                fitDict[parName][p]=b

    return fitDict