diff --git a/R/CalGR.R b/R/CalGR.R index 2ab26dc98869be0a9995d0c7a3b6cec8f9c6018b..f9ac28be4aa6c3f3731302ee92bef4a90c682d97 100644 --- a/R/CalGR.R +++ b/R/CalGR.R @@ -23,18 +23,22 @@ CalGR <- function(PrepGR, CalCrit = c("NSE", "KGE", "KGE2", "RMSE"), WupInd <- NULL if (!is.null(WupPer)) { - WupPer <- as.POSIXct(WupPer, tz = "UTC") - if (length(WupPer) != 2) { - stop("Warm-up period \"WupPer\" must be of length 2") - } - if (any(is.na(WupPer))) { - stop("Non convenient date format for the warm-up period \"WupPer\"") - } else { - if (!any(PrepGR$InputsModel$DatesR == WupPer[1]) | !any(PrepGR$InputsModel$DatesR == WupPer[2])) { - stop("Non convenient date for the warm-up period \"WupPer\"") + if (!identical(WupPer, 0L)){ + WupPer <- as.POSIXct(WupPer, tz = "UTC") + if (length(WupPer) != 2) { + stop("Warm-up period \"WupPer\" must be of length 2") + } + if (any(is.na(WupPer))) { + stop("Non convenient date format for the warm-up period \"WupPer\"") } else { - WupInd <- which(PrepGR$InputsModel$DatesR == WupPer[1]):which(PrepGR$InputsModel$DatesR == WupPer[2]) + if (!any(PrepGR$InputsModel$DatesR == WupPer[1]) | !any(PrepGR$InputsModel$DatesR == WupPer[2])) { + stop("Non convenient date for the warm-up period \"WupPer\"") + } else { + WupInd <- which(PrepGR$InputsModel$DatesR == WupPer[1]):which(PrepGR$InputsModel$DatesR == WupPer[2]) + } } + } else { + WupInd <- 0L } } diff --git a/R/SimGR.R b/R/SimGR.R index fe9183a042722167ac9736a64ad3d796cb59192a..f5d2fc7ffd860f660eb144ee08c7166fb27a6b6e 100644 --- a/R/SimGR.R +++ b/R/SimGR.R @@ -39,18 +39,22 @@ SimGR <- function(PrepGR, CalGR = NULL, Param, EffCrit = c("NSE", "KGE", "KGE2", WupInd <- NULL if (!is.null(WupPer)) { - WupPer <- as.POSIXct(WupPer, tz = "UTC") - if (length(WupPer) != 2) { - stop("Warm-up period \"WupPer\" must be of length 2") - } - if (any(is.na(WupPer))) { - stop("Non convenient date format for the warm-up period \"WupPer\"") - } else { - if (!any(PrepGR$InputsModel$DatesR == WupPer[1]) | !any(PrepGR$InputsModel$DatesR == WupPer[2])) { - stop("Non convenient date for the warm-up period \"WupPer\"") + if (!identical(WupPer, 0L)){ + WupPer <- as.POSIXct(WupPer, tz = "UTC") + if (length(WupPer) != 2) { + stop("Warm-up period \"WupPer\" must be of length 2") + } + if (any(is.na(WupPer))) { + stop("Non convenient date format for the warm-up period \"WupPer\"") } else { - WupInd <- which(PrepGR$InputsModel$DatesR == WupPer[1]):which(PrepGR$InputsModel$DatesR == WupPer[2]) + if (!any(PrepGR$InputsModel$DatesR == WupPer[1]) | !any(PrepGR$InputsModel$DatesR == WupPer[2])) { + stop("Non convenient date for the warm-up period \"WupPer\"") + } else { + WupInd <- which(PrepGR$InputsModel$DatesR == WupPer[1]):which(PrepGR$InputsModel$DatesR == WupPer[2]) + } } + } else { + WupInd <- 0L } }