def loadLocationHistory(filename):
    """Loads a location history from the given ``filename``. A location history
    file contains one location on each line, where the X, Y, and Z coordinates
    are separated by a space character. All remaining characters on the line
    are treated as the location comment. For example::

        1.27 4.23 1.63 this is a comment
        5.25 2.66 1.23

    Returns a list containing the location history, in the same format as that
    returned by :meth:`.LocationHistoryPanel.getHistory`.
    """

    history = []

    with open(filename, 'rt') as f:

        lines = f.read().strip().split('\n')

        for line in lines:
            line = line.strip()

            if line == '':
                continue

            try:
                parts = line.split(None, 3)
                loc   = [float(parts[0]),
                         float(parts[1]),
                         float(parts[2])]

                if len(parts) > 3: comment = parts[3]
                else:              comment = ''

                history.append((loc, comment))

            except Exception:
                raise ValueError('Invalid location history '
                                 'format: {}'.format(line))

    return history