From 14f7dc8c84c842ffcdebb8cafe338a8f71b13e9f Mon Sep 17 00:00:00 2001
From: Delaigue Olivier <olivier.delaigue@irstea.fr>
Date: Mon, 4 May 2020 09:47:30 +0200
Subject: [PATCH] v1.4.8.0 feat: added .AggregOutputs function to choose
 ConvertFun to apply on InputsModel and OutputsModel elements #41

---
 DESCRIPTION |  2 +-
 NEWS.md     |  3 ++-
 R/Utils.R   | 23 +++++++++++++++++++++++
 3 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/DESCRIPTION b/DESCRIPTION
index 3fd81ccf..e5be887b 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,7 +1,7 @@
 Package: airGR
 Type: Package
 Title: Suite of GR Hydrological Models for Precipitation-Runoff Modelling
-Version: 1.4.7.6
+Version: 1.4.8.0
 Date: 2020-05-04
 Authors@R: c(
   person("Laurent", "Coron", role = c("aut", "trl"), comment = c(ORCID = "0000-0002-1503-6204")),
diff --git a/NEWS.md b/NEWS.md
index dc91fc92..b614454f 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -4,7 +4,7 @@
 
 
 
-### 1.4.7.6 Release Notes (2020-05-04)
+### 1.4.8.0 Release Notes (2020-05-04)
 
 #### New features
 
@@ -13,6 +13,7 @@
 - Added <code>SeriesAggreg2.InputsModel()</code> function.
 - Added <code>SeriesAggreg2.OutputsModel()</code> function.
 - Added <code>SeriesAggreg2.data.frame()</code> function. This new verson of the <code>SeriesAggreg()</code> function allows to compute regimes.
+- Added<code>.AggregOutputs()</code> private function in order to choose automatically the <code>ConvertFun</code> to apply on each element of <code>InputsModel</code> and <code>OutputsModel</code> ojects.
 
 
 #### Deprecated and defunct
diff --git a/R/Utils.R b/R/Utils.R
index 2c7a7ba6..158606f7 100644
--- a/R/Utils.R
+++ b/R/Utils.R
@@ -12,6 +12,29 @@
 # }
 
 
+
+## =================================================================================
+## function to manage Fortran outputs
+## =================================================================================
+
+.AggregOutputs <- function(Outputs) {
+  Table <- list(
+    Outputs = c("PotEvap", "Precip", "Prod", "Pn", "Ps", "AE", "Perc", "PR", "Q9", "Q1", "Rout", "Exch", "AExch1", "AExch2", "AExch", "QR", "QRExp", "Exp", "QD", "Qsim", "Pliq", "Psol", "SnowPack", "ThermalState", "Gratio", "PotMelt", "Melt", "PliqAndMelt", "Temp", "Gthreshold", "Glocalmax", "LayerPrecip", "LayerTempMean", "LayerFracSolidPrecip"),
+    Aggreg  = c("sum", "sum", "mean", "sum", "sum", "sum", "sum", "sum", "sum", "sum", "mean", "sum", "sum", "sum", "sum", "sum", "sum", "mean", "sum", "sum", "sum", "sum", "mean", "mean", "mean", "sum", "sum", "sum", "mean", "mean", "mean", "sum", "mean", "sum")
+  )
+  if (length(Table$Outputs) != length(Table$Aggreg)) {
+    stop("'.AggregOutputs' is out of order")
+  }
+  match.arg(Outputs, choices = Table$Outputs, several.ok = TRUE)
+  res <- sapply(Outputs, function(iOutputs) {
+    iRes <- Table$Aggreg[Table$Outputs == iOutputs]
+    iRes <- ifelse(any(is.na(iRes)), NA, iRes)
+  })
+  return(res)
+}
+
+
+
 ## =================================================================================
 ## function to manage Fortran outputs
 ## =================================================================================
-- 
GitLab