# 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
        #
        #         nt_canals is computed as ceil(travel_time / cp.dt)
        #-------------------------------------------------------------------
        # Note:  Q_canals is same at upstream and downstream ends, but the
        #        downstream end lags the upstream end by the travel time
        #        from in_ID to out_ID.  As a result, the duration and Q
        #        vector for the downstream end are computed from those of
        #        the upstream end, and the travel time, td, as:
        #            Q_out   = [0,  Q_in]
        #            dur_out = [td, dur_in]
        #            dur_sum_out = [0, dur_sum_in] + td
        #
        #        Rather than create the dur_sum_canals_out and
        #        canals_out_Q vectors, can construct them in Update_Canals.
        #-------------------------------------------------------------------
        if (self.comp_status == 'Disabled'): return
        if not(self.use_canals):
            self.canals_in_x       = self.initialize_scalar( 0, dtype='float64')
            self.canals_in_y       = self.initialize_scalar( 0, dtype='float64')
            self.canals_in_Q_fraction = self.initialize_scalar( 0, dtype='float64')
            self.canals_out_Q      = self.initialize_scalar( 0, dtype='float64')
            self.canals_out_x      = self.initialize_scalar( 0, dtype='float64')
            self.canals_out_y      = self.initialize_scalar( 0, dtype='float64')
            return
    
        #---------------------------
        # Can canal_file be found ?
        #---------------------------
        FOUND = tf_utils.file_exists( self.canal_file )
        if not(FOUND):

# 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

        #
        #         nt_canals is computed as ceil(travel_time / cp.dt)
        #-------------------------------------------------------------------
        # Note:  Q_canals is same at upstream and downstream ends, but the
        #        downstream end lags the upstream end by the travel time
        #        from in_ID to out_ID.  As a result, the duration and Q
        #        vector for the downstream end are computed from those of
        #        the upstream end, and the travel time, td, as:
        #            Q_out   = [0,  Q_in]
        #            dur_out = [td, dur_in]
        #            dur_sum_out = [0, dur_sum_in] + td
        #
        #        Rather than create the dur_sum_canals_out and
        #        canals_out_Q vectors, can construct them in Update_Canals.
        #-------------------------------------------------------------------
        if (self.comp_status == 'Disabled'): return
        if not(self.use_canals):
            self.canals_in_x       = self.initialize_scalar( 0, dtype='float64')
            self.canals_in_y       = self.initialize_scalar( 0, dtype='float64')
            self.canals_in_Q_fraction = self.initialize_scalar( 0, dtype='float64')
            self.canals_out_Q      = self.initialize_scalar( 0, dtype='float64')
            self.canals_out_x      = self.initialize_scalar( 0, dtype='float64')
            self.canals_out_y      = self.initialize_scalar( 0, dtype='float64')
            return
    
        #---------------------------
        # Can canal_file be found ?
        #---------------------------
        FOUND = tf_utils.file_exists( self.canal_file )
        if not(FOUND):

            self.use_canals = False