# 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
        #
        #         source_ID: (source pixel ID as long integer)
        #         nt:        (number of discharge (Q) values)
        #         Q:         (vector of discharges in m^3/s)
        #------------------------------------------------------------
        if (self.comp_status == 'Disabled'): return
        if not(self.use_sources):
            self.sources_x = self.initialize_scalar( 0, dtype='float64')
            self.sources_y = self.initialize_scalar( 0, dtype='float64')
            self.sources_Q = self.initialize_scalar( 0, dtype='float64')
            return
        
        #-----------------------------
        # Can source_file be found ?
        #-----------------------------
        FOUND = tf_utils.file_exists( self.source_file )
        if not(FOUND):
            self.use_sources = False
            return

        #-------------------------
        # Open the "source_file"
        #-------------------------
        file_unit = open(self.source_file, 'r')

        #----------------------------------------------------
        # Read number of sources, max number of timesteps
        # for any source and the common timestep, source_dt
        #----------------------------------------------------
        n_sources = cfg.read_value(file_unit, dtype='Int32')

# 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

        #
        #         source_ID: (source pixel ID as long integer)
        #         nt:        (number of discharge (Q) values)
        #         Q:         (vector of discharges in m^3/s)
        #------------------------------------------------------------
        if (self.comp_status == 'Disabled'): return
        if not(self.use_sources):
            self.sources_x = self.initialize_scalar( 0, dtype='float64')
            self.sources_y = self.initialize_scalar( 0, dtype='float64')
            self.sources_Q = self.initialize_scalar( 0, dtype='float64')
            return
        
        #-----------------------------
        # Can source_file be found ?
        #-----------------------------
        FOUND = tf_utils.file_exists( self.source_file )
        if not(FOUND):
            self.use_sources = False
            return

        #-------------------------
        # Open the "source_file"
        #-------------------------
        file_unit = open(self.source_file, 'r')

        #----------------------------------------------------
        # Read number of sources, max number of timesteps
        # for any source and the common timestep, source_dt
        #----------------------------------------------------
        n_sources = cfg.read_value(file_unit, dtype='Int32')

        nt_max    = cfg.read_value(file_unit, dtype='Int32')