From 9fa981538a0d302d18d81bd89e23c12db1cd5057 Mon Sep 17 00:00:00 2001
From: Hban Mesure <>
Date: Thu, 5 Dec 2019 10:24:15 +0100
Subject: [PATCH] v1.4.1.0 NEW: add TransfoParam_GR5H fun in order to calibrate
 the GR5H model #13

---
 DESCRIPTION           |  2 +-
 NEWS.md               |  2 +-
 R/TransfoParam_GR5H.R | 50 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 52 insertions(+), 2 deletions(-)
 create mode 100644 R/TransfoParam_GR5H.R

diff --git a/DESCRIPTION b/DESCRIPTION
index b356ef8f..345e45d2 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.0.8
+Version: 1.4.1.0
 Date: 2019-12-05
 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 a2377c3f..243be7a8 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -2,7 +2,7 @@
 
 
 
-### 1.4.0.8 Release Notes (2019-12-05)
+### 1.4.1.0 Release Notes (2019-12-05)
 
 
 #### New features
diff --git a/R/TransfoParam_GR5H.R b/R/TransfoParam_GR5H.R
new file mode 100644
index 00000000..e4319320
--- /dev/null
+++ b/R/TransfoParam_GR5H.R
@@ -0,0 +1,50 @@
+TransfoParam_GR4H <- function(ParamIn, Direction) {
+
+  ## number of model parameters
+  NParam <- 5L
+  
+  
+  ## check arguments
+  isVecParamIn <- is.vector(ParamIn)
+  if (isVecParamIn) {
+    ParamIn <- matrix(ParamIn, nrow = 1)
+  }  
+  if (!inherits(ParamIn, "matrix")) {
+    stop("'ParamIn' must be of class 'matrix'")
+  }
+  if (!inherits(Direction, "character") | length(Direction) != 1 | any(!Direction %in% c("RT", "TR"))) {
+    stop("'Direction' must be a character vector of length 1 equal to 'RT' or 'TR'")
+  }
+  if (ncol(ParamIn) != NParam) {
+    stop(sprintf("the GR5H model requires %i parameters", NParam))
+  }
+  
+  
+  ## transformation
+  if(Direction=="TR"){
+    ParamOut     <-  ParamIn;
+    ParamOut[,1] <- exp(1.5*ParamIn[,1]);                ### GR5H X1 (production store capacity)    
+    ParamOut[,2] <- sinh(ParamIn[,2]);                   ### GR5H X2 (groundwater exchange coefficient)      
+    ParamOut[,3] <- exp(ParamIn[,3]);                    ### GR5H X3 (routing store capacity)       
+    ParamOut[,4] <- 480+(480-0.01)*(ParamIn[,4]-10)/20;  ### GR5H X4 (unit hydrograph time constant)
+    ParamOut[,5] <- (ParamIn[,5]+10) / 20;               ### GR5H X5 (groundwater exchange coefficient 2)
+  }
+  if(Direction=="RT"){
+    ParamOut     <-  ParamIn;
+    ParamOut[,1] <- log(ParamIn[,1])/1.5;                ### GR5H X1 (production store capacity)    
+    ParamOut[,2] <- asinh(ParamIn[,2]);                  ### GR5H X2 (groundwater exchange coefficient)      
+    ParamOut[,3] <- log(ParamIn[,3]);                    ### GR5H X3 (routing store capacity)       
+    ParamOut[,4] <- (ParamIn[,4]-480)*20/(480-0.01)+10;  ### GR5H X4 (unit hydrograph time constant)
+    ParamOut[,5] <- ParamIn[,5]*20 - 10;                 ### GR5H X5 (groundwater exchange coefficient 2)
+  }
+
+  
+  ## check output
+  if (isVecParamIn) {
+    ParamOut <- as.vector(ParamOut)
+  }
+  
+  return(ParamOut)
+
+}
+
-- 
GitLab