#  library(startR)

  repos <- "/esarchive/exp/ecmwf/system5_m1/monthly_mean/tas_f6h/$var$_$sdate$.nc"

  #easyNCDF::NcReadDims('/esarchive/exp/ecmwf/system5_m1/monthly_mean/tas_f6h/tas_20170101.nc',
  #                     var_names = 'tas')

  var <- 'tas'
  #sdate <- c(paste0('2017', '0', c(1:9), '01'), paste0('2017', c(10:12), '01'))
  sdate <- '20170101'
  #exp <- list('r4i1p1', 'r5i1p1')

  data <- Start(dat = repos,
                var = var,
                sdate = '20170101',
                ensemble = 'all', #indices(c(1:5)),
                time = 'all',
                latitude = indices(1:40),
                longitude = indices(1:50),
                return_vars = list(longitude = NULL, latitude = NULL),
                retrieve = FALSE
               )

 fun <- function(x) {
              apply(x, c(which(names(dim(x)) != 'ensemble')), mean)
            }

  step <- Step(fun, target_dims = c('ensemble',  'time'),
                    output_dims = c( 'time'))

  wf <- AddStep(data, step)
  
#Compute() on fatnodes
#  res <- Compute(wf,
#                 chunks = list(latitude = 2,
#                               longitude = 2),#$output1
#                 threads_load = 2,
#                 threads_compute = 4,
#                 cluster = list(queue_host = 'fat',
#                                queue_type = 'slurm',
#                                cores_per_job = 2,
#                                job_wallclock = '00:10:00',
#                                max_jobs = 4,
#                                bidirectional = TRUE
#                 ),
#                 ecflow_suite_dir = '/home/Earth/aho/startR_local/'
##                 wait = TRUE
#         )

#Compute() locally
  res <- Compute(wf,
                 chunks = list(latitude = 2,
                               longitude = 2))


  saveRDS(res, file = 'test_data_fat.Rds')

  dim(res$output1)

  
#  asd <- Apply(data, target_dims = c('ensemble', 'time'), fun = fun)$output1
#  names(dim(asd))[1] <- 'time'

