library(startR)
repos <- '/esarchive/exp/ecearth/a1ua/cmorfiles/DCPP/EC-Earth-Consortium/EC-Earth3/dcppA-hindcast/r10i1p1f1/Omon/tos/gr/v20190713/$var$_Omon_EC-Earth3_dcppA-hindcast_s$sdate$-$memb$_gr_$chunk$.nc'

data <- Start(dat = repos,
              var = 'tos',
              memb = c('r10i1p1f1'),
              sdate = c('1960', '1965'),
              time = indices(1:26),
              chunk = 'all',
              lat = 'all',
              lon = 'all',
              chunk_depends = 'sdate',
              time_across = 'chunk',
              merge_across_dims = TRUE,
              return_vars = list(lat = NULL, lon = NULL, time = NULL),
              retrieve = F)
attributes(data)$Variables$common$time

# Attempt 1:
path = '/esarchive/exp/ecearth/a1ts/cmorfiles/CMIP/EC-Earth-Consortium/EC-Earth3/historical/r25i1p1f1/Omon/$var$/gr/v20190312/$var$_Omon_EC-Earth3_historical_$memb$_gr_$sdate$.nc'

sdates <- c('196001-196012', '196101-196112', '196201-196212', '196301-196312',
           '196501-196512','196601-196612', '196701-196712', '196801-196812') 

data <- Start(dat = path,
              var = 'tos',
              memb = c('r25i1p1f1'),
              sdate = sdates,
              time = indices(11:34),
              #time = 'all',
              lat = 'all',
              lon = 'all',
              time_across = 'sdate',
              merge_across_dims = TRUE,
              #split_multiselected_dims = TRUE,
              return_vars = list(lat = NULL, lon = NULL, time = NULL),
              retrieve = FALSE)

# Attempt 2:

dates <- as.POSIXct(c(seq.Date(as.Date('1960-11-15', format = '%Y-%m-%d'),
                   as.Date('1963-10-15', format = '%Y-%m-%d'),
                   by = 'month'), seq.Date(as.Date('1965-11-15', format = '%Y-%m-%d'),
                   as.Date('1968-10-15', format = '%Y-%m-%d'),
                   by = 'month')))
dim(dates) <- c(time = 36, syear = 2)
path = '/esarchive/exp/ecearth/a1ts/cmorfiles/CMIP/EC-Earth-Consortium/EC-Earth3/historical/$memb$/Omon/$var$/gr/v20190312/$var$_Omon_EC-Earth3_historical_$memb$_gr_$date$.nc'

sdates <- c('196001-196012', '196101-196112', '196201-196212', '196301-196312',
          '196501-196512','196601-196612', '196701-196712', '196801-196812')


data <- Start(dat = path,
              var = 'tos',
              memb = c('r25i1p1f1'),
              date = sdates,
              time = dates,
              lat = 'all',
              lon = 'all',
              time_across = 'date',
              #merge_across_dims = TRUE,
              split_multiselected_dims = TRUE,
              return_vars = list(lat = NULL, lon = NULL, time = NULL),
              retrieve = FALSE)

# Attemp 3

sdates <- cbind(c('196001-196012', '196101-196112', '196201-196212', '196301-196312'),
           c('196501-196512','196601-196612', '196701-196712', '196801-196812'))
names(dim(sdates)) <- c('chunks', 'syears')
 
data <- Start(dat = path,
              var = 'tos',
              memb = c('r25i1p1f1'),
              sdate = sdates,
              time = indices(11:34),
              #time = 'all',
              lat = 'all',
              lon = 'all',
              time_across = 'chunks',
              #merge_across_dims = TRUE,
              split_multiselected_dims = TRUE,
              return_vars = list(lat = NULL, lon = NULL, time = NULL),
              retrieve = FALSE)

