library(CSTools)
library(zeallot)
glosea5 <- '/esnas/exp/glosea5/specs-seasonal_i1p1/$STORE_FREQ$_mean/$VAR_NAME$-allmemb/$VAR_NAME$_$START_DATE$.nc'
c(exp, obs) %<-% CST_Load(var = 'tas', exp = list(list(name = 'glosea5', path = glosea5),
                                                                           list(name = 'ecmwf/system4_m1'),
                                                                           list(name = 'meteofrance/system5_m1')),
                                                obs = "erainterim", sdates = '19921101',
                                                leadtimemin = 2, leadtimemax = 2,
                                                lonmin = -20, lonmax = 70, latmin = 25, latmax = 75, 
                                                storefreq = "monthly", sampleperiod = 1,  nmember = 15, 
                                                output = "areave")

dim(exp$data)
stats <- c(apply(exp$data - 273.15, 1, mean),
           apply(exp$data - 273.15, 1, function(x){sqrt(var(x))}))
dim(stats) <- c(dataset = 3, statistics = 2)
Glosea5PDF <- stats[1,]
dim(Glosea5PDF) <- c(statistic = 2)
attr(Glosea5PDF, "name") <- "Glosea5"
ECMWFPDF <- stats[2,]
dim(ECMWFPDF) <- c(statistic = 2)
attr(ECMWFPDF, "name") <- "ECMWF"
MFPDF <- stats[3,]
dim(MFPDF) <- c(statistic = 2)
attr(MFPDF, "name") <- "MeteoFrance"

library(ggpubr)
ggarrange(PlotPDFsOLE(pdf_1 = Glosea5PDF, pdf_2 = ECMWFPDF, legendPos = 'right'),
          PlotPDFsOLE(pdf_1 = Glosea5PDF, pdf_2 = MFPDF, legendPos = 'right'),
          PlotPDFsOLE(pdf_1 = ECMWFPDF, pdf_2 = MFPDF, legendPos = 'right'), 
          ncol = 1, nrow = 3)
ggarrange(PlotPDFsOLE(pdf_1 = Glosea5PDF, pdf_2 = ECMWFPDF),
          PlotPDFsOLE(pdf_1 = Glosea5PDF, pdf_2 = MFPDF),
          PlotPDFsOLE(pdf_1 = ECMWFPDF, pdf_2 = MFPDF),
          ncol = 1, nrow = 3)

PlotPDFsOLE(pdf_1 = Glosea5PDF, pdf_2 = ECMWFPDF)
PlotPDFsOLE(pdf_1 = Glosea5PDF, pdf_2 = MFPDF)
PlotPDFsOLE(pdf_1 = ECMWFPDF, pdf_2 = MFPDF)

