diff --git a/DESCRIPTION b/DESCRIPTION index 37c96600a7a0cc47e96e3f1fbb7cb4b108537e5f..35cdeb7272e1a273385e1381dc164522ba1f3756 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.6.3.54 +Version: 1.6.3.55 Date: 2020-11-12 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 64c53d10a858ec6e7b145c061ccd29670eab0ce7..f0a82b7be6cc4b96716947c33a19efe2c0203e1a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,7 +4,7 @@ -### 1.6.3.54 Release Notes (2020-11-12) +### 1.6.3.55 Release Notes (2020-11-12) #### New features diff --git a/R/RunModel_GR2M.R b/R/RunModel_GR2M.R index cc889d1882e3b06dd28aeb5a5acb5a6b313a93b1..14a2b8ff393fc4f1d04f554dcc57b6cd0a9327e3 100644 --- a/R/RunModel_GR2M.R +++ b/R/RunModel_GR2M.R @@ -2,7 +2,7 @@ RunModel_GR2M <- function(InputsModel, RunOptions, Param) { ## Initialization of variables - NParam <- 2; + NParam <- 2 FortranOutputs <- .FortranOutputs(GR = "GR2M")$GR @@ -14,7 +14,7 @@ RunModel_GR2M <- function(InputsModel, RunOptions, Param) { if (inherits(RunOptions, "GR" ) == FALSE) { stop("'RunOptions' must be of class 'GR' ") } if (!is.vector(Param) | !is.numeric(Param)) { stop("'Param' must be a numeric vector") } if (sum(!is.na(Param)) != NParam) { stop(paste("'Param' must be a vector of length ", NParam, " and contain no NA", sep = "")) } - Param <- as.double(Param); + Param <- as.double(Param) Param_X1X2_threshold <- 1e-2 if (Param[1L] < Param_X1X2_threshold) { @@ -27,21 +27,21 @@ RunModel_GR2M <- function(InputsModel, RunOptions, Param) { } ## Input_data_preparation - if (identical(RunOptions$IndPeriod_WarmUp, as.integer(0))) { RunOptions$IndPeriod_WarmUp <- NULL; } - IndPeriod1 <- c(RunOptions$IndPeriod_WarmUp, RunOptions$IndPeriod_Run); + if (identical(RunOptions$IndPeriod_WarmUp, as.integer(0))) { RunOptions$IndPeriod_WarmUp <- NULL } + IndPeriod1 <- c(RunOptions$IndPeriod_WarmUp, RunOptions$IndPeriod_Run) LInputSeries <- as.integer(length(IndPeriod1)) - if ("all" %in% RunOptions$Outputs_Sim) { IndOutputs <- as.integer(1:length(FortranOutputs)); - } else { IndOutputs <- which(FortranOutputs %in% RunOptions$Outputs_Sim); } + if ("all" %in% RunOptions$Outputs_Sim) { IndOutputs <- as.integer(1:length(FortranOutputs)) + } else { IndOutputs <- which(FortranOutputs %in% RunOptions$Outputs_Sim) } ## Output_data_preparation - IndPeriod2 <- (length(RunOptions$IndPeriod_WarmUp)+1):LInputSeries; - ExportDatesR <- "DatesR" %in% RunOptions$Outputs_Sim; - ExportStateEnd <- "StateEnd" %in% RunOptions$Outputs_Sim; + IndPeriod2 <- (length(RunOptions$IndPeriod_WarmUp)+1):LInputSeries + ExportDatesR <- "DatesR" %in% RunOptions$Outputs_Sim + ExportStateEnd <- "StateEnd" %in% RunOptions$Outputs_Sim ## Use_of_IniResLevels if (!is.null(RunOptions$IniResLevels)) { - RunOptions$IniStates[1] <- RunOptions$IniResLevels[1]*Param[1]; ### production store level (mm) - RunOptions$IniStates[2] <- RunOptions$IniResLevels[2]*Param[2]; ### routing store level (mm) + RunOptions$IniStates[1] <- RunOptions$IniResLevels[1]*Param[1] ### production store level (mm) + RunOptions$IniStates[2] <- RunOptions$IniResLevels[2]*Param[2] ### routing store level (mm) } ## Call_fortan @@ -60,8 +60,8 @@ RunModel_GR2M <- function(InputsModel, RunOptions, Param) { Outputs = matrix(as.double(-999.999), nrow = LInputSeries, ncol = length(IndOutputs)), ### output series [mm] StateEnd = rep(as.double(-999.999), 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 [round(RESULTS$Outputs , 3) == (-999.999)] <- NA + RESULTS$StateEnd[round(RESULTS$StateEnd, 3) == (-999.999)] <- NA if (ExportStateEnd) { RESULTS$StateEnd <- CreateIniStates(FUN_MOD = RunModel_GR2M, InputsModel = InputsModel, ProdStore = RESULTS$StateEnd[1L], RoutStore = RESULTS$StateEnd[2L], ExpStore = NULL, @@ -74,28 +74,28 @@ RunModel_GR2M <- function(InputsModel, RunOptions, Param) { ## Output_data_preparation ## OutputsModel_only if (ExportDatesR == FALSE & ExportStateEnd == FALSE) { - OutputsModel <- lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2, i]); - names(OutputsModel) <- FortranOutputs[IndOutputs]; } + OutputsModel <- lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2, i]) + names(OutputsModel) <- FortranOutputs[IndOutputs] } ## DatesR_and_OutputsModel_only if (ExportDatesR == TRUE & ExportStateEnd == FALSE) { OutputsModel <- c( list(InputsModel$DatesR[RunOptions$IndPeriod_Run]), - lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2, i]) ); - names(OutputsModel) <- c("DatesR", FortranOutputs[IndOutputs]); } + lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2, i]) ) + names(OutputsModel) <- c("DatesR", FortranOutputs[IndOutputs]) } ## OutputsModel_and_SateEnd_only if (ExportDatesR == FALSE & ExportStateEnd == TRUE) { OutputsModel <- c( lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2, i]), - list(RESULTS$StateEnd) ); - names(OutputsModel) <- c(FortranOutputs[IndOutputs], "StateEnd"); } + list(RESULTS$StateEnd) ) + names(OutputsModel) <- c(FortranOutputs[IndOutputs], "StateEnd") } ## DatesR_and_OutputsModel_and_SateEnd if ((ExportDatesR==TRUE & ExportStateEnd==TRUE) | "all" %in% RunOptions$Outputs_Sim) { OutputsModel <- c( list(InputsModel$DatesR[RunOptions$IndPeriod_Run]), lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2, i]), - list(RESULTS$StateEnd) ); - names(OutputsModel) <- c("DatesR", FortranOutputs[IndOutputs], "StateEnd"); } + list(RESULTS$StateEnd) ) + names(OutputsModel) <- c("DatesR", FortranOutputs[IndOutputs], "StateEnd") } ## End - rm(RESULTS); - class(OutputsModel) <- c("OutputsModel", "monthly", "GR"); - return(OutputsModel); + rm(RESULTS) + class(OutputsModel) <- c("OutputsModel", "monthly", "GR") + return(OutputsModel) } diff --git a/R/RunModel_GR4H.R b/R/RunModel_GR4H.R index 7f2f8c078146b1463b439847e56035a3f5efffd3..f43091b14f9302be43f02725e1be42777c261bd1 100644 --- a/R/RunModel_GR4H.R +++ b/R/RunModel_GR4H.R @@ -2,7 +2,7 @@ RunModel_GR4H <- function(InputsModel, RunOptions, Param) { ## Initialization of variables - NParam <- 4; + NParam <- 4 FortranOutputs <- .FortranOutputs(GR = "GR4H")$GR @@ -14,7 +14,7 @@ RunModel_GR4H <- function(InputsModel, RunOptions, Param) { if (inherits(RunOptions, "GR" ) == FALSE) { stop("'RunOptions' must be of class 'GR' ") } if (!is.vector(Param) | !is.numeric(Param)) { stop("'Param' must be a numeric vector") } if (sum(!is.na(Param)) != NParam) { stop(paste("'Param' must be a vector of length ", NParam, " and contain no NA", sep = "")) } - Param <- as.double(Param); + Param <- as.double(Param) Param_X1X3_threshold <- 1e-2 Param_X4_threshold <- 0.5 @@ -32,21 +32,21 @@ RunModel_GR4H <- function(InputsModel, RunOptions, Param) { } ## Input_data_preparation - if (identical(RunOptions$IndPeriod_WarmUp, as.integer(0))) { RunOptions$IndPeriod_WarmUp <- NULL; } - IndPeriod1 <- c(RunOptions$IndPeriod_WarmUp, RunOptions$IndPeriod_Run); + if (identical(RunOptions$IndPeriod_WarmUp, as.integer(0))) { RunOptions$IndPeriod_WarmUp <- NULL } + IndPeriod1 <- c(RunOptions$IndPeriod_WarmUp, RunOptions$IndPeriod_Run) LInputSeries <- as.integer(length(IndPeriod1)) - if ("all" %in% RunOptions$Outputs_Sim) { IndOutputs <- as.integer(1:length(FortranOutputs)); - } else { IndOutputs <- which(FortranOutputs %in% RunOptions$Outputs_Sim); } + if ("all" %in% RunOptions$Outputs_Sim) { IndOutputs <- as.integer(1:length(FortranOutputs)) + } else { IndOutputs <- which(FortranOutputs %in% RunOptions$Outputs_Sim) } ## Output_data_preparation - IndPeriod2 <- (length(RunOptions$IndPeriod_WarmUp)+1):LInputSeries; - ExportDatesR <- "DatesR" %in% RunOptions$Outputs_Sim; - ExportStateEnd <- "StateEnd" %in% RunOptions$Outputs_Sim; + IndPeriod2 <- (length(RunOptions$IndPeriod_WarmUp)+1):LInputSeries + ExportDatesR <- "DatesR" %in% RunOptions$Outputs_Sim + ExportStateEnd <- "StateEnd" %in% RunOptions$Outputs_Sim ## Use_of_IniResLevels if (!is.null(RunOptions$IniResLevels)) { - RunOptions$IniStates[1] <- RunOptions$IniResLevels[1]*Param[1]; ### production store level (mm) - RunOptions$IniStates[2] <- RunOptions$IniResLevels[2]*Param[3]; ### routing store level (mm) + RunOptions$IniStates[1] <- RunOptions$IniResLevels[1]*Param[1] ### production store level (mm) + RunOptions$IniStates[2] <- RunOptions$IniResLevels[2]*Param[3] ### routing store level (mm) } ## Call_fortan @@ -65,8 +65,8 @@ RunModel_GR4H <- function(InputsModel, RunOptions, Param) { Outputs = matrix(as.double(-999.999), nrow = LInputSeries, ncol = length(IndOutputs)), ### output series [mm] StateEnd = rep(as.double(-999.999), 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[ round(RESULTS$Outputs , 3) == (-999.999)] <- NA + RESULTS$StateEnd[round(RESULTS$StateEnd, 3) == (-999.999)] <- 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, @@ -79,28 +79,28 @@ RunModel_GR4H <- function(InputsModel, RunOptions, Param) { ## Output_data_preparation ## OutputsModel_only if (ExportDatesR == FALSE & ExportStateEnd == FALSE) { - OutputsModel <- lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2, i]); - names(OutputsModel) <- FortranOutputs[IndOutputs]; } + OutputsModel <- lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2, i]) + names(OutputsModel) <- FortranOutputs[IndOutputs] } ## DatesR_and_OutputsModel_only if (ExportDatesR == TRUE & ExportStateEnd == FALSE) { OutputsModel <- c( list(InputsModel$DatesR[RunOptions$IndPeriod_Run]), - lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2, i]) ); - names(OutputsModel) <- c("DatesR", FortranOutputs[IndOutputs]); } + lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2, i]) ) + names(OutputsModel) <- c("DatesR", FortranOutputs[IndOutputs]) } ## OutputsModel_and_SateEnd_only if (ExportDatesR == FALSE & ExportStateEnd == TRUE) { OutputsModel <- c( lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2, i]), - list(RESULTS$StateEnd) ); - names(OutputsModel) <- c(FortranOutputs[IndOutputs], "StateEnd"); } + list(RESULTS$StateEnd) ) + names(OutputsModel) <- c(FortranOutputs[IndOutputs], "StateEnd") } ## DatesR_and_OutputsModel_and_SateEnd if ((ExportDatesR == TRUE & ExportStateEnd == TRUE) | "all" %in% RunOptions$Outputs_Sim) { OutputsModel <- c( list(InputsModel$DatesR[RunOptions$IndPeriod_Run]), lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2, i]), - list(RESULTS$StateEnd) ); - names(OutputsModel) <- c("DatesR", FortranOutputs[IndOutputs], "StateEnd"); } + list(RESULTS$StateEnd) ) + names(OutputsModel) <- c("DatesR", FortranOutputs[IndOutputs], "StateEnd") } ## End - rm(RESULTS); - class(OutputsModel) <- c("OutputsModel", "hourly", "GR"); - return(OutputsModel); + rm(RESULTS) + class(OutputsModel) <- c("OutputsModel", "hourly", "GR") + return(OutputsModel) } diff --git a/R/RunModel_GR4J.R b/R/RunModel_GR4J.R index 8d8c5da6f7cd209ff0693d855f7eafe8c50f857f..98973044a6e96409aeb3c3dec70c591d9cc5e336 100644 --- a/R/RunModel_GR4J.R +++ b/R/RunModel_GR4J.R @@ -2,7 +2,7 @@ RunModel_GR4J <- function(InputsModel, RunOptions, Param) { ## Initialization of variables - NParam <- 4; + NParam <- 4 FortranOutputs <- .FortranOutputs(GR = "GR4J")$GR @@ -14,7 +14,7 @@ RunModel_GR4J <- function(InputsModel, RunOptions, Param) { if (inherits(RunOptions, "GR" ) == FALSE) { stop("'RunOptions' must be of class 'GR' ") } if (!is.vector(Param) | !is.numeric(Param)) { stop("'Param' must be a numeric vector") } if (sum(!is.na(Param)) != NParam) { stop(paste("'Param' must be a vector of length ", NParam, " and contain no NA", sep = "")) } - Param <- as.double(Param); + Param <- as.double(Param) Param_X1X3_threshold <- 1e-2 Param_X4_threshold <- 0.5 @@ -32,20 +32,20 @@ RunModel_GR4J <- function(InputsModel, RunOptions, Param) { } ## Input_data_preparation - if (identical(RunOptions$IndPeriod_WarmUp, as.integer(0))) { RunOptions$IndPeriod_WarmUp <- NULL; } - IndPeriod1 <- c(RunOptions$IndPeriod_WarmUp, RunOptions$IndPeriod_Run); + if (identical(RunOptions$IndPeriod_WarmUp, as.integer(0))) { RunOptions$IndPeriod_WarmUp <- NULL } + IndPeriod1 <- c(RunOptions$IndPeriod_WarmUp, RunOptions$IndPeriod_Run) LInputSeries <- as.integer(length(IndPeriod1)) - if ("all" %in% RunOptions$Outputs_Sim) { IndOutputs <- as.integer(1:length(FortranOutputs)); - } else { IndOutputs <- which(FortranOutputs %in% RunOptions$Outputs_Sim); } + if ("all" %in% RunOptions$Outputs_Sim) { IndOutputs <- as.integer(1:length(FortranOutputs)) + } else { IndOutputs <- which(FortranOutputs %in% RunOptions$Outputs_Sim) } ## Input_data_preparation - IndPeriod2 <- (length(RunOptions$IndPeriod_WarmUp)+1):LInputSeries; - ExportDatesR <- "DatesR" %in% RunOptions$Outputs_Sim; - ExportStateEnd <- "StateEnd" %in% RunOptions$Outputs_Sim; + IndPeriod2 <- (length(RunOptions$IndPeriod_WarmUp)+1):LInputSeries + ExportDatesR <- "DatesR" %in% RunOptions$Outputs_Sim + ExportStateEnd <- "StateEnd" %in% RunOptions$Outputs_Sim ## Use_of_IniResLevels if (!is.null(RunOptions$IniResLevels)) { - RunOptions$IniStates[1] <- RunOptions$IniResLevels[1]*Param[1]; ### production store level (mm) - RunOptions$IniStates[2] <- RunOptions$IniResLevels[2]*Param[3]; ### routing store level (mm) + RunOptions$IniStates[1] <- RunOptions$IniResLevels[1]*Param[1] ### production store level (mm) + RunOptions$IniStates[2] <- RunOptions$IniResLevels[2]*Param[3] ### routing store level (mm) } ## Call_fortan @@ -64,8 +64,8 @@ RunModel_GR4J <- function(InputsModel, RunOptions, Param) { Outputs = matrix(as.double(-999.999), nrow = LInputSeries, ncol = length(IndOutputs)), ### output series [mm] StateEnd = rep(as.double(-999.999), 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[ round(RESULTS$Outputs , 3) == (-999.999)] <- NA + RESULTS$StateEnd[round(RESULTS$StateEnd, 3) == (-999.999)] <- 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, @@ -78,28 +78,28 @@ RunModel_GR4J <- function(InputsModel, RunOptions, Param) { ## Output_data_preparation ## OutputsModel_only if (ExportDatesR == FALSE & ExportStateEnd == FALSE) { - OutputsModel <- lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2, i]); - names(OutputsModel) <- FortranOutputs[IndOutputs]; } + OutputsModel <- lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2, i]) + names(OutputsModel) <- FortranOutputs[IndOutputs] } ## DatesR_and_OutputsModel_only if (ExportDatesR == TRUE & ExportStateEnd == FALSE) { OutputsModel <- c( list(InputsModel$DatesR[RunOptions$IndPeriod_Run]), - lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2, i]) ); - names(OutputsModel) <- c("DatesR", FortranOutputs[IndOutputs]); } + lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2, i]) ) + names(OutputsModel) <- c("DatesR", FortranOutputs[IndOutputs]) } ## OutputsModel_and_StateEnd_only if (ExportDatesR == FALSE & ExportStateEnd == TRUE) { OutputsModel <- c( lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2, i]), - list(RESULTS$StateEnd) ); - names(OutputsModel) <- c(FortranOutputs[IndOutputs], "StateEnd"); } + list(RESULTS$StateEnd) ) + names(OutputsModel) <- c(FortranOutputs[IndOutputs], "StateEnd") } ## DatesR_and_OutputsModel_and_StateEnd if ((ExportDatesR == TRUE & ExportStateEnd == TRUE) | "all" %in% RunOptions$Outputs_Sim) { OutputsModel <- c( list(InputsModel$DatesR[RunOptions$IndPeriod_Run]), lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2, i]), - list(RESULTS$StateEnd) ); - names(OutputsModel) <- c("DatesR", FortranOutputs[IndOutputs], "StateEnd"); } + list(RESULTS$StateEnd) ) + names(OutputsModel) <- c("DatesR", FortranOutputs[IndOutputs], "StateEnd") } ## End - rm(RESULTS); - class(OutputsModel) <- c("OutputsModel", "daily", "GR"); - return(OutputsModel); + rm(RESULTS) + class(OutputsModel) <- c("OutputsModel", "daily", "GR") + return(OutputsModel) } diff --git a/R/RunModel_GR5H.R b/R/RunModel_GR5H.R index e8295302ee4cbeef0ef2e3588b7410918b07eeec..a09f8bf0e573665d9948c2f4ee399e048e7913dd 100644 --- a/R/RunModel_GR5H.R +++ b/R/RunModel_GR5H.R @@ -2,7 +2,7 @@ RunModel_GR5H <- function(InputsModel, RunOptions, Param) { ## Initialization of variables - NParam <- 5; + NParam <- 5 FortranOutputs <- .FortranOutputs(GR = "GR5H")$GR IsIntStore <- inherits(RunOptions, "interception") if (IsIntStore) { @@ -20,7 +20,7 @@ RunModel_GR5H <- function(InputsModel, RunOptions, Param) { if (inherits(RunOptions, "GR" ) == FALSE) { stop("'RunOptions' must be of class 'GR' ") } if (!is.vector(Param) | !is.numeric(Param)) { stop("'Param' must be a numeric vector") } if (sum(!is.na(Param)) != NParam) { stop(paste("'Param' must be a vector of length ", NParam, " and contain no NA", sep = "")) } - Param <- as.double(Param); + Param <- as.double(Param) Param_X1X3_threshold <- 1e-2 Param_X4_threshold <- 0.5 @@ -38,23 +38,23 @@ RunModel_GR5H <- function(InputsModel, RunOptions, Param) { } ## Input_data_preparation - if (identical(RunOptions$IndPeriod_WarmUp, as.integer(0))) { RunOptions$IndPeriod_WarmUp <- NULL; } - IndPeriod1 <- c(RunOptions$IndPeriod_WarmUp, RunOptions$IndPeriod_Run); + if (identical(RunOptions$IndPeriod_WarmUp, as.integer(0))) { RunOptions$IndPeriod_WarmUp <- NULL } + IndPeriod1 <- c(RunOptions$IndPeriod_WarmUp, RunOptions$IndPeriod_Run) LInputSeries <- as.integer(length(IndPeriod1)) - if ("all" %in% RunOptions$Outputs_Sim) { IndOutputs <- as.integer(1:length(FortranOutputs)); - } else { IndOutputs <- which(FortranOutputs %in% RunOptions$Outputs_Sim); } + if ("all" %in% RunOptions$Outputs_Sim) { IndOutputs <- as.integer(1:length(FortranOutputs)) + } else { IndOutputs <- which(FortranOutputs %in% RunOptions$Outputs_Sim) } ## Output_data_preparation - IndPeriod2 <- (length(RunOptions$IndPeriod_WarmUp)+1):LInputSeries; - ExportDatesR <- "DatesR" %in% RunOptions$Outputs_Sim; - ExportStateEnd <- "StateEnd" %in% RunOptions$Outputs_Sim; + IndPeriod2 <- (length(RunOptions$IndPeriod_WarmUp)+1):LInputSeries + ExportDatesR <- "DatesR" %in% RunOptions$Outputs_Sim + ExportStateEnd <- "StateEnd" %in% RunOptions$Outputs_Sim ## Use_of_IniResLevels if (!is.null(RunOptions$IniResLevels)) { - RunOptions$IniStates[1] <- RunOptions$IniResLevels[1]*Param[1]; ### production store level (mm) - RunOptions$IniStates[2] <- RunOptions$IniResLevels[2]*Param[3]; ### routing store level (mm) + RunOptions$IniStates[1] <- RunOptions$IniResLevels[1]*Param[1] ### production store level (mm) + RunOptions$IniStates[2] <- RunOptions$IniResLevels[2]*Param[3] ### routing store level (mm) if (IsIntStore) { - RunOptions$IniStates[4] <- RunOptions$IniResLevels[4] * Imax; ### interception store level (mm) + RunOptions$IniStates[4] <- RunOptions$IniResLevels[4] * Imax ### interception store level (mm) } } @@ -75,8 +75,8 @@ RunModel_GR5H <- function(InputsModel, RunOptions, Param) { 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 ) - RESULTS$Outputs[ round(RESULTS$Outputs , 3) == (-999.999)] <- NA; - RESULTS$StateEnd[round(RESULTS$StateEnd, 3) == (-999.999)] <- NA; + RESULTS$Outputs[ round(RESULTS$Outputs , 3) == (-999.999)] <- NA + RESULTS$StateEnd[round(RESULTS$StateEnd, 3) == (-999.999)] <- 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, @@ -90,31 +90,31 @@ RunModel_GR5H <- function(InputsModel, RunOptions, Param) { ## Output_data_preparation ## OutputsModel_only if (ExportDatesR == FALSE & ExportStateEnd == FALSE) { - OutputsModel <- lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2, i]); - names(OutputsModel) <- FortranOutputs[IndOutputs]; } + OutputsModel <- lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2, i]) + names(OutputsModel) <- FortranOutputs[IndOutputs] } ## DatesR_and_OutputsModel_only if (ExportDatesR == TRUE & ExportStateEnd == FALSE) { OutputsModel <- c( list(InputsModel$DatesR[RunOptions$IndPeriod_Run]), - lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2, i]) ); - names(OutputsModel) <- c("DatesR", FortranOutputs[IndOutputs]); } + lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2, i]) ) + names(OutputsModel) <- c("DatesR", FortranOutputs[IndOutputs]) } ## OutputsModel_and_StateEnd_only if (ExportDatesR == FALSE & ExportStateEnd == TRUE) { OutputsModel <- c( lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2, i]), - list(RESULTS$StateEnd) ); - names(OutputsModel) <- c(FortranOutputs[IndOutputs], "StateEnd"); } + list(RESULTS$StateEnd) ) + names(OutputsModel) <- c(FortranOutputs[IndOutputs], "StateEnd") } ## DatesR_and_OutputsModel_and_StateEnd if ((ExportDatesR == TRUE & ExportStateEnd == TRUE) | "all" %in% RunOptions$Outputs_Sim) { OutputsModel <- c( list(InputsModel$DatesR[RunOptions$IndPeriod_Run]), lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2, i]), - list(RESULTS$StateEnd) ); - names(OutputsModel) <- c("DatesR", FortranOutputs[IndOutputs], "StateEnd"); } + list(RESULTS$StateEnd) ) + names(OutputsModel) <- c("DatesR", FortranOutputs[IndOutputs], "StateEnd") } ## End - rm(RESULTS); - class(OutputsModel) <- c("OutputsModel", "hourly", "GR"); + rm(RESULTS) + class(OutputsModel) <- c("OutputsModel", "hourly", "GR") if (IsIntStore) { class(OutputsModel) <- c(class(OutputsModel), "interception") } - return(OutputsModel); + return(OutputsModel) } diff --git a/R/RunModel_GR5J.R b/R/RunModel_GR5J.R index ba94d13fb090f258f917d1b5fa87ee18e7c15cd4..60cd9fd9501ec0430230ab48a64bd55158de3762 100644 --- a/R/RunModel_GR5J.R +++ b/R/RunModel_GR5J.R @@ -2,7 +2,7 @@ RunModel_GR5J <- function(InputsModel, RunOptions, Param) { ## Initialization of variables - NParam <- 5; + NParam <- 5 FortranOutputs <- .FortranOutputs(GR = "GR5J")$GR @@ -14,7 +14,7 @@ RunModel_GR5J <- function(InputsModel, RunOptions, Param) { if (inherits(RunOptions, "GR" ) == FALSE) { stop("'RunOptions' must be of class 'GR' ") } if (!is.vector(Param) | !is.numeric(Param)) { stop("'Param' must be a numeric vector") } if (sum(!is.na(Param)) != NParam) { stop(paste("'Param' must be a vector of length ", NParam, " and contain no NA", sep = "")) } - Param <- as.double(Param); + Param <- as.double(Param) Param_X1X3_threshold <- 1e-2 Param_X4_threshold <- 0.5 @@ -32,21 +32,21 @@ RunModel_GR5J <- function(InputsModel, RunOptions, Param) { } ## Input_data_preparation - if (identical(RunOptions$IndPeriod_WarmUp, as.integer(0))) { RunOptions$IndPeriod_WarmUp <- NULL; } - IndPeriod1 <- c(RunOptions$IndPeriod_WarmUp, RunOptions$IndPeriod_Run); + if (identical(RunOptions$IndPeriod_WarmUp, as.integer(0))) { RunOptions$IndPeriod_WarmUp <- NULL } + IndPeriod1 <- c(RunOptions$IndPeriod_WarmUp, RunOptions$IndPeriod_Run) LInputSeries <- as.integer(length(IndPeriod1)) - if ("all" %in% RunOptions$Outputs_Sim) { IndOutputs <- as.integer(1:length(FortranOutputs)); - } else { IndOutputs <- which(FortranOutputs %in% RunOptions$Outputs_Sim); } + if ("all" %in% RunOptions$Outputs_Sim) { IndOutputs <- as.integer(1:length(FortranOutputs)) + } else { IndOutputs <- which(FortranOutputs %in% RunOptions$Outputs_Sim) } ## Output_data_preparation - IndPeriod2 <- (length(RunOptions$IndPeriod_WarmUp)+1):LInputSeries; - ExportDatesR <- "DatesR" %in% RunOptions$Outputs_Sim; - ExportStateEnd <- "StateEnd" %in% RunOptions$Outputs_Sim; + IndPeriod2 <- (length(RunOptions$IndPeriod_WarmUp)+1):LInputSeries + ExportDatesR <- "DatesR" %in% RunOptions$Outputs_Sim + ExportStateEnd <- "StateEnd" %in% RunOptions$Outputs_Sim ## Use_of_IniResLevels if (!is.null(RunOptions$IniResLevels)) { - RunOptions$IniStates[1] <- RunOptions$IniResLevels[1]*Param[1]; ### production store level (mm) - RunOptions$IniStates[2] <- RunOptions$IniResLevels[2]*Param[3]; ### routing store level (mm) + RunOptions$IniStates[1] <- RunOptions$IniResLevels[1]*Param[1] ### production store level (mm) + RunOptions$IniStates[2] <- RunOptions$IniResLevels[2]*Param[3] ### routing store level (mm) } ## Call_fortan @@ -65,8 +65,8 @@ RunModel_GR5J <- function(InputsModel, RunOptions, Param) { Outputs = matrix(as.double(-999.999), nrow = LInputSeries, ncol = length(IndOutputs)), ### output series [mm] StateEnd = rep(as.double(-999.999), 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[ round(RESULTS$Outputs , 3) == (-999.999)] <- NA + RESULTS$StateEnd[round(RESULTS$StateEnd, 3) == (-999.999)] <- 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, @@ -79,28 +79,28 @@ RunModel_GR5J <- function(InputsModel, RunOptions, Param) { ## Output_data_preparation ## OutputsModel_only if (ExportDatesR == FALSE & ExportStateEnd == FALSE) { - OutputsModel <- lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2, i]); - names(OutputsModel) <- FortranOutputs[IndOutputs]; } + OutputsModel <- lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2, i]) + names(OutputsModel) <- FortranOutputs[IndOutputs] } ## DatesR_and_OutputsModel_only if (ExportDatesR == TRUE & ExportStateEnd == FALSE) { OutputsModel <- c( list(InputsModel$DatesR[RunOptions$IndPeriod_Run]), - lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2, i]) ); - names(OutputsModel) <- c("DatesR", FortranOutputs[IndOutputs]); } + lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2, i]) ) + names(OutputsModel) <- c("DatesR", FortranOutputs[IndOutputs]) } ## OutputsModel_and_SateEnd_only if (ExportDatesR == FALSE & ExportStateEnd == TRUE) { OutputsModel <- c( lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2, i]), - list(RESULTS$StateEnd) ); - names(OutputsModel) <- c(FortranOutputs[IndOutputs], "StateEnd"); } + list(RESULTS$StateEnd) ) + names(OutputsModel) <- c(FortranOutputs[IndOutputs], "StateEnd") } ## DatesR_and_OutputsModel_and_SateEnd if ((ExportDatesR == TRUE & ExportStateEnd == TRUE) | "all" %in% RunOptions$Outputs_Sim) { OutputsModel <- c( list(InputsModel$DatesR[RunOptions$IndPeriod_Run]), lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2, i]), - list(RESULTS$StateEnd) ); - names(OutputsModel) <- c("DatesR", FortranOutputs[IndOutputs], "StateEnd"); } + list(RESULTS$StateEnd) ) + names(OutputsModel) <- c("DatesR", FortranOutputs[IndOutputs], "StateEnd") } ## End - rm(RESULTS); - class(OutputsModel) <- c("OutputsModel", "daily", "GR"); - return(OutputsModel); + rm(RESULTS) + class(OutputsModel) <- c("OutputsModel", "daily", "GR") + return(OutputsModel) } diff --git a/R/RunModel_GR6J.R b/R/RunModel_GR6J.R index 2a43efc17e18d7c49738fce41a17c42090b0ae68..f5df113b84d12843494c2d0e758cce55fafb925b 100644 --- a/R/RunModel_GR6J.R +++ b/R/RunModel_GR6J.R @@ -2,7 +2,7 @@ RunModel_GR6J <- function(InputsModel, RunOptions, Param) { ## Initialization of variables - NParam <- 6; + NParam <- 6 FortranOutputs <- .FortranOutputs(GR = "GR6J")$GR @@ -14,7 +14,7 @@ RunModel_GR6J <- function(InputsModel, RunOptions, Param) { if (inherits(RunOptions, "GR" ) == FALSE) { stop("'RunOptions' must be of class 'GR' ") } if (!is.vector(Param) | !is.numeric(Param)) { stop("'Param' must be a numeric vector") } if (sum(!is.na(Param)) != NParam) { stop(paste("'Param' must be a vector of length ", NParam, " and contain no NA", sep = "")) } - Param <- as.double(Param); + Param <- as.double(Param) Param_X1X3X6_threshold <- 1e-2 Param_X4_threshold <- 0.5 @@ -36,21 +36,21 @@ RunModel_GR6J <- function(InputsModel, RunOptions, Param) { } ## Input_data_preparation - if (identical(RunOptions$IndPeriod_WarmUp, as.integer(0))) { RunOptions$IndPeriod_WarmUp <- NULL; } - IndPeriod1 <- c(RunOptions$IndPeriod_WarmUp, RunOptions$IndPeriod_Run); + if (identical(RunOptions$IndPeriod_WarmUp, as.integer(0))) { RunOptions$IndPeriod_WarmUp <- NULL } + IndPeriod1 <- c(RunOptions$IndPeriod_WarmUp, RunOptions$IndPeriod_Run) LInputSeries <- as.integer(length(IndPeriod1)) - if ("all" %in% RunOptions$Outputs_Sim) { IndOutputs <- as.integer(1:length(FortranOutputs)); - } else { IndOutputs <- which(FortranOutputs %in% RunOptions$Outputs_Sim); } + if ("all" %in% RunOptions$Outputs_Sim) { IndOutputs <- as.integer(1:length(FortranOutputs)) + } else { IndOutputs <- which(FortranOutputs %in% RunOptions$Outputs_Sim) } ## Output_data_preparation - IndPeriod2 <- (length(RunOptions$IndPeriod_WarmUp)+1):LInputSeries; - ExportDatesR <- "DatesR" %in% RunOptions$Outputs_Sim; - ExportStateEnd <- "StateEnd" %in% RunOptions$Outputs_Sim; + IndPeriod2 <- (length(RunOptions$IndPeriod_WarmUp)+1):LInputSeries + ExportDatesR <- "DatesR" %in% RunOptions$Outputs_Sim + ExportStateEnd <- "StateEnd" %in% RunOptions$Outputs_Sim ## Use_of_IniResLevels if (!is.null(RunOptions$IniResLevels)) { - RunOptions$IniStates[1] <- RunOptions$IniResLevels[1]*Param[1]; ### production store level (mm) - RunOptions$IniStates[2] <- RunOptions$IniResLevels[2]*Param[3]; ### routing store level (mm) + RunOptions$IniStates[1] <- RunOptions$IniResLevels[1]*Param[1] ### production store level (mm) + RunOptions$IniStates[2] <- RunOptions$IniResLevels[2]*Param[3] ### routing store level (mm) RunOptions$IniStates[3] <- RunOptions$IniResLevels[3] ### exponential store level (mm) } @@ -70,8 +70,8 @@ RunModel_GR6J <- function(InputsModel, RunOptions, Param) { Outputs = matrix(as.double(-999.999), nrow = LInputSeries, ncol = length(IndOutputs)), ### output series [mm] StateEnd = rep(as.double(-999.999), 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[ round(RESULTS$Outputs , 3) == (-999.999)] <- NA + RESULTS$StateEnd[round(RESULTS$StateEnd, 3) == (-999.999)] <- 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, @@ -84,28 +84,28 @@ RunModel_GR6J <- function(InputsModel, RunOptions, Param) { ## Output_data_preparation ## OutputsModel_only if (ExportDatesR == FALSE & ExportStateEnd == FALSE) { - OutputsModel <- lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2, i]); - names(OutputsModel) <- FortranOutputs[IndOutputs]; } + OutputsModel <- lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2, i]) + names(OutputsModel) <- FortranOutputs[IndOutputs] } ## DatesR_and_OutputsModel_only if (ExportDatesR == TRUE & ExportStateEnd == FALSE) { OutputsModel <- c( list(InputsModel$DatesR[RunOptions$IndPeriod_Run]), - lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2, i]) ); - names(OutputsModel) <- c("DatesR", FortranOutputs[IndOutputs]); } + lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2, i]) ) + names(OutputsModel) <- c("DatesR", FortranOutputs[IndOutputs]) } ## OutputsModel_and_SateEnd_only if (ExportDatesR == FALSE & ExportStateEnd == TRUE) { OutputsModel <- c( lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2, i]), - list(RESULTS$StateEnd) ); - names(OutputsModel) <- c(FortranOutputs[IndOutputs], "StateEnd"); } + list(RESULTS$StateEnd) ) + names(OutputsModel) <- c(FortranOutputs[IndOutputs], "StateEnd") } ## DatesR_and_OutputsModel_and_SateEnd if ((ExportDatesR == TRUE & ExportStateEnd == TRUE) | "all" %in% RunOptions$Outputs_Sim) { OutputsModel <- c( list(InputsModel$DatesR[RunOptions$IndPeriod_Run]), lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2, i]), - list(RESULTS$StateEnd) ); - names(OutputsModel) <- c("DatesR", FortranOutputs[IndOutputs], "StateEnd"); } + list(RESULTS$StateEnd) ) + names(OutputsModel) <- c("DatesR", FortranOutputs[IndOutputs], "StateEnd") } ## End - rm(RESULTS); - class(OutputsModel) <- c("OutputsModel", "daily", "GR"); - return(OutputsModel); + rm(RESULTS) + class(OutputsModel) <- c("OutputsModel", "daily", "GR") + return(OutputsModel) }