From 47f142ec64fa295fc9a11390dcd5dcea654db4c6 Mon Sep 17 00:00:00 2001
From: Delaigue Olivier <olivier.delaigue@irstea.fr>
Date: Mon, 25 Jan 2021 14:41:46 +0100
Subject: [PATCH] v1.6.9.29 refactor: use [.InputsModel method in Imax to index
 by IndPeriod_Run Refs #92

---
 DESCRIPTION | 2 +-
 NEWS.md     | 2 +-
 R/Imax.R    | 8 +-------
 3 files changed, 3 insertions(+), 9 deletions(-)

diff --git a/DESCRIPTION b/DESCRIPTION
index 3facf084..487c9ef8 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.6.9.28
+Version: 1.6.9.29
 Date: 2021-01-25
 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 2b90594b..b4cd125e 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -6,7 +6,7 @@
 
 #### Major user-visible changes
 
-- `Imax()` now returns an error message when `IndPeriod_Run` doesn't select 24 hours by day). ([#92](https://gitlab.irstea.fr/HYCAR-Hydro/airgr/-/issues/92))
+- `Imax()` now returns an error message when `IndPeriod_Run` doesn't select 24 hours by day, instead of `numeric(0)`. ([#92](https://gitlab.irstea.fr/HYCAR-Hydro/airgr/-/issues/92))
 
 ____________________________________________________________________________________
 
diff --git a/R/Imax.R b/R/Imax.R
index 59abad65..b783ce65 100644
--- a/R/Imax.R
+++ b/R/Imax.R
@@ -34,18 +34,13 @@ Imax <- function(InputsModel,
   ## ---------- hourly inputs aggregation
 
   ## aggregate data at the daily time step
-  TabSeries <- data.frame(DatesR = InputsModel$DatesR[IndPeriod_Run],
-                          Precip = InputsModel$Precip[IndPeriod_Run],
-                          PotEvap = InputsModel$PotEvap[IndPeriod_Run])
-  daily_data <- SeriesAggreg(TabSeries, Format = "%Y%m%d",
-                             ConvertFun = c("sum", "sum"))
+  daily_data <- SeriesAggreg(InputsModel[IndPeriod_Run], Format = "%Y%m%d")
 
 
   ## ---------- calculate interception
 
   ## calculate total interception of daily GR models on the period
   cum_daily <- sum(pmin(daily_data$Precip, daily_data$PotEvap))
-
   if (anyNA(cum_daily)) {
     stop("'IndPeriod_Run' must be set to select 24 hours by day")
   }
@@ -53,7 +48,6 @@ Imax <- function(InputsModel,
   ## calculate total interception of the GR5H interception store on the period
   ## and compute difference with daily values
   differences <- array(NA, c(length(TestedValues)))
-  print(differences)
   for (Imax in TestedValues) {
     C0 <- 0
     cum_hourly <- 0
-- 
GitLab