# 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/components/snow_base.py
# class snow_component( BMI_base.BMI_component ):
#     def set_constants(self):
#     def latent_heat_of_sublimation(self):
#     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 check_input_types(self):
#     def initialize_computed_vars(self):
#     def update_meltrate(self):
#     def enforce_max_meltrate(self):
#     def update_SM_integral(self):
#     def update_swe(self):
#     def update_depth(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):
#         T = self.T_air
#         T_IS_GRID = self.is_grid('T_air')
#         P_IS_GRID = self.is_grid('P_snow')
#         H0_SNOW_IS_SCALAR = self.is_scalar('h0_snow')
#         H0_SWE_IS_SCALAR  = self.is_scalar('h0_swe') 


import numpy as np
from topoflow.utils import model_input
from topoflow.components import snow_base
        #        equivalent (swe) in update_swe() in "snow_base.py".
        #-------------------------------------------------------------
        T_air = self.T_air  # (2/3/13, new framework)
        
        #------------------------------
        # Compute degree-day meltrate
        #------------------------------
        M = (self.c0 / np.float64(8.64E7)) * (T_air - self.T0)   #[m/s]

        # This is really an "enforce_min_meltrate()"
        self.SM = np.maximum(M, np.float64(0))
   
        #-------------------------------------------------------
        # Note: enforce_max_meltrate() method is always called
        #       by the base class to make sure that meltrate
        #       does not exceed the max possible.
        #-------------------------------------------------------
        #  self.enforce_max_meltrate()
        
    #   update_meltrate()
    #------------------------------------------------------------------- 
    def open_input_files(self):

        self.c0_file       = self.in_directory + self.c0_file
        self.T0_file       = self.in_directory + self.T0_file
        self.rho_snow_file = self.in_directory + self.rho_snow_file
        self.h0_snow_file  = self.in_directory + self.h0_snow_file
        self.h0_swe_file   = self.in_directory + self.h0_swe_file

        self.c0_unit       = model_input.open_file(self.c0_type,       self.c0_file)

# 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/components/snow_base.py
# class snow_component( BMI_base.BMI_component ):
#     def set_constants(self):
#     def latent_heat_of_sublimation(self):
#     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 check_input_types(self):
#     def initialize_computed_vars(self):
#     def update_meltrate(self):
#     def enforce_max_meltrate(self):
#     def update_SM_integral(self):
#     def update_swe(self):
#     def update_depth(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):
#         T = self.T_air
#         T_IS_GRID = self.is_grid('T_air')
#         P_IS_GRID = self.is_grid('P_snow')
#         H0_SNOW_IS_SCALAR = self.is_scalar('h0_snow')
#         H0_SWE_IS_SCALAR  = self.is_scalar('h0_swe') 


# Path: topoflow/components/snow_degree_day.py
import numpy as np
from topoflow.utils import model_input
from topoflow.components import snow_base

        #        equivalent (swe) in update_swe() in "snow_base.py".
        #-------------------------------------------------------------
        T_air = self.T_air  # (2/3/13, new framework)
        
        #------------------------------
        # Compute degree-day meltrate
        #------------------------------
        M = (self.c0 / np.float64(8.64E7)) * (T_air - self.T0)   #[m/s]

        # This is really an "enforce_min_meltrate()"
        self.SM = np.maximum(M, np.float64(0))
   
        #-------------------------------------------------------
        # Note: enforce_max_meltrate() method is always called
        #       by the base class to make sure that meltrate
        #       does not exceed the max possible.
        #-------------------------------------------------------
        #  self.enforce_max_meltrate()
        
    #   update_meltrate()
    #------------------------------------------------------------------- 
    def open_input_files(self):

        self.c0_file       = self.in_directory + self.c0_file
        self.T0_file       = self.in_directory + self.T0_file
        self.rho_snow_file = self.in_directory + self.rho_snow_file
        self.h0_snow_file  = self.in_directory + self.h0_snow_file
        self.h0_swe_file   = self.in_directory + self.h0_swe_file

        self.c0_unit       = model_input.open_file(self.c0_type,       self.c0_file)

        self.T0_unit       = model_input.open_file(self.T0_type,       self.T0_file)