# Example of loading Climate Projections data with Start:
# Nuria 05 April 2019
# ---------------------------------------------------------

path <- "/home/Earth/nperez/git/ESMValTool/output_dir/recipe_multimodel_products_wp5_20190129_111548/preproc/anomaly_agreement/tas/"

files <- list.files(path, ".nc")
hist <- files[grepl("historical", files)]
future <- files[-grepl("historical", files)]

var_names <- list("bcc-cms-1-1", "MIROC5", "MPI-ESM-MR")
climatology_filenames <- paste0(path, hist)
var0 <- 'tas'
reference_data <- Start(model = climatology_filenames,
                        var = var0,
                        var_var = 'var_names',
                        time = 'all',
                        lat = 'all',
                        lon = 'all',
                        lon_var = 'lon',
                        return_vars = list(time = 'model', lon = 'model', lat = 'model'),
                        retrieve = TRUE)

lat <- attr(reference_data, "Variables")$dat1$lat
# Explore more elements and attributes

projection_filenames <- paste0(path, future)
projection_data <- Start(model = projection_filenames,
                        var = var0,
                        var_var = 'var_names',
                        time = 'all',
                        lat = 'all',
                        lon = 'all',
                        lon_var = 'lon',
                        return_vars = list(time = 'model', lon = 'model', lat = 'model'),
                        retrieve = TRUE)

