def read_nodes(header, fd):
    """
    Parse a .tsp file and return a dictionary of nodes, of the form
    {id:(x,y)}. If node coordinates are not given, an empty dictionary is
    returned. The actual number of nodes is in header['DIMENSION'].
    """

    nodes = {}

    node_coord_type = header['NODE_COORD_TYPE']
    display_data_type = header['DISPLAY_DATA_TYPE']
    if node_coord_type not in ['TWOD_COORDS', 'THREED_COORDS'] and \
            display_data_type not in ['COORDS_DISPLAY', 'TWOD_DISPLAY']:

                # Node coordinates are not given.
                return nodes

    dim = header['DIMENSION']
    fd.seek(0)
    k = 0
    display_data_section = False
    node_coord_section = False

    for line in fd:
        if line.strip() == "DISPLAY_DATA_SECTION":
            display_data_section = True
            continue
        elif line.strip() == "NODE_COORD_SECTION":
            node_coord_section = True
            continue

        if display_data_section:
            data = line.strip().split()
            nodes[int(data[0]) - 1] = tuple(map(float, data[1:]))
            k += 1
            if k >= dim:
                break
            continue

        elif node_coord_section:
            data = line.strip().split()
            nodes[int(data[0]) - 1] = tuple(map(float, data[1:]))
            k += 1
            if k >= dim:
                break
            continue

    return nodes