From 00551ea909521b4af73369192b973f1d8f194617 Mon Sep 17 00:00:00 2001
From: unknown <olivier.delaigue@ANPI1430.antony.irstea.priv>
Date: Wed, 12 Jul 2017 10:53:01 +0200
Subject: [PATCH] v1.0.9.14 bug fixed in plot.OutputsModel for flows time
 series when log_scale=TRUE & BasinArea used #4732

---
 DESCRIPTION           |  4 ++--
 R/plot.OutputsModel.R | 18 ++++++++++++------
 2 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/DESCRIPTION b/DESCRIPTION
index ca2b3a6e..c8d76dc1 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,8 +1,8 @@
 Package: airGR
 Type: Package
 Title: Suite of GR Hydrological Models for Precipitation-Runoff Modelling
-Version: 1.0.9.13
-Date: 2017-07-11
+Version: 1.0.9.14
+Date: 2017-07-12
 Authors@R: c(
   person("Laurent", "Coron", role = c("aut", "trl")),
   person("Charles", "Perrin", role = c("aut", "ths")),
diff --git a/R/plot.OutputsModel.R b/R/plot.OutputsModel.R
index 334614e8..39cbdd70 100644
--- a/R/plot.OutputsModel.R
+++ b/R/plot.OutputsModel.R
@@ -162,9 +162,15 @@ plot.OutputsModel <- function(x, Qobs = NULL, IndPeriod_Plot = NULL, BasinArea =
 
   kPlot <- 0
   
-  ## vector of Q values for the y-axis when it is expressed in 
-  seqDATA1 <- log(c(0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000))
+  ## vector of Q values for the y-axis when it is expressed in
+  Factor <- ifelse(!is.null(BasinArea), Factor_UNIT_M3S, 1)
+  seqDATA0 <- c(0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000)
+  seqDATA1 <- log(seqDATA0)
   seqDATA2 <- exp(seqDATA1)
+  if (!is.null(BasinArea)) {
+    seqDATA1ba <- log(seqDATA0 * Factor_UNIT_M3S)
+    seqDATA2ba <- round(exp(seqDATA1ba), digits = 2)
+  }
 
   ##Precip
   if (BOOLPLOT_Precip) {
@@ -268,7 +274,7 @@ plot.OutputsModel <- function(x, Qobs = NULL, IndPeriod_Plot = NULL, BasinArea =
     DATA2 <- log(DATA2)
 
     DATA3 <- OutputsModel$Qsim
-    DATA2[!SelectQsimNotZero] <- mean(OutputsModel$Qsim, na.rm = TRUE) / 10000
+    DATA3[!SelectQsimNotZero] <- mean(OutputsModel$Qsim, na.rm = TRUE) / 10000
     DATA3 <- log(DATA3)
 
     ylim1 <- range(DATA3[IndPeriod_Plot], na.rm = TRUE);
@@ -282,7 +288,7 @@ plot.OutputsModel <- function(x, Qobs = NULL, IndPeriod_Plot = NULL, BasinArea =
     par(las = 0); mtext(side = 2, paste0("flow ", plotunit), line = line, cex = cex.lab); par(las = 0);
     if (!is.null(BasinArea)) {
       Factor <- Factor_UNIT_M3S;
-      axis(side = 4, at = pretty(ylim1*Factor)/Factor, labels = pretty(ylim1*Factor), cex.axis = cex.axis, ...);
+      axis(side = 4, at = seqDATA1ba, labels = seqDATA2ba, cex.axis = cex.axis, ...)
       par(las = 0); mtext(side = 4, paste0("flow ", "m3/s"), line = line, cex = cex.lab); par(las = 0); }
     if (BOOL_Dates) {
       axis(side = 1, at = Seq1, labels = FALSE, cex.axis = cex.axis, ...);
@@ -463,7 +469,7 @@ plot.OutputsModel <- function(x, Qobs = NULL, IndPeriod_Plot = NULL, BasinArea =
       }
       if (!is.null(BasinArea)) {
         Factor <- Factor_UNIT_M3S;
-        axis(side = 4, at = seqDATA1, labels = round(seqDATA2*Factor), cex.axis = cex.axis, ...)
+        axis(side = 4, at = seqDATA1, labels = round(seqDATA2*Factor, dig = 2), cex.axis = cex.axis, ...)
         par(las = 0); mtext(side = 4, paste0("flow ", "m3/s"), line = line, cex = cex.lab); par(las = 0)
       }
       legend("topleft", txtleg, col = colleg, lty = 1, lwd = lwd, bty = "o", bg = bg, box.col = bg, cex = cex.leg)
@@ -495,7 +501,7 @@ plot.OutputsModel <- function(x, Qobs = NULL, IndPeriod_Plot = NULL, BasinArea =
       par(las = 0); mtext(side = 2, paste0("simulated flow ", plotunit), line = line, cex = cex.lab); par(las = 0);
       if (!is.null(BasinArea)) {
         Factor <- Factor_UNIT_M3S;
-        axis(side = 4, at = seqDATA1, labels = round(seqDATA2*Factor), cex.axis = cex.axis, ...);
+        axis(side = 4, at = seqDATA1, labels = round(seqDATA2*Factor, dig = 2), cex.axis = cex.axis, ...);
         par(las = 0); mtext(side = 4, paste0("flow ", "m3/s"), line = line, cex = cex.lab); par(las = 0); }
       legend("bottomright", "log scale", lty = 1, col = NA, bty = "o", bg = bg, box.col = bg, cex = cex.leg)
     } else {
-- 
GitLab