library(startR)

repos <- paste0('/esnas/exp/ecearth/i019/monthly_mean/',
                '$var$_*/$var$_Omon_EC-EARTH_i019_*S$sdate$_$member$_$chunk$.nc')

repos <- paste0('/home/Earth/aho/aho-testtest/startR/issue/',
                '$var$_Omon_EC-EARTH_i019_*S$sdate$_$member$_$chunk$.nc')

#region <- array('Barents_Sea', dim = c(chunk = 10, region = 1))
region <- 'Barents_Sea' #'Baffin'
region <- c('Grnland', 'Baffin')
data <- Start(dat = repos, 
              var = 'tosmean1', 
              sdate = '20051101', 
              member = 'all', 
              chunk = indices(1:3),  #'all', 
              time = 'all',
              region = region, # indices(1:2),   #region,
              chunk_depends = 'sdate', 
              time_across = 'chunk',  
              region_var= 'region',
              return_vars = list(region = NULL),
              merge_across_dims = FALSE, #TRUE,
              retrieve = TRUE)

  path <- '/esnas/exp/ecearth/i019/monthly_mean/tosmean1_f6h/tosmean1_Omon_EC-EARTH_i019_S20051101_r1i1p1_230507-230510.nc'
  fnc <- NcOpen(path)
  fnc_dims <- NcReadDims(fnc)
  var_names <- NcReadVarNames(fnc)
  fnc_arr <- NcToArray(fnc, vars_to_read = var_names)

  arr_sub <- Subset(fnc_arr, c('region'), list(c(1:19)))
  ArrayToNc(arr_sub, 'tosmean1_Omon_EC-EARTH_i019_S20051101_r1i1p1_230507-230510.nc')


