import yaml
from yaml.loader import SafeLoader

import f90nml
import pyoasis
from pyoasis import OASIS  # pylint: disable=no-name-in-module
import numpy as np
import logging



# to be placed in IFS_toy script 
def read_yaml(read_in_data): 
    print("YAML file is read ... ")
    
    # TODO : make this section generalized   
    if model_name == "ifs_toy":
        print("DEBUG: Toy ifs function is called")
        number_land_grid_cells = read_in_data.get("number_land_grid_cells")
        t159 = number_land_grid_cells.get("t159")
        t255 = number_land_grid_cells.get("t255")
        t511 = number_land_grid_cells.get("t511")
    else:
        t159 = ""
        t255 = ""
        t511 = ""

    # Read in Simulation information
    coupling_intervals = read_in_data.get("coupling_intervals")
    run_length_sec = read_in_data.get("run_length_sec")
    
    # Read in Oasis information
    oasis = read_in_data.get("oasis")
    oasis_component = oasis.get("component")
    oasis_output_unit = oasis.get("output_unit")
    oasis_nx = oasis.get("nx")

    # Read in Coupling infomration
    coupling = read_in_data.get("coupling")
    coupling_out_fields = coupling.get("out_fields")
    coupling_out_vars = coupling.get("out_vars")
    coupling_in_fields = coupling.get("in_fields")
    coupling_in_vars = coupling.get("in_vars")

    #print(number_land_grid_cells)
    # TODO : it is only for testing now. The next block will be gone. 
    try:
        print(number_land_grid_cells)
    except:
        print("There is no valye for number of land grid cells")

    print(oasis)
    print(coupling_out_fields)
    print(coupling_in_vars)

    #return(t159,t255, t511, coupling_intervals, run_length_sec, oasis_component,oasis_output_unit,      \
    #       oasis_nx,coupling_out_fields, coupling_out_vars, coupling_in_fields, coupling_in_vars)
 

def build_toy_model():    
    print("The build script will be here")



if __name__ == '__main__':
# Open the file and load the file
    #with open('example_input_runoff.yaml') as f:
    with open('example_input_nemo.yaml') as f:
    #with open('example_input.yaml') as f:
        read_in_data = yaml.load(f, Loader=SafeLoader)
        model_name = read_in_data.get("model_name")
        print(model_name)
        f.close()

    # TODO should be initialized as function
    #t159,t255, t511, coupling_intervals, run_length_sec, oasis_component,oasis_output_unit,oasis_nx,coupling_out_fields, coupling_out_vars, coupling_in_fields, coupling_in_vars = {}
    
    read_yaml(read_in_data)
    build_toy_model()#t159,t255, t511, coupling_intervals, run_length_sec, oasis_component,oasis_output_unit, oasis_nx,coupling_out_fields, coupling_out_vars, coupling_in_fields, coupling_in_vars)
    
    exit()


