From da135e29c474c12a72c355232ad8482356949554 Mon Sep 17 00:00:00 2001
From: David <david.dorchies@inrae.fr>
Date: Thu, 5 Dec 2024 02:36:56 +0100
Subject: [PATCH] fix(RunModel.Supervisor): missing class and DatesR for
 OutputsModelReservoir

Refs #177
---
 R/RunModel.Supervisor.R            |  6 +++++-
 man-examples/RunModel.Supervisor.R | 12 +-----------
 man/RunModel.GR.Rd                 |  7 ++++---
 man/RunModel.Supervisor.Rd         | 12 +-----------
 4 files changed, 11 insertions(+), 26 deletions(-)

diff --git a/R/RunModel.Supervisor.R b/R/RunModel.Supervisor.R
index e28e79a..5dd28fa 100644
--- a/R/RunModel.Supervisor.R
+++ b/R/RunModel.Supervisor.R
@@ -160,7 +160,11 @@ RunModel.Supervisor <- function(x, RunOptions, Param, ...) {
 
   for (id in SD_Ids) {
     StateEnd <- x$OutputsModel[[id]]$StateEnd
-    x$OutputsModel[[id]] <- OutputsModelGR[[id]]
+    if (inherits(x$InputsModel[[id]], "GR")) {
+      x$OutputsModel[[id]] <- OutputsModelGR[[id]]
+    } else {
+      x$OutputsModel[[id]]$DatesR <- x$InputsModel[[1]]$DatesR[IndPeriod_Run]
+    }
     for (outputVar in outputVars[[id]]) {
       x$OutputsModel[[id]][[outputVar]] <- x$storedOutputs[[outputVar]][, id]
     }
diff --git a/man-examples/RunModel.Supervisor.R b/man-examples/RunModel.Supervisor.R
index 49ba398..55995bc 100644
--- a/man-examples/RunModel.Supervisor.R
+++ b/man-examples/RunModel.Supervisor.R
@@ -108,14 +108,4 @@ OM_dam <- RunModel(sv,
                    Param = P_severn)
 
 # Plotting the time series of flows and reservoir storage
-oldpar <- par(mfrow=c(2,1),
-              mar = c(2,3.3,1.2,0.5),
-              mgp = c(2,1,0))
-plot(attr(OM_dam, "Qm3s")[, c("DatesR", "54095", "Dam", "54057")],
-     ylim = c(0, 200))
-Vres <- as.Qm3s(DatesR = OM_dam$Dam$DatesR,
-                   "Simulated volume" = OM_dam$Dam$Vsim / 1E6)
-plot(Vres,
-     main = "Simulated reservoir storage",
-     ylab = expression("Storage (Mm" ^ "3" * ")"))
-par(oldpar)
+plot(OM_dam$Dam)
diff --git a/man/RunModel.GR.Rd b/man/RunModel.GR.Rd
index 8731eaa..d2dfb30 100644
--- a/man/RunModel.GR.Rd
+++ b/man/RunModel.GR.Rd
@@ -21,9 +21,10 @@
 If \code{InputsModel} parameter has been created for using a semi-distributed (SD) lag model (See \code{\link[airGR]{CreateInputsModel}}), the list value contains an extra item named \code{QsimDown} which is a numeric series of simulated discharge [mm/time step] related to the run-off contribution of the downstream sub-catchment.
 }
 \description{
-Function which performs a single model run with the provided function over the selected period.
+Run ONLY the rainfall-runoff model, upstream flow routing and Diversions are
+not processed.
 }
 \details{
-This function runs \link[airGR:RunModel]{airGR::RunModel} and add an item \code{Qsim_m3} to the returned
-\emph{OutputsModel} object.
+This function runs \link[airGR:RunModel]{airGR::RunModel} (without lag) and add an item \code{Qsim_m3}
+to the returned \emph{OutputsModel} object.
 }
diff --git a/man/RunModel.Supervisor.Rd b/man/RunModel.Supervisor.Rd
index ee26829..8adb2ac 100644
--- a/man/RunModel.Supervisor.Rd
+++ b/man/RunModel.Supervisor.Rd
@@ -132,15 +132,5 @@ OM_dam <- RunModel(sv,
                    Param = P_severn)
 
 # Plotting the time series of flows and reservoir storage
-oldpar <- par(mfrow=c(2,1),
-              mar = c(2,3.3,1.2,0.5),
-              mgp = c(2,1,0))
-plot(attr(OM_dam, "Qm3s")[, c("DatesR", "54095", "Dam", "54057")],
-     ylim = c(0, 200))
-Vres <- as.Qm3s(DatesR = OM_dam$Dam$DatesR,
-                   "Simulated volume" = OM_dam$Dam$Vsim / 1E6)
-plot(Vres,
-     main = "Simulated reservoir storage",
-     ylab = expression("Storage (Mm" ^ "3" * ")"))
-par(oldpar)
+plot(OM_dam$Dam)
 }
-- 
GitLab