# 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
    #        R  = 1.0d   ;(equals 1 for saturation; R in [0,1])
    #        a1 = 1.0d   ;(accounts for moisture content of soil)
    #        a2 = 0.2d   ;(accounts for vegetation effect)
    #--------------------------------------------------------------
    
    #---------------------------------------------
    # Compute the conductive energy between the
    # surface and subsurface using Fourier's law
    #---------------------------------------------
    # soil_x is converted from [cm] to [m] when
    # it is read from the GUI and then stored
    #---------------------------------------------
    # In Qet formula, the constant 0.011 has
    # units of 1/[deg_C] to cancel T_air units.
    #---------------------------------------------  
    Qc   = Ks * (T_soil_x - T_surf) / (soil_x)
    Qnet = Qn_SW + Qn_LW
    Qet  = alpha * (np.float64(0.406) + (np.float32(0.011) * T_air)) * (Qnet - Qc)
    
    #-----------------------------------
    # Convert ET energy to a loss rate
    #------------------------------------------
    # Lf = latent heat of fusion [J/kg]
    # Lv = latent heat of vaporization [J/kg]
    # ET = (Qet / (rho_w * Lv))
    #------------------------------------------
    # rho_w = 1000d       ;[kg/m^3]
    # Lv    = -2500000d   ;[J/kg]
    # So (rho_w * Lv) = -2.5e+9  [J/m^3]
    #-------------------------------------

# 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

    #        R  = 1.0d   ;(equals 1 for saturation; R in [0,1])
    #        a1 = 1.0d   ;(accounts for moisture content of soil)
    #        a2 = 0.2d   ;(accounts for vegetation effect)
    #--------------------------------------------------------------
    
    #---------------------------------------------
    # Compute the conductive energy between the
    # surface and subsurface using Fourier's law
    #---------------------------------------------
    # soil_x is converted from [cm] to [m] when
    # it is read from the GUI and then stored
    #---------------------------------------------
    # In Qet formula, the constant 0.011 has
    # units of 1/[deg_C] to cancel T_air units.
    #---------------------------------------------  
    Qc   = Ks * (T_soil_x - T_surf) / (soil_x)
    Qnet = Qn_SW + Qn_LW
    Qet  = alpha * (np.float64(0.406) + (np.float32(0.011) * T_air)) * (Qnet - Qc)
    
    #-----------------------------------
    # Convert ET energy to a loss rate
    #------------------------------------------
    # Lf = latent heat of fusion [J/kg]
    # Lv = latent heat of vaporization [J/kg]
    # ET = (Qet / (rho_w * Lv))
    #------------------------------------------
    # rho_w = 1000d       ;[kg/m^3]
    # Lv    = -2500000d   ;[J/kg]
    # So (rho_w * Lv) = -2.5e+9  [J/m^3]
    #-------------------------------------

    ET = (Qet / np.float32(2.5E+9))  #[m/s]  (A loss, but returned as positive.)