From d70aa7094f8f109d7bbfec6d2b26a2d65d28292d Mon Sep 17 00:00:00 2001
From: Delaigue Olivier <olivier.delaigue@irstea.priv>
Date: Tue, 12 Mar 2019 15:58:31 +0100
Subject: [PATCH] v1.2.8.11 CLEAN: input checks added to PEdaily_Oudin

---
 DESCRIPTION       |  2 +-
 NEWS.rmd          |  4 +++-
 R/PEdaily_Oudin.R | 27 +++++++++++++++++++++------
 3 files changed, 25 insertions(+), 8 deletions(-)

diff --git a/DESCRIPTION b/DESCRIPTION
index 569dece9..71dce2de 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.2.8.10
+Version: 1.2.8.11
 Date: 2019-03-12
 Authors@R: c(
   person("Laurent", "Coron", role = c("aut", "trl"), comment = c(ORCID = "0000-0002-1503-6204")),
diff --git a/NEWS.rmd b/NEWS.rmd
index 1a6f3cc6..72926193 100644
--- a/NEWS.rmd
+++ b/NEWS.rmd
@@ -13,7 +13,7 @@ output:
 
 
 
-### 1.2.8.10 Release Notes (2019-03-12) 
+### 1.2.8.11 Release Notes (2019-03-12) 
 
 
 
@@ -73,6 +73,8 @@ output:
 
 - <code>Calibration()</code> function now returns an error message if <code>FUN_CALIB</code> is not a function
 
+- Inputs of <code>PEdaily_Oudin()</code> are now checked
+
 - <code>PEdaily_Oudin()</code> example corrected (the Julian day was one day too early)
 
 ____________________________________________________________________________________
diff --git a/R/PEdaily_Oudin.R b/R/PEdaily_Oudin.R
index 4105fe9a..38f6d258 100644
--- a/R/PEdaily_Oudin.R
+++ b/R/PEdaily_Oudin.R
@@ -1,18 +1,29 @@
 PEdaily_Oudin <- function(JD, Temp, LatRad, Lat, LatUnit = c("rad", "deg")) {
   
+  
+  ## ---------- check arguments
+  
   if (!missing(LatRad)) {
     warning("Deprecated \"LatRad\" argument. Please, use \"Lat\" instead.")
     if (missing(Lat)) {
       Lat <- LatRad
     }
   }
-  
-  if (!any(LatUnit %in%c("rad", "deg"))) {
-    stop("\"LatUnit\" must be \"rad\" or \"deg\".")
+  if (!inherits(JD, "numeric")) {
+    stop("'JD' must be of class 'numeric'")
+  }
+  if (!inherits(Temp, "numeric")) {
+    stop("'Temp' must be of class 'numeric'")
+  }
+  if (length(JD) != length(Temp)) {
+    stop("'Temp' and 'LatUnit' must have the same length")
+  }
+  if (!any(LatUnit %in% c("rad", "deg"))) {
+    stop("'LatUnit' must be \"rad\" or \"deg\"")
+  }
+  if (!inherits(Lat, "numeric") | length(Lat) != 1) {
+    stop("'Lat' must be a 'numeric' of length one")
   }
-  
-  PE_Oudin_D <- rep(NA, length(Temp))
-  
   if (LatUnit[1L] == "rad") {
     FI <- Lat
   }
@@ -20,6 +31,10 @@ PEdaily_Oudin <- function(JD, Temp, LatRad, Lat, LatUnit = c("rad", "deg")) {
     FI <- Lat / (180 / pi)
   }
   
+  
+  ## ---------- Oudin's formula
+  
+  PE_Oudin_D <- rep(NA, length(Temp))
   COSFI <- cos(FI)
   AFI <- abs(FI / 42) 
   
-- 
GitLab