core_model_loop(global_dic, case_dic_list)

print('Simple_Energy_Model: Saving basic results')
# Note that results for individual cases are output from core_model_loop
save_basic_results(global_dic, case_dic_list)

# -----------------------------------------------------------------------------

# copy the Gurobi log file to the output folder
#   The Verbose field in SOLVE function in CORE_MODEL.PY determined if a gurobi.log is generated.
#   delete the gurobi log to eliminate cumulations from previous runs.

if os.path.exists("./gurobi.log"):
    copy2("./gurobi.log", output_folder)
    try:
        os.remove("./gurobi.log")
    except:
        print('gurboi.log not erased')

# -----------------------------------------------------------------------------

if global_dic['POSTPROCESS']:
    print('Simple_Energy_Model: Post-processing results')
    post_process(global_dic)  # Lei's old postprocessing

if global_dic['QUICK_LOOK']:
    print('Simple_Energy_Model: Preparing quick look at results')
    pickle_file_name = './Output_Data/' + global_dic[
        'GLOBAL_NAME'] + '/' + global_dic['GLOBAL_NAME'] + '.pickle'
    quick_look(global_dic, case_dic_list)  # Fan's new postprocessing
# directory = 'D:/M/WORK/'
#root_directory = '/Users/kcaldeira/Google Drive/simple energy system model/Kens version/'
#whoami = subprocess.check_output('whoami')
#if whoami == 'kcaldeira-carbo\\kcaldeira\r\n':
#    case_input_path_filename = '/Users/kcaldeira/Google Drive/git/SEM-1/case_input.csv'
case_input_path_filename = './case_input.csv'

# -----------------------------------------------------------------------------
# =============================================================================

print 'Simple_Energy_Model: Pre-processing input'
global_dic, case_dic_list = preprocess_input(case_input_path_filename)

print 'Simple_Energy_Model: Executing core model loop'
result_list = core_model_loop(global_dic, case_dic_list)

print 'Simple_Energy_Model: Saving basic results'
scalar_names, scalar_table = save_basic_results(global_dic, case_dic_list,
                                                result_list)

if global_dic['POSTPROCESS']:
    print 'Simple_Energy_Model: Post-processing results'
    post_process(global_dic)  # Lei's old postprocessing

if global_dic['QUICK_LOOK']:
    print 'Simple_Energy_Model: Preparing quick look at results'
    pickle_file_name = './Output_Data/' + global_dic[
        'GLOBAL_NAME'] + '/' + global_dic['GLOBAL_NAME'] + '.pickle'
    quick_look(pickle_file_name)  # Fan's new postprocessing