  repos <- paste0('/esarchive/exp/ecmwf/system4_m1/$freq$/',
                  '$var$*/$var$_$sdate$.nc')
  sdate <- '19940501'
  system4 <- Start(dat = repos,
                   var = 'uas',
                   sdate = sdate,
                   freq = c('6hourly', 'daily_mean'),
                   time = 'all',#indices(seq(1, 124, 4)),  #first time step per day
                   ensemble = indices(1), #'all',
                   latitude = indices(1), #'all', #indices(1:10),
                   longitude = indices(1), #'all', #indices(1:10),
                   return_vars = list(latitude = NULL,
                                      longitude = NULL,
                                      time = c('sdate')),
                   retrieve = T, path_glob_permissive = 2)










dir = '/esarchive/scratch/lpalma/CF-S2S/data-analysis/CF/ratios/Wind_power_model/country_level_wind_power_installed_capacity/$country$_one_half_deg_windfarm_dist.nc'
dir = '/home/Earth/nperez/$var$/country_level_wind_power_installed_capacity/$country$_one_half_deg_windfarm_dist.nc'

europe.countries.iso <- c( "AUT", "BEL", "BGR", "HRV", "CYP", "CZE", "DNK", 
"EST", "FIN", "FRA", "DEU", "GRC",
 "HUN", "IRL", "ITA", "LVA", "LTU" ,"NLD", "POL", "PRT", "ROU", "SVK",
 "SVN", "ESP",
 "SWE", "GBR", "NOR", "ISL", "CHE", "BIH", "SRB", "MNE", "MKD", "ALB", "TUR", "MDA",
"BLR","UKR")
Country_inst_WP <- Start(var = "totals",
                            dat = dir,
                            pattern_dims = 'dat',
                            country = europe.countries.iso,
latitude = 'all', longitude = 'all',
#                            latitude = values(list(lats.min, lats.max)),
#                            latitude_reorder = Sort(decreasing = TRUE),
#                            longitude = values(list(lons.min, lons.max)),
#                            longitude_reorder = longitude_reorder,
                            synonims = list(latitude=c('lat','latitude'),
                                            longitude=c('lon','longitude')),
                            return_vars = list(latitude = 'dat',
                                               longitude = 'dat'),
metadata_dims = 'country',
                            retrieve = F, largest_dims_length = F)
library(startR)

obs_path <- '/esarchive/recon/ecmwf/era5/monthly_mean/$var$_f1h/$var$_$sdate$.nc'
var_name <- 'sfcWind'

lons.min <- 10
lons.max <- 20
lats.min <- 0
lats.max <- 10

#-------------------------
# Start()
#-------------------------
obs <- Start(dat = obs_path,
             var = var_name,
             sdate = c('201811', '201911', '202011'),
             time = 'all', latitude = 'first', longitude = 'first',
#             latitude = values(list(lats.min, lats.max)),
#             latitude_reorder = Sort(decreasing = T),
#             longitude = values(list(lons.min, lons.max)),
#             longitude_reorder = CircularSort(0, 360),
#             synonims = list(longitude = c('lon', 'longitude'),
#                             latitude = c('lat', 'latitude')),
#             transform = CDORemapper,
#             transform_extra_cells = 2,
#             transform_params = list(grid = 'r360x181',
#                                     method = 'conservative',
#                                     crop = c(lons.min, lons.max, lats.min, lats.max)),
#             transform_vars = c('latitude', 'longitude'),
#             return_vars = list(time = NULL,
#                                latitude = 'dat',
#                                longitude = 'dat'),
             retrieve = T)


