
source("modules/Loading/Loading.R")
source("modules/Saving/Saving.R")
source("modules/Units/Units.R")
source("modules/Visualization/Visualization.R")
#args = commandArgs(trailingOnly = TRUE)
#recipe_file <- args[1]
recipe_file <- "recipe_NAO.yml"
#recipe <- read_atomic_recipe(recipe_file)
original_recipe <- prepare_outputs(recipe_file, disable_checks = TRUE)
models <- unlist(original_recipe$Analysis$Datasets$System)

recipe_aux <- original_recipe
datos <- list()
datos$hcst <- list()
datos$fcst <- list()
NAO_ind <- list()
source("modules/Crossval/Crossval_metrics.R")
source("modules/Crossval/Crossval_NAO.R")
for (sys in models[1:2]) {
  recipe_aux$Analysis$Datasets$System <- NULL
  recipe_aux$Analysis$Datasets$System$name <- as.vector(sys)
  # Load datasets
  data <- Loading(recipe = recipe_aux)
  data <- Units(recipe = recipe_aux, data = data)
  # Verification individual models
  product <- Crossval_NAO(recipe = recipe_aux, data = data)
  source("plot_NAO.R")
  plot_NAO(recipe = recipe_aux, nao = product, data = data)
   
  skill_model <- Crossval_metrics(recipe = recipe_aux,
				  data_crossval = product,
                                  fair = FALSE, nmemb = NULL, nmemb_ref = NULL) 
  datos$hcst <- append(datos$hcst, list(data$hcst))
  datos$fcst <- append(datos$fcst, list(data$fcst))
  names(datos$hcst)[length(datos$hcst)] <- gsub('\\.','', sys)
  names(datos$fcst)[length(datos$fcst)] <- gsub('\\.','', sys)
  NAO_ind <- append(NAO_ind, list(product))
  names(NAO_ind)[length(NAO_ind)] <- gsub('\\.','', sys)
}
# No visualisation available for region aggregated
data_aux <- data
datos$obs <- data$obs
data <- datos
rm(list = 'datos')
source("modules/Crossval/Crossval_multimodel_NAO.R")
res <- Crossval_multimodel_NAO(recipe = original_recipe, data = data)


