library(startR)

path = '/esarchive/exp/ecearth/a1ua/cmorfiles/DCPP/EC-Earth-Consortium/EC-Earth3/dcppA-hindcast/$member$/$type$/$var$/gr/v20190713/$var$_$type$_EC-Earth3_dcppA-hindcast_s$sdate$-$member$_gr_$fyear$.nc'

data <- Start(dataset = path,
              var = c('tas', 'tos'),
              type = 'all',
              type_depends = 'var',
              sdate = paste0(1960:1962),
              fmonth = 1,
              lat = values(list(0, 10)),
              lon = values(list(0, 10)),
              fyear = indices(1),
              member = indices(1:2),
              fyear_depends = 'sdate',
              fmonth_across = 'fyear',
              merge_across_dims = TRUE,
              synonims = list(fmonth = c('fmonth','time'),
                              lon = c('lon', 'longitude'),
                              lat = c('lat', 'latitude')),
              return_vars = list(lat = 'dataset', lon = 'dataset'),
              num_procs = 2, retrieve = TRUE)



paths = list(list(path = '/esarchive/exp/ecearth/a1ua/cmorfiles/DCPP/EC-Earth-Consortium/EC-Earth3/dcppA-hindcast/$member$/Omon/tos/gr/v20190713/$var$_Omon_EC-Earth3_dcppA-hindcast_s$sdate$-$member$_gr_$fyear$.nc'),
             list(path = '/esarchive/exp/ecearth/a1ua/cmorfiles/DCPP/EC-Earth-Consortium/EC-Earth3/dcppA-hindcast/$member$/Amon/tas/gr/v20190713/$var$_Amon_EC-Earth3_dcppA-hindcast_s$sdate$-$member$_gr_$fyear$.nc'))
data = startR::Start(dataset = paths,
                     var = c('tas','tos'),
                     sdate = paste0(1960:1962),
                     fmonth = c(1:12),
                     lat = values(list(-90, 90)),
                     lon = values(list(0, 359.9)),
                     fyear = 'all',
                     member = indices(1:2),
                     fyear_depends = 'sdate',
                     fmonth_across = 'fyear',
                     merge_across_dims = TRUE,
                     synonims = list(fmonth = c('fmonth','time'), lon = c('lon', 'longitude'), lat = c('lat', 'latitude')),
                     return_vars = list(lat = 'dataset', lon = 'dataset'),
                     num_procs = 4, retrieve = TRUE)
lat = as.vector(attributes(data)$Variables$dat1$lat)
lon = as.vector(attributes(data)$Variables$dat1$lon)
# > dim(data)
# dataset     var   sdate  fmonth     lat     lon  member 
# 2             2       3      12     256     512       2 
data_tas = data[1,2,,,,,]
data_tos = data[2,1,,,,,]
# > dim(data_tas)
# sdate fmonth    lat    lon member 
#     3     12    256    512      2 
# > dim(data_tos)
# sdate fmonth    lat    lon member 
#     3     12    256    512      2 
PlotEquiMap(var = data_tas[1,1,,,1], lon = lon, lat = lat, filled.continents = F, toptitle = 'tas')
PlotEquiMap(var = data_tos[1,1,,,1], lon = lon, lat = lat, filled.continents = F, toptitle = 'tos')
