From 23738c96b5fa0b20c655d0294a80bfc833c3a400 Mon Sep 17 00:00:00 2001
From: Delaigue Olivier <olivier.delaigue@irstea.priv>
Date: Mon, 25 Mar 2019 18:34:23 +0100
Subject: [PATCH] v1.2.11.12 BUG: add setting parameter values for Gthreshold
 and Glocalmax when hysteresis is used in RunModel_CemaNeige* funs #5252

---
 DESCRIPTION                | 2 +-
 NEWS.rmd                   | 2 +-
 R/RunModel_CemaNeige.R     | 7 ++++++-
 R/RunModel_CemaNeigeGR4J.R | 6 +++++-
 R/RunModel_CemaNeigeGR5J.R | 6 +++++-
 R/RunModel_CemaNeigeGR6J.R | 6 +++++-
 6 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/DESCRIPTION b/DESCRIPTION
index cd1e15e4..9fce7cea 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.11.11
+Version: 1.2.11.12
 Date: 2019-03-25
 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 b1350506..0692e5a1 100644
--- a/NEWS.rmd
+++ b/NEWS.rmd
@@ -13,7 +13,7 @@ output:
 
 
 
-### 1.2.11.11 Release Notes (2019-03-25) 
+### 1.2.11.12 Release Notes (2019-03-25) 
 
 
 
diff --git a/R/RunModel_CemaNeige.R b/R/RunModel_CemaNeige.R
index b8f91324..d58e93df 100644
--- a/R/RunModel_CemaNeige.R
+++ b/R/RunModel_CemaNeige.R
@@ -65,7 +65,12 @@ RunModel_CemaNeige <- function(InputsModel, RunOptions, Param) {
   
   ## Call_DLL_CemaNeige_________________________
   for (iLayer in 1:NLayers) {
-    StateStartCemaNeige <- RunOptions$IniStates[(7 + 20 + 40) + c(iLayer, iLayer + NLayers)]
+    
+    if (!IsHyst) {
+      StateStartCemaNeige <- RunOptions$IniStates[(7 + 20 + 40) + c(iLayer, iLayer+NLayers)]
+    } else {
+      StateStartCemaNeige <- RunOptions$IniStates[(7 + 20 + 40) + c(iLayer, iLayer+NLayers, iLayer+2*NLayers, iLayer+3*NLayers)]
+    }
     RESULTS <- .Fortran("frun_CemaNeige", PACKAGE = "airGR",
                         ## inputs
                         LInputs = as.integer(length(IndPeriod1)),                                       ### length of input and output series
diff --git a/R/RunModel_CemaNeigeGR4J.R b/R/RunModel_CemaNeigeGR4J.R
index d656a436..6c79f9bc 100644
--- a/R/RunModel_CemaNeigeGR4J.R
+++ b/R/RunModel_CemaNeigeGR4J.R
@@ -58,7 +58,11 @@ RunModel_CemaNeigeGR4J <- function(InputsModel,RunOptions,Param){
 
     ##Call_DLL_CemaNeige_________________________
       for(iLayer in 1:NLayers){
-        StateStartCemaNeige <- RunOptions$IniStates[(7+20+40) + c(iLayer, iLayer+NLayers)]
+        if (!IsHyst) {
+          StateStartCemaNeige <- RunOptions$IniStates[(7 + 20 + 40) + c(iLayer, iLayer+NLayers)]
+        } else {
+          StateStartCemaNeige <- RunOptions$IniStates[(7 + 20 + 40) + c(iLayer, iLayer+NLayers, iLayer+2*NLayers, iLayer+3*NLayers)]
+        }
         RESULTS <- .Fortran("frun_CemaNeige",PACKAGE="airGR",
                         ##inputs
                             LInputs=LInputSeries,                                                         ### length of input and output series
diff --git a/R/RunModel_CemaNeigeGR5J.R b/R/RunModel_CemaNeigeGR5J.R
index 70b254c1..9ae4c341 100644
--- a/R/RunModel_CemaNeigeGR5J.R
+++ b/R/RunModel_CemaNeigeGR5J.R
@@ -56,7 +56,11 @@ RunModel_CemaNeigeGR5J <- function(InputsModel,RunOptions,Param){
       
     ##Call_DLL_CemaNeige_________________________
       for(iLayer in 1:NLayers){
-        StateStartCemaNeige <- RunOptions$IniStates[(7+20+40) + c(iLayer, iLayer+NLayers)]
+        if (!IsHyst) {
+          StateStartCemaNeige <- RunOptions$IniStates[(7 + 20 + 40) + c(iLayer, iLayer+NLayers)]
+        } else {
+          StateStartCemaNeige <- RunOptions$IniStates[(7 + 20 + 40) + c(iLayer, iLayer+NLayers, iLayer+2*NLayers, iLayer+3*NLayers)]
+        }
         RESULTS <- .Fortran("frun_CemaNeige",PACKAGE="airGR",
                         ##inputs
                             LInputs=LInputSeries,                                                         ### length of input and output series
diff --git a/R/RunModel_CemaNeigeGR6J.R b/R/RunModel_CemaNeigeGR6J.R
index 1e1fce32..db28275a 100644
--- a/R/RunModel_CemaNeigeGR6J.R
+++ b/R/RunModel_CemaNeigeGR6J.R
@@ -60,7 +60,11 @@ RunModel_CemaNeigeGR6J <- function(InputsModel,RunOptions,Param){
       
     ##Call_DLL_CemaNeige_________________________
       for(iLayer in 1:NLayers){
-        StateStartCemaNeige <- RunOptions$IniStates[(7+20+40) + c(iLayer, iLayer+NLayers)]
+        if (!IsHyst) {
+          StateStartCemaNeige <- RunOptions$IniStates[(7 + 20 + 40) + c(iLayer, iLayer+NLayers)]
+        } else {
+          StateStartCemaNeige <- RunOptions$IniStates[(7 + 20 + 40) + c(iLayer, iLayer+NLayers, iLayer+2*NLayers, iLayer+3*NLayers)]
+        }
         RESULTS <- .Fortran("frun_CemaNeige",PACKAGE="airGR",
                         ##inputs
                             LInputs=LInputSeries,                                                          ### length of input and output series
-- 
GitLab