var <- 'tas'; startMonths <- c('03', '04', '05', '06'); sm <- 4
library(s2dverification)
library(rgdal)
library(sp)
library(easyNCDF)
library(CSTools)
library(multiApply)
library(raster)
library(fields)
library(ncdf4)
library(easyVerification)
library(s2dv)


path_ERA5_CDS <- list(path = '/esarchive/recon/ecmwf/era5/monthly_mean/$VAR_NAME$_f1h-r1440x721cds/$VAR_NAME$_$YEAR$$MONTH$.nc')
lonmax <- 4; lonmin <- 350; latmax <- 44; latmin <- 35.6
leadtimemin <- 1; leadtimemax <- 7; cdoMethod <- 'bicubic'
sdates <- paste0(2019, '11', '01')
data <- Load(var = 'tas', exp = NULL, obs = list(path_ERA5_CDS),
                 sdates = '20191101', 
                 storefreq = 'monthly',lonmin = 0, lonmax = 359.75,
                 latmax = 90, latmin = -90,
                 leadtimemin = 1, leadtimemax = 2,
                 nprocs = 1, output = "lonlat")#, grid = "r1440x721", method = cdoMethod)


library(startR)
path <- '/esarchive/recon/ecmwf/era5/monthly_mean/$var$_f1h-r1440x721cds/$var$_$file_date$.nc'
dates_file <- c("201911","201920","202001","201412")
dates_file <- format(c(seq(as.Date("2018-11-01", "%Y-%m-%d"), 
                           as.Date("2019-05-01", "%Y-%m-%d"), 'month'), 
                       seq(as.Date("2019-11-01", "%Y-%m-%d"), 
                           as.Date("2020-05-01", "%Y-%m-%d"), 'month')), 
                      "%Y%m")
 

dim(dates_file) <- c(time = 7, sdate = 2)

obs <- Start(dat = path,
             var = 'tas',
             file_date = dates_file,
             lat = values(list(35.6, 44)),
             lat_reorder = Sort(decreasing = TRUE),
             lon = values(list(350, 4)),
             lon_reorder = CircularSort(-180, 180),
             return_vars = list(lat = 'dat',
                                lon = 'dat',
                                time = 'file_date'),
             split_multiselected_dims = TRUE,
             retrieve = TRUE)
              
