source("tools/libs.R")
## TODO: Remove with the next release
source("modules/Loading/load_datasets.R")

Loading <- function(recipe) {
  # Source correct function depending on filesystem and time horizon
  # Case: CERISE (Mars)
  if (tolower(recipe$Run$filesystem) == "mars") {
    source("modules/Loading/R/load_GRIB.R")
    data <- load_GRIB(recipe)
  } else {
    # Case: esarchive
    time_horizon <- tolower(recipe$Analysis$Horizon)
    if (time_horizon == "seasonal") {
      if(recipe$Analysis$Variables$name == 'tas-tos') {
        source("modules/Loading/R/load_tas_tos.R")
        data <- load_tas_tos(recipe) 
       } else {
        source("modules/Loading/R/load_seasonal.R")
        data <- load_seasonal(recipe)
       }
    } else if (time_horizon == "decadal") {
      source("modules/Loading/R/load_decadal.R")
      data <- load_decadal(recipe)
    } else {
      stop("Incorrect time horizon.")
    }
  }
  return(data)
}
