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) %in% c("cerise", "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") {
      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.")
    }
  }
  # Display data summary
  if (recipe$Run$logger$threshold <= 2) {
    data_summary(data$hcst, recipe)
    data_summary(data$obs, recipe)
    if (!is.null(data$fcst)) {
      data_summary(data$fcst, recipe)
    }
  }
  return(data)
}
