# Path: rvic/core/time_utility.py
# def ord_to_datetime(time, units, calendar='standard'):
#     '''
#     netCDF4.num2date yields a fake datetime object, this function converts
#     converts that back to a real datetime object
#     '''
#     # this is the netCDF4.datetime object
#     # if the calendar is standard, t is already a real datetime object
#     if type(time) == np.ndarray:
#         if len(time) == 1:
#             time = time[0]
#         else:
#             raise ValueError('time variable is a numpy array with length > 1')
#     t = num2date(time, units, calendar=calendar)
#     if calendar in ['proleptic_gregorian', 'standard', 'gregorian']:
#         return t
#     else:
#         return datetime(t.year, t.month, t.day, t.hour, t.minute, t.second)
# 
# Path: rvic/core/log.py
# LOG_NAME = 'rvic'
# 
# Path: rvic/core/share.py
# SECSPERDAY = HOURSPERDAY * SECSPERHOUR
# 
# HOURSPERDAY = 24.
# 
# TIMEUNITS = 'days since ' + REFERENCE_STRING  # do not change (MUST BE DAYS)!
# 
# Path: rvic/core/share.py
# NC_INT = 'i4'
# 
# NC_FLOAT = 'f4'
# 
# NC_CHAR = 'S1'
# 
# Path: rvic/core/share.py
# NC_DOUBLE = 'f8'
# 
# WATERDENSITY = 1000.
# 
# MONTHSPERYEAR = 12
# 
# Path: rvic/core/pycompat.py
# def iteritems(d):
#     return iter(d.items())


import os
import numpy as np
from netCDF4 import Dataset, date2num, num2date, stringtochar
from datetime import datetime
from .time_utility import ord_to_datetime
from logging import getLogger
from .log import LOG_NAME
from .share import SECSPERDAY, HOURSPERDAY, TIMEUNITS
from .share import NC_INT, NC_FLOAT, NC_CHAR
from .share import NC_DOUBLE, WATERDENSITY, MONTHSPERYEAR
from .pycompat import iteritems
from . import share
                 '\t# fincl:        {0}'.format(','.join(self._fincl)),
                 '\t# nhtfrq:       {0}'.format(self._nhtfrq),
                 '\t# mfilt:        {0}'.format(self._mfilt),
                 '\t# ncprec:       {0}'.format(self._ncprec),
                 '\t# avgflag:      {0}'.format(self._avgflag),
                 '\t# fname_format: {0}'.format(self._fname_format),
                 '\t# file_format:  {0}'.format(self._file_format),
                 '\t# outtype:      {0}'.format(self._outtype),
                 '\t# out_dir:      {0}'.format(self._out_dir),
                 '\t# calendar:     {0}'.format(self._calendar),
                 '\t# units:        {0}'.format(self._units),
                 '  ------- End of History Tape Settings -------']
        return '\n'.join(parts)
    # ---------------------------------------------------------------- #

    # ---------------------------------------------------------------- #
    # Update the history tapes with new fluxes
    def update(self, data2tape, time_ord):
        ''' Update the tape with new data'''

        # ------------------------------------------------------------ #
        # Check that the time_ord is in sync
        if self._time_ord != time_ord:
            raise ValueError('rout_var.time_ord does not match the time_ord '
                             'passed in by the convolution call')
        # ------------------------------------------------------------ #

        # ------------------------------------------------------------ #
        # Get the next timestamp
        self._time_ord += self._dt / SECSPERDAY

# Path: rvic/core/time_utility.py
# def ord_to_datetime(time, units, calendar='standard'):
#     '''
#     netCDF4.num2date yields a fake datetime object, this function converts
#     converts that back to a real datetime object
#     '''
#     # this is the netCDF4.datetime object
#     # if the calendar is standard, t is already a real datetime object
#     if type(time) == np.ndarray:
#         if len(time) == 1:
#             time = time[0]
#         else:
#             raise ValueError('time variable is a numpy array with length > 1')
#     t = num2date(time, units, calendar=calendar)
#     if calendar in ['proleptic_gregorian', 'standard', 'gregorian']:
#         return t
#     else:
#         return datetime(t.year, t.month, t.day, t.hour, t.minute, t.second)
# 
# Path: rvic/core/log.py
# LOG_NAME = 'rvic'
# 
# Path: rvic/core/share.py
# SECSPERDAY = HOURSPERDAY * SECSPERHOUR
# 
# HOURSPERDAY = 24.
# 
# TIMEUNITS = 'days since ' + REFERENCE_STRING  # do not change (MUST BE DAYS)!
# 
# Path: rvic/core/share.py
# NC_INT = 'i4'
# 
# NC_FLOAT = 'f4'
# 
# NC_CHAR = 'S1'
# 
# Path: rvic/core/share.py
# NC_DOUBLE = 'f8'
# 
# WATERDENSITY = 1000.
# 
# MONTHSPERYEAR = 12
# 
# Path: rvic/core/pycompat.py
# def iteritems(d):
#     return iter(d.items())


# Path: rvic/core/history.py
import os
import numpy as np
from netCDF4 import Dataset, date2num, num2date, stringtochar
from datetime import datetime
from .time_utility import ord_to_datetime
from logging import getLogger
from .log import LOG_NAME
from .share import SECSPERDAY, HOURSPERDAY, TIMEUNITS
from .share import NC_INT, NC_FLOAT, NC_CHAR
from .share import NC_DOUBLE, WATERDENSITY, MONTHSPERYEAR
from .pycompat import iteritems
from . import share

                 '\t# fincl:        {0}'.format(','.join(self._fincl)),
                 '\t# nhtfrq:       {0}'.format(self._nhtfrq),
                 '\t# mfilt:        {0}'.format(self._mfilt),
                 '\t# ncprec:       {0}'.format(self._ncprec),
                 '\t# avgflag:      {0}'.format(self._avgflag),
                 '\t# fname_format: {0}'.format(self._fname_format),
                 '\t# file_format:  {0}'.format(self._file_format),
                 '\t# outtype:      {0}'.format(self._outtype),
                 '\t# out_dir:      {0}'.format(self._out_dir),
                 '\t# calendar:     {0}'.format(self._calendar),
                 '\t# units:        {0}'.format(self._units),
                 '  ------- End of History Tape Settings -------']
        return '\n'.join(parts)
    # ---------------------------------------------------------------- #

    # ---------------------------------------------------------------- #
    # Update the history tapes with new fluxes
    def update(self, data2tape, time_ord):
        ''' Update the tape with new data'''

        # ------------------------------------------------------------ #
        # Check that the time_ord is in sync
        if self._time_ord != time_ord:
            raise ValueError('rout_var.time_ord does not match the time_ord '
                             'passed in by the convolution call')
        # ------------------------------------------------------------ #

        # ------------------------------------------------------------ #
        # Get the next timestamp
        self._time_ord += self._dt / SECSPERDAY

        self._timestamp = ord_to_datetime(self._time_ord, TIMEUNITS,