def load_capcodes_dict(filename):
    """Load capcodes to dictionary."""
    capcodes = {}
    try:
        print("Loading data from '{}'".format(filename))
        with open(filename, "r") as csv_file:
            csv_list = [
                [val.strip() for val in r.split(",")] for r in csv_file.readlines()
            ]

        (_, *header), *data = csv_list
        for row in data:
            key, *values = row
            capcodes[key] = {key: value for key, value in zip(header, values)}
        print("{} records loaded".format(len(capcodes)))
    except KeyError:
        print(f"Could not parse file contents of: {filename}")
    except OSError:
        print(f"Could not open/read file: {filename}, ignore filter")

    return capcodes