#!/usr/bin/env Rscript
args = commandArgs(trailingOnly = TRUE)

# Author: N.Pérez-Zanón 26th July 2021
# execution: Rscript OperationalCS.R conf_user.yml recipe.yml
# This code should process and check the recipe and build the workflow
print(args)
library(yaml)
conf <- read_yaml(args[1]) # conf <- read_yaml("conf_user.yml")
recipe <- read_yaml(args[2]) # recipe <- read_yaml("recipe_seasonal.yml")

# Load required libraries
source("data_analysis/libraries.R")

check_conf(conf, file = args[1]) # check_conf(conf, file = "conf_user.yml")
verifications <- check_recipe(recipe, file = args[2], conf) 
# verifications <- check_recipe(recipe, file = "recipe.yml", conf)

for (indep in verifications$independent) {  
  variable <- indep
  fcst.sdate <- recipe$Analysis$Time$forecast_sdate
  fcst.freq <- recipe$Analysis$Time$freq
  hcst.inityear <- recipe$Analysis$Time$hindcast_start
  hcst.endyear <- recipe$Analysis$Time$hindcast_end
  fcst.name <- recipe$Analysis$Datasets$System[[1]]$name
  ref.name <- recipe$Analysis$Datasets$Reference[[1]]$name
  ltmin <- recipe$Analysis$Time$leadtimemin 
  ltmax <- recipe$Analysis$Time$leadtimemax
  lats.min <- recipe$Analysis$Region$Regional[[1]]$latmin
  lats.max <- recipe$Analysis$Region$Regional[[1]]$latmax
  lons.min <- recipe$Analysis$Region$Regional[[1]]$lonmin
  lons.max <- recipe$Analysis$Region$Regional[[1]]$lonmax
  stream <- "fcst"
  source("data_analysis//seas5.load.R")
}



