Detect and attempt fixing double nodes in a mesh.

    The double nodes are nodes having the same coordinates
    w.r.t. precision given by `eps`.

def fix_double_nodes(coor, ngroups, conns, eps):
    """
    Detect and attempt fixing double nodes in a mesh.

    The double nodes are nodes having the same coordinates
    w.r.t. precision given by `eps`.
    """
    n_nod, dim = coor.shape
    cmap = find_map( coor, nm.zeros( (0,dim) ), eps = eps, allow_double = True )
    if cmap.size:
        output('double nodes in input mesh!')
        output('trying to fix...')

        while cmap.size:
            print cmap.size

            # Just like in Variable.equation_mapping()...
            ii = nm.argsort( cmap[:,1] )
            scmap = cmap[ii]

            eq = nm.arange( n_nod )
            eq[scmap[:,1]] = -1
            eqi = eq[eq >= 0]
            eq[eqi] = nm.arange( eqi.shape[0] )
            remap = eq.copy()
            remap[scmap[:,1]] = eq[scmap[:,0]]
            print coor.shape
            coor = coor[eqi]
            ngroups = ngroups[eqi]
            print coor.shape
            ccs = []
            for conn in conns:
                ccs.append( remap[conn] )
            conns = ccs
            cmap = find_map( coor, nm.zeros( (0,dim) ), eps = eps,
                            allow_double = True )
        output('...done')
    return coor, ngroups, conns