library(startR)

  repos <- "/esarchive/exp/ecmwf/system5_m1/monthly_mean/$var$_f6h/$var$_$sdate$.nc"
  var <- 'tas'
  sdate <- c('20170101')#, '20170201')
  
  t_begin_total <- Sys.time()
  data_Start <- Start(dat = repos,
                var = var, 
                sdate = sdate,
                ensemble = indices(1),
                time = 'all',
                latitude = 'all', #indices(1:100),
                longitude = 'all', #indices(1:100),
                return_vars = list(time = c('sdate'), 
                                   longitude = NULL, latitude = NULL),
                retrieve = TRUE
               )
  t_end_total <- Sys.time()

  print(paste0('Start time: ', as.numeric(difftime(t_end_total, 
                                                   t_begin_total, units = 'secs'))))


library(s2dverification)
#s2dv
   ecearth <- list(name = 'system5_m1',
                   path = file.path('/esarchive/exp/ecmwf',
                                    '$EXP_NAME$/$STORE_FREQ$_mean',  #month_mean',
                                    '$VAR_NAME$_f6h/$VAR_NAME$_$START_DATE$.nc'))
   startDates <- sdate
   time_length <- 7
   lon <- c(0, 359)
   lat <- c(-90, 90)

   t_begin_total <- Sys.time()
   data_Load <- Load(var = 'tas',
                     exp = list(ecearth),
                     sdates = startDates,
                     storefreq = "monthly",
                     leadtimemax = time_length,
                     output = 'lonlat',
                     nmember = 1)
                     #lonmin = lon[1], lonmax = lon[2],
                     #latmin = lat[1], latmax = lat[2])

  t_end_total <- Sys.time()
  print(paste0('Load time: ', as.numeric(difftime(t_end_total,
                                                  t_begin_total, units = 'secs'))))

#Plot
  lons <- data_Load$lon
  lats <- data_Load$lat
#plot Load
  PlotEquiMap(data_Load$mod[1, 1, 1, 1, , ], lons, lats, toptitle = 'Load')
#plot Start
  PlotEquiMap(data_Start[1, 1, 1, 1, 1, , ], lons, lats, toptitle = 'Start')

