# Path: topoflow/components/evap_base.py
# class evap_component( BMI_base.BMI_component):
#     def set_constants(self):
#     def latent_heat_of_evaporation(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_Qc(self):
#     def update_ET_rate(self):
#     def update_ET_integral(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
# 
# 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)


import numpy as np
import os
from topoflow.components import evap_base
from topoflow.utils import model_input
        # rho_w = 1000d       ;[kg/m^3]
        # Lv    = -2500000d   ;[J/kg]
        # So (rho_w * Lv) = -2.5e+9  [J/m^3]
        #-------------------------------------
        ET = (Qet / np.float64(2.5E+9))  #[m/s]  (A loss, but returned as positive.)
        
        self.ET = np.maximum(ET, np.float64(0))

        ##########################################
        #  THIS MAY BE COSTLY.  BETTER WAY OR
        #  ALLOW ET TO BE A SCALAR ??
        ##########################################
        if (np.size(self.ET) == 1):
            self.ET += np.zeros((self.ny, self.nx), dtype='Float64')
            
    #   update_ET_rate()
    #-------------------------------------------------------------------  
    def open_input_files(self):

        #----------------------------------------------------
        # Note: Priestley-Taylor method needs alpha but the
        #       energy balance method doesn't. (2/5/13)
        #----------------------------------------------------
        self.alpha_file    = self.in_directory + self.alpha_file
        self.K_soil_file   = self.in_directory + self.K_soil_file
        self.soil_x_file   = self.in_directory + self.soil_x_file
        self.T_soil_x_file = self.in_directory + self.T_soil_x_file

        self.alpha_unit    = model_input.open_file(self.alpha_type,    self.alpha_file)
        self.K_soil_unit   = model_input.open_file(self.K_soil_type,   self.K_soil_file)

# Path: topoflow/components/evap_base.py
# class evap_component( BMI_base.BMI_component):
#     def set_constants(self):
#     def latent_heat_of_evaporation(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_Qc(self):
#     def update_ET_rate(self):
#     def update_ET_integral(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
# 
# 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/evap_priestley_taylor.py
import numpy as np
import os
from topoflow.components import evap_base
from topoflow.utils import model_input

        # rho_w = 1000d       ;[kg/m^3]
        # Lv    = -2500000d   ;[J/kg]
        # So (rho_w * Lv) = -2.5e+9  [J/m^3]
        #-------------------------------------
        ET = (Qet / np.float64(2.5E+9))  #[m/s]  (A loss, but returned as positive.)
        
        self.ET = np.maximum(ET, np.float64(0))

        ##########################################
        #  THIS MAY BE COSTLY.  BETTER WAY OR
        #  ALLOW ET TO BE A SCALAR ??
        ##########################################
        if (np.size(self.ET) == 1):
            self.ET += np.zeros((self.ny, self.nx), dtype='Float64')
            
    #   update_ET_rate()
    #-------------------------------------------------------------------  
    def open_input_files(self):

        #----------------------------------------------------
        # Note: Priestley-Taylor method needs alpha but the
        #       energy balance method doesn't. (2/5/13)
        #----------------------------------------------------
        self.alpha_file    = self.in_directory + self.alpha_file
        self.K_soil_file   = self.in_directory + self.K_soil_file
        self.soil_x_file   = self.in_directory + self.soil_x_file
        self.T_soil_x_file = self.in_directory + self.T_soil_x_file

        self.alpha_unit    = model_input.open_file(self.alpha_type,    self.alpha_file)
        self.K_soil_unit   = model_input.open_file(self.K_soil_type,   self.K_soil_file)

        self.soil_x_unit   = model_input.open_file(self.soil_x_type,   self.soil_x_file)