def get_main_variable(ds):
    """
    Gets the main variable from a NetCDF4 Dataset. The main
    variable is determined as that which has the biggest shape/size.
    If there is more than one variable of the biggest size it raises
    an Exception.

    :param ds: netCDF4 Dataset object
    :return: netCDF4 Variable object
    """
    dsv = ds.variables
    sizes = {}

    for ncvar in dsv:
        sizes[ncvar] = dsv[ncvar].size

    mx_size = max(sizes.values())
    if list(sizes.values()).count(mx_size) > 1:
        raise Exception("More than one 'main' variable found in netCDF4 file.")

    return [dsv[ncvar] for ncvar, size in sizes.items() if dsv[ncvar].size == mx_size][0]