"""DO NOT DELETE THIS FILE. This script imports the heatsource module
and executes the model routines. This script must be located in the same
directory as HeatSource_control.csv. NOTE that executing this script
from Python shell (IDLE) will not identify __file__ correctly and will
result in an error. It must be executed from a command prompt. Your
options are to double click on this file and execute using python.exe,
use the batch command files (which point to these files), or
open terminal and execture manually by typing:
python -i path/to/this/script/HS9_Setup_Model_Inputs.py"""

from heatsource9 import BigRedButton
from os.path import dirname, exists, join, realpath, abspath

def getScriptPath():
    """Gets the path to the directory where the script is being executed from."""
    return abspath(join(dirname(realpath(__file__)), '.'))

inputdir = getScriptPath() + '/'
control_file = 'HeatSource_Control.csv'

if exists(join(inputdir,control_file)) is False:
    raise Exception("HeatSource_Control.csv not found. Move the executable or place the control file in this directory: %s." % inputdir)

# Run Setup, run_type = 3
BigRedButton.run_input_setup(inputdir, control_file, use_timestamp=False,
                                     overwrite=False)


                       "lcdatainput": [36, "LANDCOVER DATA INPUT TYPE (Codes/Values)", "Codes"],
                       "canopy_data": [37, "CANOPY DATA TYPE (LAI/CanopyCover)", canopy_data_type],
                       "vegDistMethod": [38, "VEGETATION ANGLE CALCULATION METHOD (point/zone)", "point"],
                       "heatsource8": [39, "USE HEAT SOURCE 8 LANDCOVER METHODS (TRUE/FALSE)", "FALSE"]}            
            
            # sort so we have a list in the order of the line number
            cf_sorted = sorted(cf_dict.items(), key=itemgetter(1))
            cf_list = [line[1] for line in cf_sorted]
        
            cf_header = ["LINE", "PARAMETER", "VALUE"]
            write_csv(dir_model, "HeatSource_Control.csv",
                      cf_header, cf_list)
        
        # Build the other input files
        BigRedButton.run_input_setup(dir_model,"HeatSource_Control.csv",
                                     use_timestamp=False,
                                     overwrite=False)
            
        # copy the files to the model directory folder
        for copy_from, copy_to in files_to_copy:
            if copy_to == 0:
                shutil.copy(copy_from, dir_model)
            elif copy_to == 1:
                shutil.copy(copy_from, dir_inputs)
            else:
                shutil.copy(copy_from, copy_to)
        
        del nodeDict
        
    write_csv(outputdir, "model_directory.csv", ["GROUP", "PATH", "STATUS"], model_paths)