library(yaml)
library(startR)
decadal_dic <- read_yaml("/esarchive/scratch/nperez/git/Flor/Decadal/archive.yml")
names(decadal_dic$esarchive$Decadal)
  # to read from recipe:
  model = 'HadGEM3'
  var = 'tas'
  lat_min = 0
  lat_max = 10
  lon_min = 0
  lon_max = 10
  sim <- 'historical'
  #model = 'EC-Earth3-i1'
  sdates <- 1960:2015
  member <- NULL
  years_hist <- 1961:2014

  if ('var_name' %in% names(decadal_dic$esarchive$Decadal[[model]][[sim]][[var]])) {
    var_name <- decadal_dic$esarchive$Decadal[[model]]$hist[[var]]$var_name
  } else {
    var_name <- var
  }
  if (is.null(member)) {
    members <- decadal_dic$esarchive$Decadal[[model]][[sim]]$member
  }

  hist <- Start(path = decadal_dic$esarchive$Decadal[[model]][[sim]][[var]]$path,
                var = var_name,
                year = as.character(years_hist),
                month = 'all',
                lat = values(list(lat_min, lat_max)),
                lon = values(list(lon_min, lon_max)),
                member = members,
                synonims = list(month = c('month','time'), 
                                lon = c('lon', 'longitude'), 
                                lat = c('lat', 'latitude')),
                return_vars = list(lat = 'dataset', lon = 'dataset'),
                lat_reorder = Sort(decreasing = F),
                lon_reorder = CircularSort(0, 360),
                num_procs = 1, retrieve = F)


                month = time_aux,
                lat = values(list(lat_min, lat_max)),
                lon = values(list(lon_min, lon_max)),
                member = members,
                synonims = list(month = c('month','time')),
                return_vars = list(lat = 'dataset', lon = 'dataset'),
                lat_reorder = Sort(decreasing = F),
                lon_reorder = CircularSort(0, 360),
                num_procs = 1, retrieve = F)

