library(startR)
# Deborah solution
dates <- attr(Data_nca_init_1, 'Variables')$common$time   # Data_nca_init_1 is some decadal data that I already loaded, containing the forecast time dimension
dates_file <- sapply(dates, format, '%Y%m')
dim(dates_file) <- dim(dates)

Data_obs <- Start(dat = dataset,
              # outer dimensions
              var = var2,
              file_date = dates_file,
              # inner dimensions
              lat = 'all', #values(list(lats.min, lats.max)),
              lon = 'all', #values(list(lons.min, lons.max)),
	      return_vars = list(lat = 'dat', lon = 'dat', time = 'file_date'),
              split_multiselected_dims = TRUE,
	      retrieve = T)
# File example:
path <- "/esarchive/"
file <- 'tos_Omon_EC-Earth3_historical_r7i1p1f1_gr_199701-199712.nc'

file <- '/esarchive/exp/CMIP6/historical/ecearth/cmip6-historical_i0p1/tos_Omon_EC-Earth3_historical_r3i1p1f1_gn_185001-185012.nc'
data <- Start(dat = file,
              # outer dimensions
              var = 'tos',
              time = 'all',
              # inner dimensions
              i = indices(1:5), 
              j = indices(1:6), 
              return_vars = list(i = 'dat', j = 'dat', time = 'dat'),
              split_multiselected_dims = FALSE,
              retrieve = T)
data <- Start(model = fullpath_filenames[i],
                  var = var,
                  var_var = 'var_names',
                  time ='all',
                  latitude = 'all',
                  longitude = 'all',
                  longitude_var = 'longitude',
                  return_vars = list(time = 'model', longitude = 'model', latitude = 'model'),
                  synonims = list(longitude = c('lon', 'longitude'), latitude = c('lat', 'latitude')),
                  retrieve = TRUE,
                  split_multiselected_dims = TRUE)


vari = 'tos'
mod = 'Omon'
grid = 'gr'

#Load CMIP6 DCPP
repos <- paste0('/esarchive/exp/ecearth/a1ua/cmorfiles/DCPP/',
                'EC-Earth-Consortium/EC-Earth3/dcppA-hindcast/$memb$/', 
                mod, '/$var$/', grid, '/v20190320/$var$_', mod,
                '_EC-Earth3_dcppA-hinds$date$-$memb$_', grid,'_$ini$-$end$.nc')
file <- '/esarchive/exp/ecearth/a1ua/cmorfiles/DCPP/EC-Earth-Consortium/EC-Earth3/dcppA-hindcast/r1i1p1f1/Omon/tos/gn/v20190320/tos_Omon_EC-Earth3_dcppA-hindcast_s19601101-r1i1p1f1_gn_196011-196110.nc'
data <- Start(dat = file,
              var = 'tos',
              i = indices(1:5),
              j = indices(1:6),
              time = 'all',
              retrieve = TRUE)
file <- '/esarchive/exp/ecearth/a1ua/cmorfiles/DCPP/EC-Earth-Consortium/EC-Earth3/dcppA-hindcast/r1i1p1f1/Omon/tos/gn/v20190320/tos_Omon_EC-Earth3_dcppA-hindcast_s19601101-r1i1p1f1_gn_$ini$-$end$.nc'
data <- Start(dat = file,
              var = 'tos',
              ini = '196011',
              end = '196110',
              i = indices(1:5),
              j = indices(1:6),
              time = 'all',
              retrieve = TRUE)


data_cmip6_1 <- Start(dat = repos,
              var = vari,
              memb = c('r1i1p1f1'),
              date = '19600101',
              ini = '196011',
              end = '196010',
              time = c(1:12),
              #chunk = 'all',
              i = indices(1:5),
              j = indices(1:6),
              #chunk_depends = 'sdate',
              #time_across = 'chunk',
              #merge_across_dims = TRUE,
              return_vars = list(i = NULL, j = NULL),
              retrieve = T,
              split_multiselected_dims = TRUE)

