# Path: topoflow/components/infil_base.py
# class infil_component( BMI_base.BMI_component):
#     def set_constants(self):       
#     def initialize(self, cfg_file=None, mode="nondriver",
#                    SILENT=False):
#     def update(self, dt=-1.0):
#     def finalize(self):
#     def build_layer_z_vector(self):
#     def build_layered_var(self, var_list_for_layers):
#     def set_computed_input_vars(self):
#     def check_input_types(self):
#     def update_surface_influx(self):
#     def update_infil_rate(self):
#     def adjust_infil_rate(self):
#     def update_IN_integral(self):
#     def update_Rg(self):
#     def update_Rg_integral(self):
#     def update_I(self):
#     def update_q0(self):
#     def check_infiltration(self):
#     def check_low_rainrate(self):
#     def open_input_files(self):
#     def read_input_files(self):
#     def close_input_files(self):
#     def update_outfile_names(self):
#     def open_output_files(self):
#     def write_output_files(self, time_seconds=None):
#     def close_output_files(self):
#     def save_grids(self):
#     def save_pixel_values(self):
#     def save_profiles(self):
#     def save_cubes(self):
#         ALL_SCALARS = (nmax == 1)
#         SM     = self.SM        # (2/3/13, new framework)
#         CHECK_LOW_RAIN = not(self.RICHARDS)
#         SM      = self.SM       # (2/3/13, new framework)
#             OK = np.isfinite( self.IN )
#             OK = (nbad == 0)
#             G  = model_input.read_next(self.G_unit[k], self.G_type[k], rti)
# 
# Path: topoflow/utils/model_input.py
# def open_file(var_type, input_file):
# def read_next2(self, var_name, rti, dtype='Float32', factor=1.0):
# def read_next(file_unit, var_type, rti, \
#               dtype='Float32', factor=1.0):
# def read_scalar(file_unit, dtype='Float32'):
# def read_grid(file_unit, rti, dtype='Float32'):
# def close_file(file_unit):
#     END_OF_FILE = (file_pos == file_size)
# 
# Path: topoflow/utils/tf_utils.py
# def TF_Print(string):
#     """Print a string to the TopoFlow output log window."""
# 
#     #------------------------------------------
#     # For now, just print to terminal window.
#     # Later, this will be method in tf_gui.py.
#     #------------------------------------------
#     print string
# 
# def TF_String(number, FORMAT=None):
# 
#     return idl_func.string(number, format=FORMAT).strip()


import numpy as np
import os
from topoflow.components import infil_base
from topoflow.utils import model_input
from topoflow.utils.tf_utils import TF_Print, TF_String
        ## n = self.time_index
        ## Smith_Parlange_Infil_Rate_v2(self, r, r_last, n)
       
    #   update_infil_rate()
    #-------------------------------------------------------------------  
    def open_input_files(self):

        #-------------------------------------------------------
        # This method works for Green-Ampt and Smith-Parlange
        # but must be overridden for Richards 1D.
        #-------------------------------------------------------
        # NB! Green-Ampt and Smith-Parlange currently only
        #     support ONE layer (n_layers == 1).
        #-------------------------------------------------------
        self.Ks_unit  = []  # (empty lists to hold file objects)
        self.Ki_unit  = []
        self.qs_unit  = []
        self.qi_unit  = []
        self.G_unit   = []
        self.gam_unit = []

        for k in xrange(self.n_layers):
            self.Ks_file[k] = self.in_directory + self.Ks_file[k]
            self.Ki_file[k] = self.in_directory + self.Ki_file[k]
            self.qs_file[k] = self.in_directory + self.qs_file[k]
            self.qi_file[k] = self.in_directory + self.qi_file[k]
            self.G_file[k]  = self.in_directory + self.G_file[k]
            self.gam_file[k] = self.in_directory + self.gam_file[k]

            self.Ks_unit.append(  model_input.open_file(self.Ks_type[k],  self.Ks_file[k]) )

# Path: topoflow/components/infil_base.py
# class infil_component( BMI_base.BMI_component):
#     def set_constants(self):       
#     def initialize(self, cfg_file=None, mode="nondriver",
#                    SILENT=False):
#     def update(self, dt=-1.0):
#     def finalize(self):
#     def build_layer_z_vector(self):
#     def build_layered_var(self, var_list_for_layers):
#     def set_computed_input_vars(self):
#     def check_input_types(self):
#     def update_surface_influx(self):
#     def update_infil_rate(self):
#     def adjust_infil_rate(self):
#     def update_IN_integral(self):
#     def update_Rg(self):
#     def update_Rg_integral(self):
#     def update_I(self):
#     def update_q0(self):
#     def check_infiltration(self):
#     def check_low_rainrate(self):
#     def open_input_files(self):
#     def read_input_files(self):
#     def close_input_files(self):
#     def update_outfile_names(self):
#     def open_output_files(self):
#     def write_output_files(self, time_seconds=None):
#     def close_output_files(self):
#     def save_grids(self):
#     def save_pixel_values(self):
#     def save_profiles(self):
#     def save_cubes(self):
#         ALL_SCALARS = (nmax == 1)
#         SM     = self.SM        # (2/3/13, new framework)
#         CHECK_LOW_RAIN = not(self.RICHARDS)
#         SM      = self.SM       # (2/3/13, new framework)
#             OK = np.isfinite( self.IN )
#             OK = (nbad == 0)
#             G  = model_input.read_next(self.G_unit[k], self.G_type[k], rti)
# 
# Path: topoflow/utils/model_input.py
# def open_file(var_type, input_file):
# def read_next2(self, var_name, rti, dtype='Float32', factor=1.0):
# def read_next(file_unit, var_type, rti, \
#               dtype='Float32', factor=1.0):
# def read_scalar(file_unit, dtype='Float32'):
# def read_grid(file_unit, rti, dtype='Float32'):
# def close_file(file_unit):
#     END_OF_FILE = (file_pos == file_size)
# 
# Path: topoflow/utils/tf_utils.py
# def TF_Print(string):
#     """Print a string to the TopoFlow output log window."""
# 
#     #------------------------------------------
#     # For now, just print to terminal window.
#     # Later, this will be method in tf_gui.py.
#     #------------------------------------------
#     print string
# 
# def TF_String(number, FORMAT=None):
# 
#     return idl_func.string(number, format=FORMAT).strip()


# Path: topoflow/components/infil_smith_parlange.py
import numpy as np
import os
from topoflow.components import infil_base
from topoflow.utils import model_input
from topoflow.utils.tf_utils import TF_Print, TF_String

        ## n = self.time_index
        ## Smith_Parlange_Infil_Rate_v2(self, r, r_last, n)
       
    #   update_infil_rate()
    #-------------------------------------------------------------------  
    def open_input_files(self):

        #-------------------------------------------------------
        # This method works for Green-Ampt and Smith-Parlange
        # but must be overridden for Richards 1D.
        #-------------------------------------------------------
        # NB! Green-Ampt and Smith-Parlange currently only
        #     support ONE layer (n_layers == 1).
        #-------------------------------------------------------
        self.Ks_unit  = []  # (empty lists to hold file objects)
        self.Ki_unit  = []
        self.qs_unit  = []
        self.qi_unit  = []
        self.G_unit   = []
        self.gam_unit = []

        for k in xrange(self.n_layers):
            self.Ks_file[k] = self.in_directory + self.Ks_file[k]
            self.Ki_file[k] = self.in_directory + self.Ki_file[k]
            self.qs_file[k] = self.in_directory + self.qs_file[k]
            self.qi_file[k] = self.in_directory + self.qi_file[k]
            self.G_file[k]  = self.in_directory + self.G_file[k]
            self.gam_file[k] = self.in_directory + self.gam_file[k]

            self.Ks_unit.append(  model_input.open_file(self.Ks_type[k],  self.Ks_file[k]) )

            self.Ki_unit.append(  model_input.open_file(self.Ki_type[k],  self.Ki_file[k]) )