library(s2dverification)

chunk <- as.integer(commandArgs(TRUE)[1])

ERAint <- '/esnas/reconstructions/ecmwf/eraint/$STORE_FREQ$_mean/$VAR_NAME$_f6h/$VAR_NAME$_$YEAR$$MONTH$.nc'

domain <- Load(var = "sfcWind", exp = NULL, obs = list(list(path=ERAint)), '19950101', storefreq = 'daily', leadtimemax = 1, output = 'lonlat', nprocs=1)
n.lat <- length(domain$lat)
n.lon <- length(domain$lon)

data <- Load(var = "sfcWind", exp = NULL, obs = list(list(path=ERAint)), '19950101', storefreq = 'daily', leadtimemax = 3, output = 'lonlat', latmin = domain$lat[chunk+1], latmax = domain$lat[chunk], nprocs=1)$obs
data <- data[,,,,1,]

n.lat <- 1
my.RMS <- array(NA, c(n.lat, n.lon))

# it is mandatory to save the output variable with the name 'var' and inside the file 'output_" + chunk number + ".RData":
var <- RMS(data,data+1)
save(var, file=paste0("/scratch/Earth/ncortesi/output_",chunk,".RData"))
