# Path: cis/exceptions.py
# class InvalidVariableError(CISError):
#     pass
# 
# Path: cis/utils.py
# def listify(item):
#     """
#     If item is not a list, return it as a list
# 
#     :param item: Item which may or may not be a list
#     :return: List
#     """
#     from types import GeneratorType
#     if isinstance(item, (tuple, GeneratorType)):
#         return list(item)
#     if not isinstance(item, list):
#         return [item]
#     return item


from cis.exceptions import InvalidVariableError
from cis.utils import listify
    from netCDF4 import Dataset
    from netCDF4 import Dataset
    from netCDF4 import MFDataset
    from cis.exceptions import InvalidVariableError
    from cis.utils import add_element_to_list_in_dict
    from netCDF4 import Dataset
    from cis.data_io.ungridded_data import Metadata
    from cis.utils import set_standard_name_if_valid
import logging
    import numpy as np
    import logging

    try:
        datafile = MFDataset(filenames, aggdim=dim)
    except RuntimeError as e:
        raise IOError(e)

    data = {}
    for variable in usr_variables:
        # Get data.
        try:
            data[variable] = datafile.variables[variable]
        except:
            raise InvalidVariableError('Variable {} not found in file {}.'.format(variable, filenames))

    return data


def read_many_files_individually(filenames, usr_variables):
    """
    Read multiple Variables from many NetCDF files manually - i.e. not with MFDataset as this doesn't always work,
    in particular for NetCDF4 files.

    :param filenames: A list of NetCDF filenames to read, or a string with wildcards.
    :param usr_variables: A list of variable (dataset) names to read from the files. The names must appear exactly as
      in in the NetCDF file. Variable names may be fully qualified NetCDF4 Hierarchical group variables in the form
      ``<group1>/<group2....>/<variable_name>``, e.g. ``AVHRR/Ch4CentralWavenumber``.
    :return: A dictionary of lists of variable instances constructed from all of the input files with the fully
      qualified variable name as the key
    """


# Path: cis/exceptions.py
# class InvalidVariableError(CISError):
#     pass
# 
# Path: cis/utils.py
# def listify(item):
#     """
#     If item is not a list, return it as a list
# 
#     :param item: Item which may or may not be a list
#     :return: List
#     """
#     from types import GeneratorType
#     if isinstance(item, (tuple, GeneratorType)):
#         return list(item)
#     if not isinstance(item, list):
#         return [item]
#     return item


# Path: cis/data_io/netcdf.py
from cis.exceptions import InvalidVariableError
from cis.utils import listify
    from netCDF4 import Dataset
    from netCDF4 import Dataset
    from netCDF4 import MFDataset
    from cis.exceptions import InvalidVariableError
    from cis.utils import add_element_to_list_in_dict
    from netCDF4 import Dataset
    from cis.data_io.ungridded_data import Metadata
    from cis.utils import set_standard_name_if_valid
import logging
    import numpy as np
    import logging


    try:
        datafile = MFDataset(filenames, aggdim=dim)
    except RuntimeError as e:
        raise IOError(e)

    data = {}
    for variable in usr_variables:
        # Get data.
        try:
            data[variable] = datafile.variables[variable]
        except:
            raise InvalidVariableError('Variable {} not found in file {}.'.format(variable, filenames))

    return data


def read_many_files_individually(filenames, usr_variables):
    """
    Read multiple Variables from many NetCDF files manually - i.e. not with MFDataset as this doesn't always work,
    in particular for NetCDF4 files.

    :param filenames: A list of NetCDF filenames to read, or a string with wildcards.
    :param usr_variables: A list of variable (dataset) names to read from the files. The names must appear exactly as
      in in the NetCDF file. Variable names may be fully qualified NetCDF4 Hierarchical group variables in the form
      ``<group1>/<group2....>/<variable_name>``, e.g. ``AVHRR/Ch4CentralWavenumber``.
    :return: A dictionary of lists of variable instances constructed from all of the input files with the fully
      qualified variable name as the key
    """


    usr_variables = listify(usr_variables)