library(startR)
# sdate 1990 tiene diferente version 
# v20200101 para 1962 1981
# v20200731 para 1990
cmipmodel = 'cesm1-1-cam5-cmip5'
vari = 'msftmz'
mod = 'Omon'
grid = 'gn'
fl = 'cmorfiles'
membs = c('r1i1p1f1','r2i1p1f1')

#,'r3i1p1f1','r4i1p1f1','r5i1p1f1','r6i1p1f1','r7i1p1f1','r8i1p1f1','r9i1p1f1','r10i1p1f1')
#membs = c('r1i1p1f1')
nmemb=10
times = c(3:122)
#times = c(1:12)
repos <- paste0('/esarchive/exp/cesm1-1-cam5-cmip5/cmip6-dcppA-hindcast_i1p1/original_files/cmorfiles/DCPP/NCAR/CESM1-1-CAM5-CMIP5/dcppA-hindcast/$memb$/',mod,'/$var$/',grid,'/$version$/$var$_',mod,'_CESM1-1-CAM5-CMIP5_dcppA-hindcast_s$sdate$-$memb$_',grid,'_*.nc',sep='')
data_volc <- Start(dat = repos,
             var = vari,
             memb = membs,
             sdate = c('1962','1981', '1990'),
             time = indices(3:12),
             basin = indices(1),
             lev = 'all',
             lat = indices(1:4),
             version = 'all', #indices(1:2),# list('1962' = 'v20200731',
                            #'1981' = 'v20200731', 
                            #'1990' = 'v20200101'),
             version_depends = 'sdate',
             #sdate_depends = 'version',
             #chunk = 'all',
             #chunk_depends = 'sdate',
             #time_across = 'chunk',
             #merge_across_dims = TRUE,
             return_vars = list(time = NULL, lev=NULL, lat=NULL),
             path_glob_permissive = 2,
             retrieve = TRUE)

source("/esarchive/scratch/nperez/git/startR/R/multiStart.R")
source("/esarchive/scratch/nperez/git/startR/R/zzz.R")
.warning <- startR:::.warning()

repos <- list(v20200731 = list(name = 'v20200731', path = 
                               paste0('/esarchive/exp/cesm1-1-cam5-cmip5/cmip6-dcppA-hindcast_i1p1/original_files/cmorfiles/DCPP/NCAR/CESM1-1-CAM5-CMIP5/dcppA-hindcast/$memb$/',
      mod,'/$var$/',grid,'/v20200731/$var$_',mod,
     '_CESM1-1-CAM5-CMIP5_dcppA-hindcast_s$sdate$-$memb$_',grid,'_$chunk$.nc',sep='')),
         list(v20200101 = list(name = 'v20200101', path = 
                               paste0('/esarchive/exp/cesm1-1-cam5-cmip5/cmip6-dcppA-hindcast_i1p1/original_files/cmorfiles/DCPP/NCAR/CESM1-1-CAM5-CMIP5/dcppA-hindcast/$memb$/',mod,
    '/$var$/',grid,'/v20200101/$var$_',mod,
    '_CESM1-1-CAM5-CMIP5_dcppA-hindcast_s$sdate$-$memb$_',grid,'_$chunk$.nc',sep=''))))
multiStart(dat = repos,
             var = vari,
             memb = membs,
             #sdate = c('1962','1981', '1990'),
             sdate = list(list(name = 'v20200731', sdate = c(1,8)), 
                          list(name = 'v20200101',  sdate = c(1))),
             time = indices(3:12),
             basin = indices(1),
             lev = 'all',
             lat = indices(1:4),
             chunk = 'all',
             chunk_depends = 'sdate',
             #time_across = 'chunk',
             #merge_across_dims = TRUE,
             #return_vars = list(time = NULL, lev=NULL, lat=NULL),
             retrieve = TRUE)

