From f2084d3f36534a2c6780ce0771e4e6de31bae208 Mon Sep 17 00:00:00 2001
From: Delaigue Olivier <olivier.delaigue@irstea.fr>
Date: Thu, 25 Mar 2021 14:05:30 +0100
Subject: [PATCH] speed(NA): manage NA in input and output of Fortran codes in
 RunModel functions - remove the use of the round() function - replace
 -999.999 by -99e9 - replace == by <= -99e8 Refs #113

---
 R/PE_Oudin.R               |  2 +-
 R/RunModel_CemaNeige.R     |  8 ++---
 R/RunModel_CemaNeigeGR4H.R | 70 +++++++++++++++++++-------------------
 R/RunModel_CemaNeigeGR4J.R | 16 ++++-----
 R/RunModel_CemaNeigeGR5H.R | 16 ++++-----
 R/RunModel_CemaNeigeGR5J.R | 16 ++++-----
 R/RunModel_CemaNeigeGR6J.R | 16 ++++-----
 R/RunModel_GR1A.R          |  8 ++---
 R/RunModel_GR2M.R          |  8 ++---
 R/RunModel_GR4H.R          |  8 ++---
 R/RunModel_GR4J.R          |  8 ++---
 R/RunModel_GR5H.R          |  8 ++---
 R/RunModel_GR5J.R          |  8 ++---
 R/RunModel_GR6J.R          |  8 ++---
 14 files changed, 100 insertions(+), 100 deletions(-)

diff --git a/R/PE_Oudin.R b/R/PE_Oudin.R
index 173c9e4f..0f6c8352 100644
--- a/R/PE_Oudin.R
+++ b/R/PE_Oudin.R
@@ -75,7 +75,7 @@ PE_Oudin <- function(JD, Temp,
                         InputsTT = as.double(Temp),
                         InputsJJ = as.double(JD),
                         ##outputs
-                        PE_Oudin_D = rep(as.double(-999.999), LInputs)
+                        PE_Oudin_D = rep(as.double(-99e9), LInputs)
     )
     PE_Oudin_D = RESULTS$PE_Oudin_D
 
diff --git a/R/RunModel_CemaNeige.R b/R/RunModel_CemaNeige.R
index 2cbac815..8d2fb384 100644
--- a/R/RunModel_CemaNeige.R
+++ b/R/RunModel_CemaNeige.R
@@ -94,13 +94,13 @@ RunModel_CemaNeige <- function(InputsModel, RunOptions, Param) {
                         NOutputs = as.integer(length(IndOutputsCemaNeige)),                             ### number of output series
                         IndOutputs = IndOutputsCemaNeige,                                               ### indices of output series
                         ## outputs
-                        Outputs = matrix(-999.999,                                                      ### output series [mm, mm/time step or degC]
+                        Outputs = matrix(-99e9,                                                      ### output series [mm, mm/time step or degC]
                                          nrow = length(IndPeriod1),
                                          ncol = length(IndOutputsCemaNeige)),
-                        StateEnd = rep(-999.999, NStates)                                               ### state variables at the end of the model run
+                        StateEnd = rep(-99e9, NStates)                                               ### state variables at the end of the model run
     )
-    RESULTS$Outputs[ round(RESULTS$Outputs , 3) == -999.999] <- NA
-    RESULTS$StateEnd[round(RESULTS$StateEnd, 3) == -999.999] <- NA
+    RESULTS$Outputs[RESULTS$Outputs   <= -99e8] <- NA
+    RESULTS$StateEnd[RESULTS$StateEnd <= -99e8] <- NA
     
     
     
diff --git a/R/RunModel_CemaNeigeGR4H.R b/R/RunModel_CemaNeigeGR4H.R
index 4e73176c..735112c2 100644
--- a/R/RunModel_CemaNeigeGR4H.R
+++ b/R/RunModel_CemaNeigeGR4H.R
@@ -1,14 +1,14 @@
 RunModel_CemaNeigeGR4H <- function(InputsModel, RunOptions, Param) {
-  
-  
+
+
   ## Initialization of variables
   IsHyst <- inherits(RunOptions, "hysteresis")
   NParam <- ifelse(test = IsHyst, yes = 8L, no = 6L)
   NParamCN <- NParam - 4L
   NStates <- 4L
   FortranOutputs <- .FortranOutputs(GR = "GR4H", isCN = TRUE)
-  
-  
+
+
   ## Arguments check
   if (!inherits(InputsModel, "InputsModel")) {
     stop("'InputsModel' must be of class 'InputsModel'")
@@ -38,8 +38,8 @@ RunModel_CemaNeigeGR4H <- function(InputsModel, RunOptions, Param) {
     stop(paste("'Param' must be a vector of length", NParam, "and contain no NA"))
   }
   Param <- as.double(Param)
-  
-  
+
+
   Param_X1X3_threshold <- 1e-2
   Param_X4_threshold   <- 0.5
   if (Param[1L] < Param_X1X3_threshold) {
@@ -53,8 +53,8 @@ RunModel_CemaNeigeGR4H <- function(InputsModel, RunOptions, Param) {
   if (Param[4L] < Param_X4_threshold) {
     warning(sprintf("Param[4] (X4: unit hydrograph time constant [h]) < %.2f\n X4 set to %.2f", Param_X4_threshold, Param_X4_threshold))
     Param[4L] <- Param_X4_threshold
-  }      
-  
+  }
+
   ## Input data preparation
   if (identical(RunOptions$IndPeriod_WarmUp, 0L)) {
     RunOptions$IndPeriod_WarmUp <- NULL
@@ -67,12 +67,12 @@ RunModel_CemaNeigeGR4H <- function(InputsModel, RunOptions, Param) {
   ParamMod       <- Param[1:NParamMod]
   NLayers        <- length(InputsModel$LayerPrecip)
   NStatesMod     <- as.integer(length(RunOptions$IniStates) - NStates * NLayers)
-   
+
   ## Output data preparation
   ExportDatesR   <- "DatesR"   %in% RunOptions$Outputs_Sim
   ExportStateEnd <- "StateEnd" %in% RunOptions$Outputs_Sim
-  
-  
+
+
   ## CemaNeige________________________________________________________________________________
   if (inherits(RunOptions, "CemaNeige")) {
     if ("all" %in% RunOptions$Outputs_Sim) {
@@ -83,11 +83,11 @@ RunModel_CemaNeigeGR4H <- function(InputsModel, RunOptions, Param) {
     CemaNeigeLayers <- list()
     CemaNeigeStateEnd <- NULL
     NameCemaNeigeLayers <- "CemaNeigeLayers"
-    
-    
+
+
     ## Call CemaNeige Fortran_________________________
     for (iLayer in 1:NLayers) {
-      
+
       if (!IsHyst) {
         StateStartCemaNeige <- RunOptions$IniStates[(7 + 20*24 + 40*24) + c(iLayer, iLayer+NLayers)]
       } else {
@@ -107,13 +107,13 @@ RunModel_CemaNeigeGR4H <- function(InputsModel, RunOptions, Param) {
                           IsHyst = as.integer(IsHyst),                                                    ### use of hysteresis
                           NOutputs = as.integer(length(IndOutputsCemaNeige)),                             ### number of output series
                           IndOutputs = IndOutputsCemaNeige,                                               ### indices of output series
-                          ## outputs                                                               
-                          Outputs = matrix(as.double(-999.999), nrow = LInputSeries, ncol = length(IndOutputsCemaNeige)), ### output series [mm, mm/h or degC]
-                          StateEnd = rep(as.double(-999.999), as.integer(NStates))                                        ### state variables at the end of the model run
+                          ## outputs
+                          Outputs = matrix(as.double(-99e9), nrow = LInputSeries, ncol = length(IndOutputsCemaNeige)), ### output series [mm, mm/h or degC]
+                          StateEnd = rep(as.double(-99e9), as.integer(NStates))                                        ### state variables at the end of the model run
       )
-      RESULTS$Outputs[ round(RESULTS$Outputs , 3) == -999.999] <- NA
-      RESULTS$StateEnd[round(RESULTS$StateEnd, 3) == -999.999] <- NA
-      
+      RESULTS$Outputs[RESULTS$Outputs   <= -99e8] <- NA
+      RESULTS$StateEnd[RESULTS$StateEnd <= -99e8] <- NA
+
       ## Data storage
       CemaNeigeLayers[[iLayer]] <- lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2, i])
       names(CemaNeigeLayers[[iLayer]]) <- FortranOutputs$CN[IndOutputsCemaNeige]
@@ -137,22 +137,22 @@ RunModel_CemaNeigeGR4H <- function(InputsModel, RunOptions, Param) {
     NameCemaNeigeLayers <- NULL
     CatchMeltAndPliq <- InputsModel$Precip[IndPeriod1]
   }
-  
-  
-  
+
+
+
   ## GR model
   if ("all" %in% RunOptions$Outputs_Sim) {
     IndOutputsMod <- as.integer(1:length(FortranOutputs$GR))
   } else {
     IndOutputsMod <- which(FortranOutputs$GR %in% RunOptions$Outputs_Sim)
   }
-  
+
   ## Use of IniResLevels
   if (!is.null(RunOptions$IniResLevels)) {
     RunOptions$IniStates[1] <- RunOptions$IniResLevels[1] * ParamMod[1] ### production store level (mm)
     RunOptions$IniStates[2] <- RunOptions$IniResLevels[2] * ParamMod[3] ### routing store level (mm)
   }
-  
+
   ## Call GR model Fortan
   RESULTS <- .Fortran("frun_gr4h", PACKAGE = "airGR",
                       ## inputs
@@ -165,12 +165,12 @@ RunModel_CemaNeigeGR4H <- function(InputsModel, RunOptions, Param) {
                       StateStart = RunOptions$IniStates[1:NStatesMod], ### state variables used when the model run starts
                       NOutputs = as.integer(length(IndOutputsMod)),    ### number of output series
                       IndOutputs = IndOutputsMod,                      ### indices of output series
-                      ## outputs                                        
-                      Outputs = matrix(as.double(-999.999), nrow = LInputSeries, ncol = length(IndOutputsMod)), ### output series [mm or mm/h]
-                      StateEnd = rep(as.double(-999.999), NStatesMod)                                           ### state variables at the end of the model run
+                      ## outputs
+                      Outputs = matrix(as.double(-99e9), nrow = LInputSeries, ncol = length(IndOutputsMod)), ### output series [mm or mm/h]
+                      StateEnd = rep(as.double(-99e9), NStatesMod)                                           ### state variables at the end of the model run
   )
-  RESULTS$Outputs[ round(RESULTS$Outputs , 3) == -999.999] <- NA
-  RESULTS$StateEnd[round(RESULTS$StateEnd, 3) == -999.999] <- NA
+  RESULTS$Outputs[RESULTS$Outputs   <= -99e8] <- NA
+  RESULTS$StateEnd[RESULTS$StateEnd <= -99e8] <- NA
   if (ExportStateEnd) {
     RESULTS$StateEnd[-3L] <- ifelse(RESULTS$StateEnd[-3L] < 0, 0, RESULTS$StateEnd[-3L]) ### remove negative values except for the ExpStore location
     idNStates <- seq_len(NStates*NLayers) %% NStates
@@ -180,15 +180,15 @@ RunModel_CemaNeigeGR4H <- function(InputsModel, RunOptions, Param) {
                                         UH2 = RESULTS$StateEnd[(1:(40*24)) + (7+20*24)],
                                         GCemaNeigeLayers       = CemaNeigeStateEnd[seq_len(NStates*NLayers)[idNStates == 1]],
                                         eTGCemaNeigeLayers     = CemaNeigeStateEnd[seq_len(NStates*NLayers)[idNStates == 2]],
-                                        GthrCemaNeigeLayers    = CemaNeigeStateEnd[seq_len(NStates*NLayers)[idNStates == 3]], 
+                                        GthrCemaNeigeLayers    = CemaNeigeStateEnd[seq_len(NStates*NLayers)[idNStates == 3]],
                                         GlocmaxCemaNeigeLayers = CemaNeigeStateEnd[seq_len(NStates*NLayers)[idNStates == 0]],
                                         verbose = FALSE)
   }
-  
+
   if (inherits(RunOptions, "CemaNeige") & "Precip" %in% RunOptions$Outputs_Sim) {
     RESULTS$Outputs[, which(FortranOutputs$GR[IndOutputsMod] == "Precip")] <- InputsModel$Precip[IndPeriod1]
   }
-  
+
   ## Output data preparation
   ## OutputsModel only
   if (!ExportDatesR & !ExportStateEnd) {
@@ -218,7 +218,7 @@ RunModel_CemaNeigeGR4H <- function(InputsModel, RunOptions, Param) {
                       list(RESULTS$StateEnd))
     names(OutputsModel) <- c("DatesR", FortranOutputs$GR[IndOutputsMod], NameCemaNeigeLayers, "StateEnd")
   }
-  
+
   ## End
   rm(RESULTS)
   class(OutputsModel) <- c("OutputsModel", "hourly", "GR", "CemaNeige")
@@ -226,5 +226,5 @@ RunModel_CemaNeigeGR4H <- function(InputsModel, RunOptions, Param) {
     class(OutputsModel) <- c(class(OutputsModel), "hysteresis")
   }
   return(OutputsModel)
-  
+
 }
diff --git a/R/RunModel_CemaNeigeGR4J.R b/R/RunModel_CemaNeigeGR4J.R
index 974e20d7..d7105bea 100644
--- a/R/RunModel_CemaNeigeGR4J.R
+++ b/R/RunModel_CemaNeigeGR4J.R
@@ -104,11 +104,11 @@ RunModel_CemaNeigeGR4J <- function(InputsModel, RunOptions, Param) {
                           NOutputs = as.integer(length(IndOutputsCemaNeige)),                             ### number of output series
                           IndOutputs = IndOutputsCemaNeige,                                               ### indices of output series
                           ## outputs                                                               
-                          Outputs = matrix(as.double(-999.999), nrow = LInputSeries, ncol = length(IndOutputsCemaNeige)), ### output series [mm, mm/d or degC]
-                          StateEnd = rep(as.double(-999.999), as.integer(NStates))                                        ### state variables at the end of the model run
+                          Outputs = matrix(as.double(-99e9), nrow = LInputSeries, ncol = length(IndOutputsCemaNeige)), ### output series [mm, mm/d or degC]
+                          StateEnd = rep(as.double(-99e9), as.integer(NStates))                                        ### state variables at the end of the model run
       )
-      RESULTS$Outputs[ round(RESULTS$Outputs , 3) == -999.999] <- NA
-      RESULTS$StateEnd[round(RESULTS$StateEnd, 3) == -999.999] <- NA
+      RESULTS$Outputs[RESULTS$Outputs   <= -99e8] <- NA
+      RESULTS$StateEnd[RESULTS$StateEnd <= -99e8] <- NA
       
       ## Data storage
       CemaNeigeLayers[[iLayer]] <- lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2, i])
@@ -162,11 +162,11 @@ RunModel_CemaNeigeGR4J <- function(InputsModel, RunOptions, Param) {
                       NOutputs = as.integer(length(IndOutputsMod)),    ### number of output series
                       IndOutputs = IndOutputsMod,                      ### indices of output series
                       ## outputs                                        
-                      Outputs = matrix(as.double(-999.999), nrow = LInputSeries, ncol = length(IndOutputsMod)), ### output series [mm or mm/d]
-                      StateEnd = rep(as.double(-999.999), NStatesMod)                                           ### state variables at the end of the model run
+                      Outputs = matrix(as.double(-99e9), nrow = LInputSeries, ncol = length(IndOutputsMod)), ### output series [mm or mm/d]
+                      StateEnd = rep(as.double(-99e9), NStatesMod)                                           ### state variables at the end of the model run
   )
-  RESULTS$Outputs[ round(RESULTS$Outputs , 3) == -999.999] <- NA
-  RESULTS$StateEnd[round(RESULTS$StateEnd, 3) == -999.999] <- NA
+  RESULTS$Outputs[RESULTS$Outputs   <= -99e8] <- NA
+  RESULTS$StateEnd[RESULTS$StateEnd <= -99e8] <- NA
   if (ExportStateEnd) {
     RESULTS$StateEnd[-3L] <- ifelse(RESULTS$StateEnd[-3L] < 0, 0, RESULTS$StateEnd[-3L]) ### remove negative values except for the ExpStore location
     idNStates <- seq_len(NStates*NLayers) %% NStates
diff --git a/R/RunModel_CemaNeigeGR5H.R b/R/RunModel_CemaNeigeGR5H.R
index 8f1f70cc..dc259454 100644
--- a/R/RunModel_CemaNeigeGR5H.R
+++ b/R/RunModel_CemaNeigeGR5H.R
@@ -114,11 +114,11 @@ RunModel_CemaNeigeGR5H <- function(InputsModel, RunOptions, Param) {
                           NOutputs = as.integer(length(IndOutputsCemaNeige)),                             ### number of output series
                           IndOutputs = IndOutputsCemaNeige,                                               ### indices of output series
                           ## outputs                                                               
-                          Outputs = matrix(as.double(-999.999), nrow = LInputSeries, ncol = length(IndOutputsCemaNeige)), ### output series [mm, mm/h or degC]
-                          StateEnd = rep(as.double(-999.999), as.integer(NStates))                                        ### state variables at the end of the model run
+                          Outputs = matrix(as.double(-99e9), nrow = LInputSeries, ncol = length(IndOutputsCemaNeige)), ### output series [mm, mm/h or degC]
+                          StateEnd = rep(as.double(-99e9), as.integer(NStates))                                        ### state variables at the end of the model run
       )
-      RESULTS$Outputs[ round(RESULTS$Outputs , 3) == -999.999] <- NA
-      RESULTS$StateEnd[round(RESULTS$StateEnd, 3) == -999.999] <- NA
+      RESULTS$Outputs[RESULTS$Outputs   <= -99e8] <- NA
+      RESULTS$StateEnd[RESULTS$StateEnd <= -99e8] <- NA
       
       ## Data storage
       CemaNeigeLayers[[iLayer]] <- lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2, i])
@@ -176,11 +176,11 @@ RunModel_CemaNeigeGR5H <- function(InputsModel, RunOptions, Param) {
                       NOutputs = as.integer(length(IndOutputsMod)),    ### number of output series
                       IndOutputs = IndOutputsMod,                      ### indices of output series
                       ## outputs
-                      Outputs = matrix(as.double(-999.999), nrow = LInputSeries, ncol = length(IndOutputsMod)), ### output series [mm or mm/h]
-                      StateEnd = rep(as.double(-999.999), NStatesMod)                                           ### state variables at the end of the model run
+                      Outputs = matrix(as.double(-99e9), nrow = LInputSeries, ncol = length(IndOutputsMod)), ### output series [mm or mm/h]
+                      StateEnd = rep(as.double(-99e9), NStatesMod)                                           ### state variables at the end of the model run
   )
-  RESULTS$Outputs[ round(RESULTS$Outputs , 3) == -999.999] <- NA
-  RESULTS$StateEnd[round(RESULTS$StateEnd, 3) == -999.999] <- NA
+  RESULTS$Outputs[RESULTS$Outputs   <= -99e8] <- NA
+  RESULTS$StateEnd[RESULTS$StateEnd <= -99e8] <- NA
   if (ExportStateEnd) {
     RESULTS$StateEnd[-3L] <- ifelse(RESULTS$StateEnd[-3L] < 0, 0, RESULTS$StateEnd[-3L]) ### remove negative values except for the ExpStore location
     idNStates <- seq_len(NStates*NLayers) %% NStates
diff --git a/R/RunModel_CemaNeigeGR5J.R b/R/RunModel_CemaNeigeGR5J.R
index e09d22d1..b4384d37 100644
--- a/R/RunModel_CemaNeigeGR5J.R
+++ b/R/RunModel_CemaNeigeGR5J.R
@@ -105,11 +105,11 @@ RunModel_CemaNeigeGR5J <- function(InputsModel, RunOptions, Param) {
                           NOutputs = as.integer(length(IndOutputsCemaNeige)),                             ### number of output series
                           IndOutputs = IndOutputsCemaNeige,                                               ### indices of output series
                           ## outputs                                                               
-                          Outputs =  matrix(as.double(-999.999), nrow = LInputSeries, ncol = length(IndOutputsCemaNeige)), ### output series [mm, mm/d or degC]
-                          StateEnd = rep(as.double(-999.999), as.integer(NStates))                                         ### state variables at the end of the model run
+                          Outputs =  matrix(as.double(-99e9), nrow = LInputSeries, ncol = length(IndOutputsCemaNeige)), ### output series [mm, mm/d or degC]
+                          StateEnd = rep(as.double(-99e9), as.integer(NStates))                                         ### state variables at the end of the model run
       )
-      RESULTS$Outputs[ round(RESULTS$Outputs , 3) == -999.999] <- NA
-      RESULTS$StateEnd[round(RESULTS$StateEnd, 3) == -999.999] <- NA
+      RESULTS$Outputs[RESULTS$Outputs   <= -99e8] <- NA
+      RESULTS$StateEnd[RESULTS$StateEnd <= -99e8] <- NA
       
       ## Data storage
       CemaNeigeLayers[[iLayer]] <- lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2, i])
@@ -163,11 +163,11 @@ RunModel_CemaNeigeGR5J <- function(InputsModel, RunOptions, Param) {
                       NOutputs = as.integer(length(IndOutputsMod)),    ### number of output series
                       IndOutputs = IndOutputsMod,                      ### indices of output series
                       ## outputs                                        
-                      Outputs = matrix(as.double(-999.999), nrow = LInputSeries, ncol = length(IndOutputsMod)), ### output series [mm or mm/d]
-                      StateEnd = rep(as.double(-999.999), NStatesMod)                                           ### state variables at the end of the model run
+                      Outputs = matrix(as.double(-99e9), nrow = LInputSeries, ncol = length(IndOutputsMod)), ### output series [mm or mm/d]
+                      StateEnd = rep(as.double(-99e9), NStatesMod)                                           ### state variables at the end of the model run
   )
-  RESULTS$Outputs[ round(RESULTS$Outputs , 3) == -999.999] <- NA
-  RESULTS$StateEnd[round(RESULTS$StateEnd, 3) == -999.999] <- NA
+  RESULTS$Outputs[RESULTS$Outputs   <= -99e8] <- NA
+  RESULTS$StateEnd[RESULTS$StateEnd <= -99e8] <- NA
   if (ExportStateEnd) {
     RESULTS$StateEnd[-3L] <- ifelse(RESULTS$StateEnd[-3L] < 0, 0, RESULTS$StateEnd[-3L]) ### remove negative values except for the ExpStore location
     idNStates <- seq_len(NStates*NLayers) %% NStates
diff --git a/R/RunModel_CemaNeigeGR6J.R b/R/RunModel_CemaNeigeGR6J.R
index d8421231..278bb6a2 100644
--- a/R/RunModel_CemaNeigeGR6J.R
+++ b/R/RunModel_CemaNeigeGR6J.R
@@ -109,11 +109,11 @@ RunModel_CemaNeigeGR6J <- function(InputsModel, RunOptions, Param) {
                           NOutputs = as.integer(length(IndOutputsCemaNeige)),                             ### number of output series
                           IndOutputs = IndOutputsCemaNeige,                                               ### indices of output series
                           ## outputs                                                               
-                          Outputs = matrix(as.double(-999.999), nrow = LInputSeries,ncol = length(IndOutputsCemaNeige)), ### output series [mm, mm/d or degC]
-                          StateEnd = rep(as.double(-999.999), as.integer(NStates))                                       ### state variables at the end of the model run
+                          Outputs = matrix(as.double(-99e9), nrow = LInputSeries,ncol = length(IndOutputsCemaNeige)), ### output series [mm, mm/d or degC]
+                          StateEnd = rep(as.double(-99e9), as.integer(NStates))                                       ### state variables at the end of the model run
       )
-      RESULTS$Outputs[ round(RESULTS$Outputs , 3) == -999.999] <- NA
-      RESULTS$StateEnd[round(RESULTS$StateEnd, 3) == -999.999] <- NA
+      RESULTS$Outputs[RESULTS$Outputs   <= -99e8] <- NA
+      RESULTS$StateEnd[RESULTS$StateEnd <= -99e8] <- NA
       
       ## Data storage
       CemaNeigeLayers[[iLayer]] <- lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2, i])
@@ -168,11 +168,11 @@ RunModel_CemaNeigeGR6J <- function(InputsModel, RunOptions, Param) {
                       NOutputs = as.integer(length(IndOutputsMod)),    ### number of output series
                       IndOutputs = IndOutputsMod,                      ### indices of output series
                       ## outputs                                        
-                      Outputs = matrix(as.double(-999.999), nrow = LInputSeries,ncol = length(IndOutputsMod)), ### output series [mm or mm/d]
-                      StateEnd = rep(as.double(-999.999), NStatesMod)                                          ### state variables at the end of the model run
+                      Outputs = matrix(as.double(-99e9), nrow = LInputSeries,ncol = length(IndOutputsMod)), ### output series [mm or mm/d]
+                      StateEnd = rep(as.double(-99e9), NStatesMod)                                          ### state variables at the end of the model run
   )
-  RESULTS$Outputs[ round(RESULTS$Outputs , 3) == -999.999] <- NA
-  RESULTS$StateEnd[round(RESULTS$StateEnd, 3) == -999.999] <- NA
+  RESULTS$Outputs[RESULTS$Outputs   <= -99e8] <- NA
+  RESULTS$StateEnd[RESULTS$StateEnd <= -99e8] <- NA
   if (ExportStateEnd) {
     RESULTS$StateEnd[-3L] <- ifelse(RESULTS$StateEnd[-3L] < 0, 0, RESULTS$StateEnd[-3L]) ## remove negative values except for the ExpStore location
     idNStates <- seq_len(NStates*NLayers) %% NStates
diff --git a/R/RunModel_GR1A.R b/R/RunModel_GR1A.R
index 7f67a3f9..39572b1c 100644
--- a/R/RunModel_GR1A.R
+++ b/R/RunModel_GR1A.R
@@ -63,11 +63,11 @@ RunModel_GR1A <- function(InputsModel, RunOptions, Param) {
                       NOutputs = as.integer(length(IndOutputs)),          ### number of output series
                       IndOutputs = IndOutputs,                            ### indices of output series
                       ## outputs
-                      Outputs = matrix(as.double(-999.999), nrow = LInputSeries, ncol = length(IndOutputs)), ### output series [mm/y]
-                      StateEnd = rep(as.double(-999.999), length(RunOptions$IniStates))                      ### state variables at the end of the model run
+                      Outputs = matrix(as.double(-99e9), nrow = LInputSeries, ncol = length(IndOutputs)), ### output series [mm/y]
+                      StateEnd = rep(as.double(-99e9), length(RunOptions$IniStates))                      ### state variables at the end of the model run
   )
-  RESULTS$Outputs[ round(RESULTS$Outputs , 3) == -999.999] <- NA
-  RESULTS$StateEnd[round(RESULTS$StateEnd, 3) == -999.999] <- NA
+  RESULTS$Outputs[RESULTS$Outputs   <= -99e8] <- NA
+  RESULTS$StateEnd[RESULTS$StateEnd <= -99e8] <- NA
   
   
   ## Output data preparation
diff --git a/R/RunModel_GR2M.R b/R/RunModel_GR2M.R
index e2868936..47bf78cc 100644
--- a/R/RunModel_GR2M.R
+++ b/R/RunModel_GR2M.R
@@ -76,11 +76,11 @@ RunModel_GR2M <- function(InputsModel, RunOptions, Param) {
                       NOutputs = as.integer(length(IndOutputs)),          ### number of output series
                       IndOutputs = IndOutputs,                            ### indices of output series
                       ## outputs
-                      Outputs = matrix(as.double(-999.999), nrow = LInputSeries, ncol = length(IndOutputs)), ### output series [mm or mm/month]
-                      StateEnd = rep(as.double(-999.999), length(RunOptions$IniStates))                      ### state variables at the end of the model run
+                      Outputs = matrix(as.double(-99e9), nrow = LInputSeries, ncol = length(IndOutputs)), ### output series [mm or mm/month]
+                      StateEnd = rep(as.double(-99e9), length(RunOptions$IniStates))                      ### state variables at the end of the model run
   )
-  RESULTS$Outputs [round(RESULTS$Outputs , 3) == -999.999] <- NA
-  RESULTS$StateEnd[round(RESULTS$StateEnd, 3) == -999.999] <- NA
+  RESULTS$Outputs[RESULTS$Outputs   <= -99e8] <- NA
+  RESULTS$StateEnd[RESULTS$StateEnd <= -99e8] <- NA
   if (ExportStateEnd) { 
     RESULTS$StateEnd <- CreateIniStates(FUN_MOD = RunModel_GR2M, InputsModel = InputsModel, 
                                         ProdStore = RESULTS$StateEnd[1L], RoutStore = RESULTS$StateEnd[2L], ExpStore = NULL, 
diff --git a/R/RunModel_GR4H.R b/R/RunModel_GR4H.R
index 388cb900..ef7e6e1e 100644
--- a/R/RunModel_GR4H.R
+++ b/R/RunModel_GR4H.R
@@ -81,11 +81,11 @@ RunModel_GR4H <- function(InputsModel, RunOptions, Param) {
                       NOutputs = as.integer(length(IndOutputs)),          ### number of output series
                       IndOutputs = IndOutputs,                            ### indices of output series
                       ## outputs
-                      Outputs = matrix(as.double(-999.999), nrow = LInputSeries, ncol = length(IndOutputs)), ### output series [mm or mm/h]
-                      StateEnd = rep(as.double(-999.999), length(RunOptions$IniStates))                      ### state variables at the end of the model run
+                      Outputs = matrix(as.double(-99e9), nrow = LInputSeries, ncol = length(IndOutputs)), ### output series [mm or mm/h]
+                      StateEnd = rep(as.double(-99e9), length(RunOptions$IniStates))                      ### state variables at the end of the model run
   )
-  RESULTS$Outputs[ round(RESULTS$Outputs , 3) == -999.999] <- NA
-  RESULTS$StateEnd[round(RESULTS$StateEnd, 3) == -999.999] <- NA
+  RESULTS$Outputs[RESULTS$Outputs   <= -99e8] <- NA
+  RESULTS$StateEnd[RESULTS$StateEnd <= -99e8] <- NA
   if (ExportStateEnd) {
     RESULTS$StateEnd[-3L] <- ifelse(RESULTS$StateEnd[-3L] < 0, 0, RESULTS$StateEnd[-3L]) ### remove negative values except for the ExpStore location
     RESULTS$StateEnd <- CreateIniStates(FUN_MOD = RunModel_GR4H, InputsModel = InputsModel, 
diff --git a/R/RunModel_GR4J.R b/R/RunModel_GR4J.R
index cab27ee3..c2e93549 100644
--- a/R/RunModel_GR4J.R
+++ b/R/RunModel_GR4J.R
@@ -80,11 +80,11 @@ RunModel_GR4J <- function(InputsModel, RunOptions, Param) {
                       NOutputs = as.integer(length(IndOutputs)),          ### number of output series
                       IndOutputs = IndOutputs,                            ### indices of output series
                       ## outputs
-                      Outputs = matrix(as.double(-999.999), nrow = LInputSeries, ncol = length(IndOutputs)), ### output series [mm or mm/d]
-                      StateEnd = rep(as.double(-999.999), length(RunOptions$IniStates))                      ### state variables at the end of the model run
+                      Outputs = matrix(as.double(-99e9), nrow = LInputSeries, ncol = length(IndOutputs)), ### output series [mm or mm/d]
+                      StateEnd = rep(as.double(-99e9), length(RunOptions$IniStates))                      ### state variables at the end of the model run
   )
-  RESULTS$Outputs[ round(RESULTS$Outputs , 3) == -999.999] <- NA
-  RESULTS$StateEnd[round(RESULTS$StateEnd, 3) == -999.999] <- NA
+  RESULTS$Outputs[RESULTS$Outputs   <= -99e8] <- NA
+  RESULTS$StateEnd[RESULTS$StateEnd <= -99e8] <- NA
   if (ExportStateEnd) {
     RESULTS$StateEnd[-3L] <- ifelse(RESULTS$StateEnd[-3L] < 0, 0, RESULTS$StateEnd[-3L]) ### remove negative values except for the ExpStore location
     RESULTS$StateEnd <- CreateIniStates(FUN_MOD = RunModel_GR4J, InputsModel = InputsModel, 
diff --git a/R/RunModel_GR5H.R b/R/RunModel_GR5H.R
index a8a5944e..9880cc43 100644
--- a/R/RunModel_GR5H.R
+++ b/R/RunModel_GR5H.R
@@ -91,11 +91,11 @@ RunModel_GR5H <- function(InputsModel, RunOptions, Param) {
                       NOutputs = as.integer(length(IndOutputs)),          ### number of output series
                       IndOutputs = IndOutputs,                            ### indices of output series
                       ## outputs
-                      Outputs = matrix(as.double(-999.999), nrow = LInputSeries, ncol = length(IndOutputs)), ### output series [mm or mm/h]
-                      StateEnd = rep(as.double(-999.999), length(RunOptions$IniStates))                      ### state variables at the end of the model run
+                      Outputs = matrix(as.double(-99e9), nrow = LInputSeries, ncol = length(IndOutputs)), ### output series [mm or mm/h]
+                      StateEnd = rep(as.double(-99e9), length(RunOptions$IniStates))                      ### state variables at the end of the model run
   )
-  RESULTS$Outputs[ round(RESULTS$Outputs , 3) == -999.999] <- NA
-  RESULTS$StateEnd[round(RESULTS$StateEnd, 3) == -999.999] <- NA
+  RESULTS$Outputs[RESULTS$Outputs   <= -99e8] <- NA
+  RESULTS$StateEnd[RESULTS$StateEnd <= -99e8] <- NA
   if (ExportStateEnd) {
     RESULTS$StateEnd[-3L] <- ifelse(RESULTS$StateEnd[-3L] < 0, 0, RESULTS$StateEnd[-3L]) ### remove negative values except for the ExpStore location
     RESULTS$StateEnd <- CreateIniStates(FUN_MOD = RunModel_GR5H, InputsModel = InputsModel,
diff --git a/R/RunModel_GR5J.R b/R/RunModel_GR5J.R
index 60fe028c..b14df6fd 100644
--- a/R/RunModel_GR5J.R
+++ b/R/RunModel_GR5J.R
@@ -81,11 +81,11 @@ RunModel_GR5J <- function(InputsModel, RunOptions, Param) {
                       NOutputs = as.integer(length(IndOutputs)),          ### number of output series
                       IndOutputs = IndOutputs,                            ### indices of output series
                       ## outputs
-                      Outputs = matrix(as.double(-999.999), nrow = LInputSeries, ncol = length(IndOutputs)), ### output series [mm or mm/d]
-                      StateEnd = rep(as.double(-999.999), length(RunOptions$IniStates))                      ### state variables at the end of the model run
+                      Outputs = matrix(as.double(-99e9), nrow = LInputSeries, ncol = length(IndOutputs)), ### output series [mm or mm/d]
+                      StateEnd = rep(as.double(-99e9), length(RunOptions$IniStates))                      ### state variables at the end of the model run
   )
-  RESULTS$Outputs[ round(RESULTS$Outputs , 3) == -999.999] <- NA
-  RESULTS$StateEnd[round(RESULTS$StateEnd, 3) == -999.999] <- NA
+  RESULTS$Outputs[RESULTS$Outputs   <= -99e8] <- NA
+  RESULTS$StateEnd[RESULTS$StateEnd <= -99e8] <- NA
   if (ExportStateEnd) {
     RESULTS$StateEnd[-3L] <- ifelse(RESULTS$StateEnd[-3L] < 0, 0, RESULTS$StateEnd[-3L]) ### remove negative values except for the ExpStore location
     RESULTS$StateEnd <- CreateIniStates(FUN_MOD = RunModel_GR5J, InputsModel = InputsModel, 
diff --git a/R/RunModel_GR6J.R b/R/RunModel_GR6J.R
index 4539fe3b..c66d4ba2 100644
--- a/R/RunModel_GR6J.R
+++ b/R/RunModel_GR6J.R
@@ -86,11 +86,11 @@ RunModel_GR6J <- function(InputsModel, RunOptions, Param) {
                       NOutputs = as.integer(length(IndOutputs)),          ### number of output series
                       IndOutputs = IndOutputs,                            ### indices of output series
                       ## outputs
-                      Outputs = matrix(as.double(-999.999), nrow = LInputSeries, ncol = length(IndOutputs)), ### output series [mm or mm/d]
-                      StateEnd = rep(as.double(-999.999), length(RunOptions$IniStates))                      ### state variables at the end of the model run
+                      Outputs = matrix(as.double(-99e9), nrow = LInputSeries, ncol = length(IndOutputs)), ### output series [mm or mm/d]
+                      StateEnd = rep(as.double(-99e9), length(RunOptions$IniStates))                      ### state variables at the end of the model run
   )
-  RESULTS$Outputs[ round(RESULTS$Outputs , 3) == -999.999] <- NA
-  RESULTS$StateEnd[round(RESULTS$StateEnd, 3) == -999.999] <- NA
+  RESULTS$Outputs[RESULTS$Outputs   <= -99e8] <- NA
+  RESULTS$StateEnd[RESULTS$StateEnd <= -99e8] <- NA
   if (ExportStateEnd) {
     RESULTS$StateEnd[-3L] <- ifelse(RESULTS$StateEnd[-3L] < 0, 0, RESULTS$StateEnd[-3L]) ### remove negative values except for the ExpStore location
     RESULTS$StateEnd <- CreateIniStates(FUN_MOD = RunModel_GR6J, InputsModel = InputsModel, 
-- 
GitLab