library(startR)

  repos <- "/esarchive/exp/ecmwf/system5_m1/monthly_mean/tas_f6h/$var$_$sdate$.nc"
  var <- 'tas'
  sdate <- c('20170101', '20170201')
  data <- Start(dat = repos,
                var = var, #c('tas', 'latitude', 'longitude'), #lat and lon are NANs
                sdate = indices(1), #sdate,
                ensemble = indices(1),
                time = indices(1), #'all',
                latitude = 'all', #indices(1:100),
                longitude = 'all', #indices(1:100),
                return_vars = list(time = c('sdate'), longitude = NULL, latitude = NULL),
                retrieve = FALSE
               )
  func <- function(x) {
#     apply(x + 1, 2, mean)
    a <- apply(x + 1, 2, mean)
    dim(a) <- c(time = length(a))   #give it a name!!!!
    return(a)
  }
  step <- Step(func, target_dims = c('ensemble', 'time'),
                    output_dims = c('time'))
  wf <- AddStep(data, step)

  res <- Compute(wf,
                 chunks = list(latitude = 2,
                               longitude = 2),#$output1
                 threads_load = 2,
                 threads_compute = 4,
                 cluster = list(queue_host = 'p1',
                                queue_type = 'slurm',
                                temp_dir = '/gpfs/scratch/bsc32/bsc32734/startR_hpc/',
                                lib_dir = '/gpfs/projects/bsc32/share/R_libs/3.5/',
                                #r_module = 'R/3.5.0-foss-2018b',
                                r_module = 'startR/0.1.2-foss-2018b-R-3.5.0',
                                #r_module = 'R/3.4.2-foss-2015a-bare',
                                job_wallclock = '00:10:00',
                                cores_per_job = 4,
                                max_jobs = 4,
                                bidirectional = FALSE,
                                polling_period = 50
                               ),
                 ecflow_suite_dir = '/home/Earth/aho/startR_local/',
                 #ecflow_suite_dir = '/esarchive/scratch/aho/ecFlow/',
                 wait = TRUE
                 )  #$output1

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

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

