# Path: topoflow/components/diversions_base.py
# class diversions_component( BMI_base.BMI_component ):
#     def initialize(self, cfg_file=None, mode="nondriver",
#                    SILENT=False):
#     def update(self, dt=-1.0):
#     def finalize(self):
#     def set_computed_input_vars(self):
#     def read_input_files(self):
#     def read_source_data(self):
#     def read_sink_data(self):
#     def read_canal_data(self):
# 
# Path: topoflow/utils/cfg_files.py
# def unit_test():
# def skip_header(file_unit, n_lines=4):
# def get_yes_words():
# def read_words(file_unit, word_delim=None):
# def read_list(file_unit, dtype_list=None, dtype='string',
#               word_delim=None):
# def read_key_value_pair(file_unit, key_delim=':', SILENT=True):
# def read_line_after_key(file_unit, key_delim=':'):
# def read_words_after_key(file_unit, key_delim=':',
#                          word_delim=None, n_words=None):
# def read_list_after_key(file_unit, dtype_list=None, dtype='string',
#                         key_delim=':', word_delim=None):
# def read_value(file_unit, dtype='string', key_delim=':'):
# def var_type_code(var_type):
# def read_input_option(file_unit, key_delim=':', word_delim=None):
# def read_output_option(file_unit, key_delim=':', word_delim=None):
# 
# Path: topoflow/utils/tf_utils.py
# def TF_Use_CCA():
# def TF_Set_Test_Info(self):
# def TF_Test_Directory():
# def TF_Test_Site_Prefix():
# def TF_Test_Case_Prefix():
# def TF_Build_Date():
# def TF_Version_Number():
# def TF_Version():
# def TF_Print(string):
# def TF_String(number, FORMAT=None):
# def file_exists(filename):
# def Count_Lines(filename, SILENT=False):
# def Current_Directory():
# def Resize(array, factor, REDUCE, new_ncols, new_nrows, SAMP_TYPE=None):
# def Make_Savefile():
# def Get_Site_Prefix(filepath):
# def Get_Case_Prefix():
# def Not_Same_Byte_Order(byte_order):
# def Courant_Condition_OK(dx, dt, vmax):
# def Stable_Timestep(dx, vmax):
# def TF_Tan(angle):
# def Convert_Flow_Grid(infile, outfile, itype, otype, byte_order, \
#                       icodes=None, ocodes=None, REPORT=False):
#         SAMP_TYPE = int16(0)
#     NOT_SAME = (machine_byte_order != byte_order)
#     OK = ((vmax * dt * factor) <= dx)
#     SWAP_ENDIAN = Not_Same_Byte_Order(byte_order)


import numpy as np
import glob
import os
from topoflow.components import diversions_base
from topoflow.utils import cfg_files as cfg
from topoflow.utils import tf_utils
        ## print 'sources_Q ='
        ## print sources_Q
        
    #   update_sources()
    #--------------------------------------------------------------------------
    def update_sinks(self):

        #-------------------------------------------------------
        # Notes: This function avoids loops in favor of array
        #        operations to increase speed.
        #-------------------------------------------------------
        #        The number of Q-values for each sink ID are
        #        stored as "self.nt_sinks".  However, for any
        #        given sink ID, the Q-values beyond that index
        #        are set to zero.
        #-------------------------------------------------------
        # NB!    This changes Q grid, so must be called before
        #        cp.update_flow_volume() uses the Q grid.
        #-------------------------------------------------------        
        if not(self.use_sinks): return

        #-----------------------------------------  
        # Update discharge, Q, for every sink ID
        #-----------------------------------------
        # Make sure sink cannot produce negative
        # discharge values.
        #-----------------------------------------
        if (self.time_index < self.nt_max_sinks):
            sinks_Q[:] = self.sinks_Q_all[ :, self.time_index ]
        else:

# Path: topoflow/components/diversions_base.py
# class diversions_component( BMI_base.BMI_component ):
#     def initialize(self, cfg_file=None, mode="nondriver",
#                    SILENT=False):
#     def update(self, dt=-1.0):
#     def finalize(self):
#     def set_computed_input_vars(self):
#     def read_input_files(self):
#     def read_source_data(self):
#     def read_sink_data(self):
#     def read_canal_data(self):
# 
# Path: topoflow/utils/cfg_files.py
# def unit_test():
# def skip_header(file_unit, n_lines=4):
# def get_yes_words():
# def read_words(file_unit, word_delim=None):
# def read_list(file_unit, dtype_list=None, dtype='string',
#               word_delim=None):
# def read_key_value_pair(file_unit, key_delim=':', SILENT=True):
# def read_line_after_key(file_unit, key_delim=':'):
# def read_words_after_key(file_unit, key_delim=':',
#                          word_delim=None, n_words=None):
# def read_list_after_key(file_unit, dtype_list=None, dtype='string',
#                         key_delim=':', word_delim=None):
# def read_value(file_unit, dtype='string', key_delim=':'):
# def var_type_code(var_type):
# def read_input_option(file_unit, key_delim=':', word_delim=None):
# def read_output_option(file_unit, key_delim=':', word_delim=None):
# 
# Path: topoflow/utils/tf_utils.py
# def TF_Use_CCA():
# def TF_Set_Test_Info(self):
# def TF_Test_Directory():
# def TF_Test_Site_Prefix():
# def TF_Test_Case_Prefix():
# def TF_Build_Date():
# def TF_Version_Number():
# def TF_Version():
# def TF_Print(string):
# def TF_String(number, FORMAT=None):
# def file_exists(filename):
# def Count_Lines(filename, SILENT=False):
# def Current_Directory():
# def Resize(array, factor, REDUCE, new_ncols, new_nrows, SAMP_TYPE=None):
# def Make_Savefile():
# def Get_Site_Prefix(filepath):
# def Get_Case_Prefix():
# def Not_Same_Byte_Order(byte_order):
# def Courant_Condition_OK(dx, dt, vmax):
# def Stable_Timestep(dx, vmax):
# def TF_Tan(angle):
# def Convert_Flow_Grid(infile, outfile, itype, otype, byte_order, \
#                       icodes=None, ocodes=None, REPORT=False):
#         SAMP_TYPE = int16(0)
#     NOT_SAME = (machine_byte_order != byte_order)
#     OK = ((vmax * dt * factor) <= dx)
#     SWAP_ENDIAN = Not_Same_Byte_Order(byte_order)


# Path: topoflow/components/diversions_fraction_method.py
import numpy as np
import glob
import os
from topoflow.components import diversions_base
from topoflow.utils import cfg_files as cfg
from topoflow.utils import tf_utils

        ## print 'sources_Q ='
        ## print sources_Q
        
    #   update_sources()
    #--------------------------------------------------------------------------
    def update_sinks(self):

        #-------------------------------------------------------
        # Notes: This function avoids loops in favor of array
        #        operations to increase speed.
        #-------------------------------------------------------
        #        The number of Q-values for each sink ID are
        #        stored as "self.nt_sinks".  However, for any
        #        given sink ID, the Q-values beyond that index
        #        are set to zero.
        #-------------------------------------------------------
        # NB!    This changes Q grid, so must be called before
        #        cp.update_flow_volume() uses the Q grid.
        #-------------------------------------------------------        
        if not(self.use_sinks): return

        #-----------------------------------------  
        # Update discharge, Q, for every sink ID
        #-----------------------------------------
        # Make sure sink cannot produce negative
        # discharge values.
        #-----------------------------------------
        if (self.time_index < self.nt_max_sinks):
            sinks_Q[:] = self.sinks_Q_all[ :, self.time_index ]
        else:

            sinks_Q[:] = np.zeros(self.n_sinks)