# 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
def read(filename, usr_variables):
    """
    Reads a Variable from a NetCDF file

    :param filename: The name (with path) of the NetCDF file to read.
    :param usr_variables: A variable (dataset) name to read from the files. The name 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 Variable instance constructed from  the input file
    """

    usr_variables = listify(usr_variables)

    try:
        datafile = Dataset(filename)
    except RuntimeError as e:
        raise IOError(str(e))

    data = {}
    for full_variable in usr_variables:
        # Split the fully qualified variable (group/variable) into group and variable
        parts = full_variable.split("/")
        groups = parts[:-1]
        variable = parts[-1]
        current_group = datafile
        for group in groups:
            current_group = current_group.groups[group]
        try:
            data[full_variable] = current_group.variables[variable]
        except:

# 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

def read(filename, usr_variables):
    """
    Reads a Variable from a NetCDF file

    :param filename: The name (with path) of the NetCDF file to read.
    :param usr_variables: A variable (dataset) name to read from the files. The name 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 Variable instance constructed from  the input file
    """

    usr_variables = listify(usr_variables)

    try:
        datafile = Dataset(filename)
    except RuntimeError as e:
        raise IOError(str(e))

    data = {}
    for full_variable in usr_variables:
        # Split the fully qualified variable (group/variable) into group and variable
        parts = full_variable.split("/")
        groups = parts[:-1]
        variable = parts[-1]
        current_group = datafile
        for group in groups:
            current_group = current_group.groups[group]
        try:
            data[full_variable] = current_group.variables[variable]
        except:

            raise InvalidVariableError(full_variable + ' could not be found in ' + filename)