# Path: rvic/core/log.py
# LOG_NAME = 'rvic'
# 
# Path: rvic/core/share.py
# NC_DOUBLE = 'f8'
# 
# NC_INT = 'i4'
# 
# NC_CHAR = 'S1'
# 
# FILLVALUE_F = default_fillvals[NC_DOUBLE]
# 
# class NcGlobals(object):
#     def __init__(self,
#                  title=None,
#                  casename=None,
#                  casestr=None,
#                  history='Created: {}'.format(time_mod.ctime(time_mod.time())),
#                  institution='University of Washington',
#                  source=sys.argv[0],
#                  references='Based on the initial model of Lohmann, et al., '
#                             '1996, Tellus, 48(A), 708-721',
#                  comment='Output from the RVIC Streamflow Routing Model.',
#                  Conventions='CF-1.6',
#                  RvicPourPointsFile=None,
#                  RvicFdrFile=None,
#                  RvicUHFile=None,
#                  RvicDomainFile=None,
#                  version=None,
#                  hostname=None,
#                  username=None):
# 
#         self.atts = OrderedDict()
# 
#         if title is not None:
#             self.atts['title'] = title
# 
#         if comment is not None:
#             self.atts['comment'] = comment
# 
#         if Conventions is not None:
#             self.atts['Conventions'] = Conventions
# 
#         if history is not None:
#             self.atts['history'] = history
# 
#         if source is not None:
#             self.atts['source'] = source
# 
#         if institution is not None:
#             self.atts['institution'] = institution
# 
#         if hostname is not None:
#             self.atts['hostname'] = hostname
#         else:
#             self.atts['hostname'] = socket.gethostname()
# 
#         if username is not None:
#             self.atts['username'] = username
#         else:
#             self.atts['username'] = getuser()
# 
#         if casename is not None:
#             self.atts['casename'] = casename
# 
#         if casestr is not None:
#             self.atts['casestr'] = casestr
# 
#         if references is not None:
#             self.atts['references'] = references
# 
#         if version is not None:
#             self.atts['version'] = version
#         else:
#             try:
#                 from rvic import version
#                 self.atts['version'] = version.short_version
#             except ImportError:
#                 self.atts['version'] = 'unknown'
# 
#         if RvicPourPointsFile is not None:
#             self.atts['RvicPourPointsFile'] = RvicPourPointsFile
# 
#         if RvicUHFile is not None:
#             self.atts['RvicUHFile'] = RvicUHFile
# 
#         if RvicFdrFile is not None:
#             self.atts['RvicFdrFile'] = RvicFdrFile
# 
#         if RvicDomainFile is not None:
#             self.atts['RvicDomainFile'] = RvicDomainFile
# 
#     def update(self):
#         self.atts['history'] = \
#             'Created: {0}'.format(time_mod.ctime(time_mod.time()))
# 
# Path: rvic/core/pycompat.py
# def iteritems(d):
#     return iter(d.items())


import numpy as np
from netCDF4 import Dataset, stringtochar
from logging import getLogger
from .log import LOG_NAME
from .share import NC_DOUBLE, NC_INT, NC_CHAR, FILLVALUE_F, NcGlobals
from .pycompat import iteritems
from . import share
    # ---------------------------------------------------------------- #

    # ---------------------------------------------------------------- #
    # Time Variables

    # Timesteps
    timesteps = f.createDimension('timesteps', subset_length)
    timesteps = f.createVariable('timesteps', NC_DOUBLE, ('timesteps',),
                                 **ncvaropts)
    timesteps[:] = np.arange(subset_length)
    for key, val in iteritems(share.timesteps):
        if val:
            setattr(timesteps, key, val.encode())
    timesteps.timestep_length = b'unit_hydrograph_dt'

    # ---------------------------------------------------------------- #

    # ---------------------------------------------------------------- #
    # write global attributes
    glob_atts.update()
    for key, val in iteritems(glob_atts.atts):
        if val:
            setattr(f, key, val.encode())
    f.featureType = b'timeSeries'
    # ---------------------------------------------------------------- #

    # ---------------------------------------------------------------- #
    # 0-D variables

    # Full time length (size of ring)

# Path: rvic/core/log.py
# LOG_NAME = 'rvic'
# 
# Path: rvic/core/share.py
# NC_DOUBLE = 'f8'
# 
# NC_INT = 'i4'
# 
# NC_CHAR = 'S1'
# 
# FILLVALUE_F = default_fillvals[NC_DOUBLE]
# 
# class NcGlobals(object):
#     def __init__(self,
#                  title=None,
#                  casename=None,
#                  casestr=None,
#                  history='Created: {}'.format(time_mod.ctime(time_mod.time())),
#                  institution='University of Washington',
#                  source=sys.argv[0],
#                  references='Based on the initial model of Lohmann, et al., '
#                             '1996, Tellus, 48(A), 708-721',
#                  comment='Output from the RVIC Streamflow Routing Model.',
#                  Conventions='CF-1.6',
#                  RvicPourPointsFile=None,
#                  RvicFdrFile=None,
#                  RvicUHFile=None,
#                  RvicDomainFile=None,
#                  version=None,
#                  hostname=None,
#                  username=None):
# 
#         self.atts = OrderedDict()
# 
#         if title is not None:
#             self.atts['title'] = title
# 
#         if comment is not None:
#             self.atts['comment'] = comment
# 
#         if Conventions is not None:
#             self.atts['Conventions'] = Conventions
# 
#         if history is not None:
#             self.atts['history'] = history
# 
#         if source is not None:
#             self.atts['source'] = source
# 
#         if institution is not None:
#             self.atts['institution'] = institution
# 
#         if hostname is not None:
#             self.atts['hostname'] = hostname
#         else:
#             self.atts['hostname'] = socket.gethostname()
# 
#         if username is not None:
#             self.atts['username'] = username
#         else:
#             self.atts['username'] = getuser()
# 
#         if casename is not None:
#             self.atts['casename'] = casename
# 
#         if casestr is not None:
#             self.atts['casestr'] = casestr
# 
#         if references is not None:
#             self.atts['references'] = references
# 
#         if version is not None:
#             self.atts['version'] = version
#         else:
#             try:
#                 from rvic import version
#                 self.atts['version'] = version.short_version
#             except ImportError:
#                 self.atts['version'] = 'unknown'
# 
#         if RvicPourPointsFile is not None:
#             self.atts['RvicPourPointsFile'] = RvicPourPointsFile
# 
#         if RvicUHFile is not None:
#             self.atts['RvicUHFile'] = RvicUHFile
# 
#         if RvicFdrFile is not None:
#             self.atts['RvicFdrFile'] = RvicFdrFile
# 
#         if RvicDomainFile is not None:
#             self.atts['RvicDomainFile'] = RvicDomainFile
# 
#     def update(self):
#         self.atts['history'] = \
#             'Created: {0}'.format(time_mod.ctime(time_mod.time()))
# 
# Path: rvic/core/pycompat.py
# def iteritems(d):
#     return iter(d.items())


# Path: rvic/core/write.py
import numpy as np
from netCDF4 import Dataset, stringtochar
from logging import getLogger
from .log import LOG_NAME
from .share import NC_DOUBLE, NC_INT, NC_CHAR, FILLVALUE_F, NcGlobals
from .pycompat import iteritems
from . import share

    # ---------------------------------------------------------------- #

    # ---------------------------------------------------------------- #
    # Time Variables

    # Timesteps
    timesteps = f.createDimension('timesteps', subset_length)
    timesteps = f.createVariable('timesteps', NC_DOUBLE, ('timesteps',),
                                 **ncvaropts)
    timesteps[:] = np.arange(subset_length)
    for key, val in iteritems(share.timesteps):
        if val:
            setattr(timesteps, key, val.encode())
    timesteps.timestep_length = b'unit_hydrograph_dt'

    # ---------------------------------------------------------------- #

    # ---------------------------------------------------------------- #
    # write global attributes
    glob_atts.update()
    for key, val in iteritems(glob_atts.atts):
        if val:
            setattr(f, key, val.encode())
    f.featureType = b'timeSeries'
    # ---------------------------------------------------------------- #

    # ---------------------------------------------------------------- #
    # 0-D variables

    # Full time length (size of ring)

    ftl = f.createVariable('full_time_length', NC_INT, (), **ncvaropts)