From eec01d4fdb59b97adb9dc35445587a4496558bbe Mon Sep 17 00:00:00 2001 From: Delaigue Olivier <olivier.delaigue@irstea.priv> Date: Fri, 1 Mar 2019 18:54:40 +0100 Subject: [PATCH] v1.2.7.3 CLEAN: remove unnecessary return(NULL) after stops --- DESCRIPTION | 2 +- NEWS.rmd | 2 +- R/Calibration_Michel.R | 10 ---------- R/CreateCalibOptions.R | 16 ---------------- R/CreateIniStates.R | 6 ------ R/CreateInputsCrit.R | 12 ------------ R/CreateInputsModel.R | 27 -------------------------- R/CreateRunOptions.R | 39 -------------------------------------- R/ErrorCrit.R | 2 -- R/RunModel_CemaNeige.R | 9 --------- R/RunModel_CemaNeigeGR4J.R | 19 +++++++++---------- R/RunModel_CemaNeigeGR5J.R | 19 +++++++++---------- R/RunModel_CemaNeigeGR6J.R | 19 +++++++++---------- R/RunModel_GR1A.R | 14 +++++++------- R/RunModel_GR2M.R | 14 +++++++------- R/RunModel_GR4H.R | 14 +++++++------- R/RunModel_GR4J.R | 14 +++++++------- R/RunModel_GR5J.R | 14 +++++++------- R/RunModel_GR6J.R | 14 +++++++------- R/SeriesAggreg.R | 29 ---------------------------- R/TransfoParam_GR1A.R | 1 - R/TransfoParam_GR2M.R | 1 - R/TransfoParam_GR4H.R | 2 +- R/TransfoParam_GR4J.R | 2 +- R/TransfoParam_GR5J.R | 2 +- R/TransfoParam_GR6J.R | 2 +- R/plot.OutputsModel.R | 17 +++++++---------- 27 files changed, 82 insertions(+), 240 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 15d19719..e4683b62 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.7.2 +Version: 1.2.7.3 Date: 2019-03-01 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 187aaee2..8ad84bc1 100644 --- a/NEWS.rmd +++ b/NEWS.rmd @@ -13,7 +13,7 @@ output: -### 1.2.7.2 Release Notes (2019-03-01) +### 1.2.7.3 Release Notes (2019-03-01) diff --git a/R/Calibration_Michel.R b/R/Calibration_Michel.R index 5db59c98..e0c3c818 100644 --- a/R/Calibration_Michel.R +++ b/R/Calibration_Michel.R @@ -5,27 +5,21 @@ Calibration_Michel <- function(InputsModel, RunOptions, InputsCrit, CalibOptions ##_____Arguments_check_____________________________________________________________________ if (!inherits(InputsModel, "InputsModel")) { stop("InputsModel must be of class 'InputsModel'") - return(NULL) } if (!inherits(RunOptions, "RunOptions")) { stop("RunOptions must be of class 'RunOptions'") - return(NULL) } if (!inherits(InputsCrit, "InputsCrit")) { stop("InputsCrit must be of class 'InputsCrit'") - return(NULL) } if (inherits(InputsCrit, "Multi")) { stop("InputsCrit must be of class 'Single' or 'Compo'") - return(NULL) } if (!inherits(CalibOptions, "CalibOptions")) { stop("CalibOptions must be of class 'CalibOptions'") - return(NULL) } if (!inherits(CalibOptions, "HBAN")) { stop("CalibOptions must be of class 'HBAN' if Calibration_Michel is used") - return(NULL) } if (!missing(FUN_CRIT)) { warning("argument 'FUN_CRIT' is deprecated. The error criterion function is now automatically get from the 'InputsCrit' object", call. = FALSE) @@ -92,7 +86,6 @@ Calibration_Michel <- function(InputsModel, RunOptions, InputsCrit, CalibOptions } if (is.null(FUN_TRANSFO)) { stop("FUN_TRANSFO was not found (in Calibration function)") - return(NULL) } } @@ -115,7 +108,6 @@ Calibration_Michel <- function(InputsModel, RunOptions, InputsCrit, CalibOptions } if (NParam > 20) { stop("Calibration_Michel can handle a maximum of 20 parameters") - return(NULL) } HistParamR <- matrix(NA, nrow = 500 * NParam, ncol = NParam) HistParamT <- matrix(NA, nrow = 500 * NParam, ncol = NParam) @@ -238,11 +230,9 @@ Calibration_Michel <- function(InputsModel, RunOptions, InputsCrit, CalibOptions ##Format_checking if (nrow(NewParamOptimT) != 1 | nrow(OldParamOptimT) != 1) { stop("each input set must be a matrix of one single line") - return(NULL) } if (ncol(NewParamOptimT)!=ncol(OldParamOptimT) | ncol(NewParamOptimT) != length(OptimParam)) { stop("each input set must have the same number of values") - return(NULL) } ##Proposal_of_new_parameter_sets ###(local search providing 2 * NParam-1 new sets) NParam <- ncol(NewParamOptimT) diff --git a/R/CreateCalibOptions.R b/R/CreateCalibOptions.R index aecc687b..cc09f8c0 100644 --- a/R/CreateCalibOptions.R +++ b/R/CreateCalibOptions.R @@ -172,15 +172,12 @@ CreateCalibOptions <- } else { if (!is.vector(FixedParam)) { stop("FixedParam must be a vector") - return(NULL) } if (length(FixedParam) != NParam) { stop("Incompatibility between FixedParam length and FUN_MOD") - return(NULL) } if (all(!is.na(FixedParam))) { stop("At least one parameter must be not set (NA)") - return(NULL) } if (all(is.na(FixedParam))) { warning("You have not set any parameter in \"FixedParam\"") @@ -197,23 +194,18 @@ CreateCalibOptions <- } else { if (!is.matrix(SearchRanges)) { stop("SearchRanges must be a matrix") - return(NULL) } if (!is.numeric(SearchRanges)) { stop("SearchRanges must be a matrix of numeric values") - return(NULL) } if (sum(is.na(SearchRanges)) != 0) { stop("SearchRanges must not include NA values") - return(NULL) } if (nrow(SearchRanges) != 2) { stop("SearchRanges must have 2 rows") - return(NULL) } if (ncol(SearchRanges) != NParam) { stop("Incompatibility between SearchRanges ncol and FUN_MOD") - return(NULL) } } @@ -280,37 +272,29 @@ CreateCalibOptions <- if ("HBAN" %in% ObjectClass & !is.null(StartParamList)) { if (!is.matrix(StartParamList)) { stop("StartParamList must be a matrix") - return(NULL) } if (!is.numeric(StartParamList)) { stop("StartParamList must be a matrix of numeric values") - return(NULL) } if (sum(is.na(StartParamList)) != 0) { stop("StartParamList must not include NA values") - return(NULL) } if (ncol(StartParamList) != NParam) { stop("Incompatibility between StartParamList ncol and FUN_MOD") - return(NULL) } } if ("HBAN" %in% ObjectClass & !is.null(StartParamDistrib)) { if (!is.matrix(StartParamDistrib)) { stop("StartParamDistrib must be a matrix") - return(NULL) } if (!is.numeric(StartParamDistrib[1, ])) { stop("StartParamDistrib must be a matrix of numeric values") - return(NULL) } if (sum(is.na(StartParamDistrib[1, ])) != 0) { stop("StartParamDistrib must not include NA values on the first line") - return(NULL) } if (ncol(StartParamDistrib) != NParam) { stop("Incompatibility between StartParamDistrib ncol and FUN_MOD") - return(NULL) } } diff --git a/R/CreateIniStates.R b/R/CreateIniStates.R index a5bc0d09..be0554e6 100644 --- a/R/CreateIniStates.R +++ b/R/CreateIniStates.R @@ -43,22 +43,18 @@ CreateIniStates <- function(FUN_MOD, InputsModel, } if (!BOOL) { stop("Incorrect 'FUN_MOD' for use in 'CreateIniStates'") - return(NULL) } ## check InputsModel if (!inherits(InputsModel, "InputsModel")) { stop("'InputsModel' must be of class 'InputsModel'") - return(NULL) } if ("GR" %in% ObjectClass & !inherits(InputsModel, "GR")) { stop("'InputsModel' must be of class 'GR'") - return(NULL) } if ("CemaNeige" %in% ObjectClass & !inherits(InputsModel, "CemaNeige")) { stop("'InputsModel' must be of class 'CemaNeige'") - return(NULL) } @@ -70,7 +66,6 @@ CreateIniStates <- function(FUN_MOD, InputsModel, if (identical(FUN_MOD, RunModel_GR6J) | identical(FUN_MOD, RunModel_CemaNeigeGR6J)) { if (is.null(ExpStore)) { stop("'RunModel_*GR6J' need an 'ExpStore' value") - return(NULL) } } else if (!is.null(ExpStore)) { if (verbose) { @@ -136,7 +131,6 @@ CreateIniStates <- function(FUN_MOD, InputsModel, if("CemaNeige" %in% ObjectClass & (is.null(GCemaNeigeLayers) | is.null(eTGCemaNeigeLayers))) { stop("'RunModel_CemaNeigeGR*' need values for 'GCemaNeigeLayers' and 'GCemaNeigeLayers'") - return(NULL) } if(!"CemaNeige" %in% ObjectClass & (!is.null(GCemaNeigeLayers) | !is.null(eTGCemaNeigeLayers))) { diff --git a/R/CreateInputsCrit.R b/R/CreateInputsCrit.R index 7c1e861d..8b09dc42 100644 --- a/R/CreateInputsCrit.R +++ b/R/CreateInputsCrit.R @@ -40,7 +40,6 @@ CreateInputsCrit <- function(FUN_CRIT, ## check 'InputsModel' if (!inherits(InputsModel, "InputsModel")) { stop("'InputsModel' must be of class 'InputsModel'") - return(NULL) } @@ -109,7 +108,6 @@ CreateInputsCrit <- function(FUN_CRIT, ## check 'RunOptions' if (!inherits(RunOptions , "RunOptions")) { stop("'RunOptions' must be of class 'RunOptions'") - return(NULL) } @@ -140,17 +138,14 @@ CreateInputsCrit <- function(FUN_CRIT, if (!(identical(iListArgs2$FUN_CRIT, ErrorCrit_NSE ) | identical(iListArgs2$FUN_CRIT, ErrorCrit_KGE ) | identical(iListArgs2$FUN_CRIT, ErrorCrit_KGE2) | identical(iListArgs2$FUN_CRIT, ErrorCrit_RMSE))) { stop("incorrect 'FUN_CRIT' for use in 'CreateInputsCrit'", call. = FALSE) - return(NULL) } if (identical(iListArgs2$FUN_CRIT, ErrorCrit_RMSE) & length(listArgs$weights) > 1 & all(!is.null(unlist(listArgs$weights)))) { stop("calculating a composite criterion with the RMSE is not allowed since RMSE is not an adimensional measure", call. = FALSE) - return(NULL) } ## check 'obs' if (!is.vector(iListArgs2$obs) | length(iListArgs2$obs) != LLL | !is.numeric(iListArgs2$obs)) { stop(sprintf("'obs' must be a (list of) vector(s) of numeric values of length %i", LLL), call. = FALSE) - return(NULL) } ## check 'BoolCrit' @@ -159,17 +154,14 @@ CreateInputsCrit <- function(FUN_CRIT, } if (!is.logical(iListArgs2$BoolCrit)) { stop("'BoolCrit' must be a (list of) vector(s) of boolean", call. = FALSE) - return(NULL) } if (length(iListArgs2$BoolCrit) != LLL) { stop("'BoolCrit' and 'InputsModel' series must have the same length", call. = FALSE) - return(NULL) } ## check 'varObs' if (!is.vector(iListArgs2$varObs) | length(iListArgs2$varObs) != 1 | !is.character(iListArgs2$varObs) | !all(iListArgs2$varObs %in% inVarObs)) { stop(msgVarObs, call. = FALSE) - return(NULL) } ## check 'varObs' + 'obs' @@ -193,14 +185,12 @@ CreateInputsCrit <- function(FUN_CRIT, ## check 'transfo' if (is.null(iListArgs2$transfo) | !is.vector(iListArgs2$transfo) | length(iListArgs2$transfo) != 1 | !is.character(iListArgs2$transfo) | !all(iListArgs2$transfo %in% inTransfo)) { stop(msgTransfo, call. = FALSE) - return(NULL) } ## check 'weights' if (!is.null(iListArgs2$weights)) { if (!is.vector(iListArgs2$weights) | length(iListArgs2$weights) != 1 | !is.numeric(iListArgs2$weights) | any(iListArgs2$weights < 0)) { stop("'weights' must be a single (list of) positive or equal to zero value(s)", call. = FALSE) - return(NULL) } } @@ -208,7 +198,6 @@ CreateInputsCrit <- function(FUN_CRIT, if (!is.null(iListArgs2$epsilon)) { if (!is.vector(iListArgs2$epsilon) | length(iListArgs2$epsilon) != 1 | !is.numeric(iListArgs2$epsilon) | any(iListArgs2$epsilon <= 0)) { stop("'epsilon' must be a single (list of) positive value(s)", call. = FALSE) - return(NULL) } } else if (iListArgs2$transfo %in% c("log", "inv") & any(iListArgs2$obs %in% 0) & warnings) { warning("zeroes detected in obs: the corresponding time-steps will be excluded by the 'ErrorCrit*' functions if the epsilon agrument = NULL", call. = FALSE) @@ -259,7 +248,6 @@ CreateInputsCrit <- function(FUN_CRIT, if(equalInputsCrit) { warning(sprintf("Elements %i and %i of the criteria list are identical. This might not be necessary", i[1], i[2]), call. = FALSE) } - return(NULL) }) } diff --git a/R/CreateInputsModel.R b/R/CreateInputsModel.R index fa659709..d2f09fbd 100644 --- a/R/CreateInputsModel.R +++ b/R/CreateInputsModel.R @@ -59,18 +59,15 @@ CreateInputsModel <- function(FUN_MOD, } if (!BOOL) { stop("Incorrect FUN_MOD for use in CreateInputsModel") - return(NULL) } ##check_arguments if ("GR" %in% ObjectClass | "CemaNeige" %in% ObjectClass) { if (is.null(DatesR)) { stop("DatesR is missing") - return(NULL) } if ("POSIXlt" %in% class(DatesR) == FALSE & "POSIXct" %in% class(DatesR) == FALSE) { stop("DatesR must be defined as POSIXlt or POSIXct") - return(NULL) } if ("POSIXlt" %in% class(DatesR) == FALSE) { DatesR <- as.POSIXlt(DatesR) @@ -78,101 +75,79 @@ CreateInputsModel <- function(FUN_MOD, if (difftime(tail(DatesR, 1), tail(DatesR, 2), units = "secs")[[1]] %in% TimeStep == FALSE) { TimeStepName <- grep("hourly|daily|monthly|yearly", ObjectClass, value = TRUE) stop(paste0("The time step of the model inputs must be ", TimeStepName, "\n")) - return(NULL) } if (any(duplicated(DatesR))) { stop("DatesR must not include duplicated values") - return(NULL) } LLL <- length(DatesR) } if ("GR" %in% ObjectClass) { if (is.null(Precip)) { stop("Precip is missing") - return(NULL) } if (is.null(PotEvap)) { stop("PotEvap is missing") - return(NULL) } if (!is.vector(Precip) | !is.vector(PotEvap)) { stop("Precip and PotEvap must be vectors of numeric values") - return(NULL) } if (!is.numeric(Precip) | !is.numeric(PotEvap)) { stop("Precip and PotEvap must be vectors of numeric values") - return(NULL) } if (length(Precip) != LLL | length(PotEvap) != LLL) { stop("Precip, PotEvap and DatesR must have the same length") - return(NULL) } } if ("CemaNeige" %in% ObjectClass) { if (is.null(Precip)) { stop("Precip is missing") - return(NULL) } if (is.null(TempMean)) { stop("TempMean is missing") - return(NULL) } if (!is.vector(Precip) | !is.vector(TempMean)) { stop("Precip and TempMean must be vectors of numeric values") - return(NULL) } if (!is.numeric(Precip) | !is.numeric(TempMean)) { stop("Precip and TempMean must be vectors of numeric values") - return(NULL) } if (length(Precip) != LLL | length(TempMean) != LLL) { stop("Precip, TempMean and DatesR must have the same length") - return(NULL) } if (is.null(TempMin) != is.null(TempMax)) { stop("TempMin and TempMax must be both defined if not null") - return(NULL) } if (!is.null(TempMin) & !is.null(TempMax)) { if (!is.vector(TempMin) | !is.vector(TempMax)) { stop("TempMin and TempMax must be vectors of numeric values") - return(NULL) } if (!is.numeric(TempMin) | !is.numeric(TempMax)) { stop("TempMin and TempMax must be vectors of numeric values") - return(NULL) } if (length(TempMin) != LLL | length(TempMax) != LLL) { stop("TempMin, TempMax and DatesR must have the same length") - return(NULL) } } if (!is.null(HypsoData)) { if (!is.vector(HypsoData)) { stop("HypsoData must be a vector of numeric values if not null") - return(NULL) } if (!is.numeric(HypsoData)) { stop("HypsoData must be a vector of numeric values if not null") - return(NULL) } if (length(HypsoData) != 101) { stop("HypsoData must be of length 101 if not null") - return(NULL) } if (sum(is.na(HypsoData)) != 0 & sum(is.na(HypsoData)) != 101) { stop("HypsoData must not contain any NA if not null") - return(NULL) } } if (!is.null(ZInputs)) { if (length(ZInputs) != 1) { stop("\t ZInputs must be a single numeric value if not null") - return(NULL) } if (is.na(ZInputs) | !is.numeric(ZInputs)) { stop("\t ZInputs must be a single numeric value if not null") - return(NULL) } } if (is.null(HypsoData)) { @@ -192,7 +167,6 @@ CreateInputsModel <- function(FUN_MOD, } if (NLayers <= 0) { stop("NLayers must be a positive integer value") - return(NULL) } if (NLayers != as.integer(NLayers)) { warning("Coerce NLayers to be of integer type (", NLayers, " => ", as.integer(NLayers), ")") @@ -260,7 +234,6 @@ CreateInputsModel <- function(FUN_MOD, if (Select[1L] > Select[2L]) { stop("Time series could not be trunced since missing values were detected at the list time-step") - return(NULL) } if ("GR" %in% ObjectClass) { Precip <- Precip[Select] diff --git a/R/CreateRunOptions.R b/R/CreateRunOptions.R index df16668b..25512811 100644 --- a/R/CreateRunOptions.R +++ b/R/CreateRunOptions.R @@ -38,60 +38,48 @@ CreateRunOptions <- function(FUN_MOD, InputsModel, IndPeriod_WarmUp = NULL, IndP } if (!BOOL) { stop("incorrect 'FUN_MOD' for use in 'CreateRunOptions'") - return(NULL) } ##check_InputsModel if (!inherits(InputsModel, "InputsModel")) { stop("'InputsModel' must be of class 'InputsModel'") - return(NULL) } if ("GR" %in% ObjectClass & !inherits(InputsModel, "GR")) { stop("'InputsModel' must be of class 'GR'") - return(NULL) } if ("CemaNeige" %in% ObjectClass & !inherits(InputsModel, "CemaNeige")) { stop("'InputsModel' must be of class 'CemaNeige'") - return(NULL) } if ("hourly" %in% ObjectClass & !inherits(InputsModel, "hourly")) { stop("'InputsModel' must be of class 'hourly'") - return(NULL) } if ("daily" %in% ObjectClass & !inherits(InputsModel, "daily")) { stop("'InputsModel' must be of class 'daily'") - return(NULL) } if ("monthly" %in% ObjectClass & !inherits(InputsModel, "monthly")) { stop("'InputsModel' must be of class 'monthly'") - return(NULL) } if ("yearly" %in% ObjectClass & !inherits(InputsModel, "yearly")) { stop("'InputsModel' must be of class 'yearly'") - return(NULL) } ##check_IndPeriod_Run if (!is.vector(IndPeriod_Run)) { stop("'IndPeriod_Run' must be a vector of numeric values") - return(NULL) } if (!is.numeric(IndPeriod_Run)) { stop("'IndPeriod_Run' must be a vector of numeric values") - return(NULL) } if (identical(as.integer(IndPeriod_Run), as.integer(seq(from = IndPeriod_Run[1], to = tail(IndPeriod_Run, 1), by = 1))) == FALSE) { stop("'IndPeriod_Run' must be a continuous sequence of integers") - return(NULL) } if (storage.mode(IndPeriod_Run) != "integer") { stop("'IndPeriod_Run' should be of type integer") - return(NULL) } @@ -136,15 +124,12 @@ CreateRunOptions <- function(FUN_MOD, InputsModel, IndPeriod_WarmUp = NULL, IndP if (!is.null(IndPeriod_WarmUp)) { if (!is.vector(IndPeriod_WarmUp)) { stop("'IndPeriod_WarmUp' must be a vector of numeric values") - return(NULL) } if (!is.numeric(IndPeriod_WarmUp)) { stop("'IndPeriod_WarmUp' must be a vector of numeric values") - return(NULL) } if (storage.mode(IndPeriod_WarmUp) != "integer") { stop("'IndPeriod_WarmUp' should be of type integer") - return(NULL) } if (identical(IndPeriod_WarmUp, as.integer(0)) & verbose) { message(paste0(WTxt, "\t No warm up period is used \n")) @@ -163,7 +148,6 @@ CreateRunOptions <- function(FUN_MOD, InputsModel, IndPeriod_WarmUp = NULL, IndP if (!is.null(IniResLevels)) { if (!is.vector(IniResLevels) | !is.numeric(IniResLevels) | any(is.na(IniResLevels))) { stop("'IniResLevels' must be a vector of numeric values") - return(NULL) } if ((identical(FUN_MOD, RunModel_GR4H) | identical(FUN_MOD, RunModel_GR4J) | identical(FUN_MOD, RunModel_CemaNeigeGR4J) | @@ -171,12 +155,10 @@ CreateRunOptions <- function(FUN_MOD, InputsModel, IndPeriod_WarmUp = NULL, IndP identical(FUN_MOD, RunModel_GR2M)) & length(IniResLevels) != 2) { stop("The length of 'IniResLevels' must be 2 for the chosen 'FUN_MOD'") - return(NULL) } if ((identical(FUN_MOD,RunModel_GR6J) | identical(FUN_MOD,RunModel_CemaNeigeGR6J)) & length(IniResLevels) != 3) { stop("The length of 'IniResLevels' must be 3 for the chosen 'FUN_MOD'") - return(NULL) } } else if (is.null(IniStates)) { if (identical(FUN_MOD, RunModel_GR6J) | identical(FUN_MOD, RunModel_CemaNeigeGR6J)) { @@ -221,31 +203,24 @@ CreateRunOptions <- function(FUN_MOD, InputsModel, IndPeriod_WarmUp = NULL, IndP if (!inherits(IniStates, "IniStates")) { stop("'IniStates' must be an object of class 'IniStates'\n") - return(NULL) } if (sum(ObjectClass %in% class(IniStates)) < 2) { stop(paste0("Non convenient 'IniStates' for this 'FUN_MOD'\n")) - return(NULL) } if (identical(FUN_MOD, RunModel_GR1A) & !is.null(IniStates)) { ## GR1A stop(paste0("'IniStates' is not available for this 'FUN_MOD'\n")) - return(NULL) } if ((identical(FUN_MOD, RunModel_GR5J) | identical(FUN_MOD, RunModel_CemaNeigeGR5J)) & !all(is.na(IniStates$UH$UH1))) { ## GR5J stop(paste0("Non convenient IniStates for this 'FUN_MOD.' In 'IniStates', UH1 has to be a vector of NA for GR5J")) - return(NULL) } if ((identical(FUN_MOD, RunModel_GR6J) | identical(FUN_MOD, RunModel_CemaNeigeGR6J)) & is.na(IniStates$Store$Exp)) { ## GR6J stop(paste0("Non convenient IniStates for this 'FUN_MOD.' GR6J needs an exponential store value in 'IniStates'")) - return(NULL) } if (!(identical(FUN_MOD, RunModel_GR6J) | identical(FUN_MOD, RunModel_CemaNeigeGR6J)) & !is.na(IniStates$Store$Exp)) { ## except GR6J stop(paste0("Non convenient IniStates for this 'FUN_MOD.' No exponential store value needed in 'IniStates'")) - return(NULL) } # if (length(na.omit(unlist(IniStates))) != NState) { # stop(paste0("The length of IniStates must be ", NState, " for the chosen FUN_MOD")) - # return(NULL) # } if (!"CemaNeige" %in% ObjectClass & any(is.na(IniStates$CemaNeigeLayers$G ))) { IniStates$CemaNeigeLayers$G <- NULL @@ -293,15 +268,12 @@ CreateRunOptions <- function(FUN_MOD, InputsModel, IndPeriod_WarmUp = NULL, IndP ##check_Outputs_Sim if (!is.vector(Outputs_Sim)) { stop("Outputs_Sim must be a vector of characters") - return(NULL) } if (!is.character(Outputs_Sim)) { stop("Outputs_Sim must be a vector of characters") - return(NULL) } if (sum(is.na(Outputs_Sim)) != 0) { stop("Outputs_Sim must not contain NA") - return(NULL) } if ("all" %in% Outputs_Sim) { Outputs_Sim <- c("DatesR", Outputs_all, "StateEnd") @@ -310,8 +282,6 @@ CreateRunOptions <- function(FUN_MOD, InputsModel, IndPeriod_WarmUp = NULL, IndP if (length(Test) != 0) { stop(paste0( "'Outputs_Sim' is incorrectly defined: ", paste(Outputs_Sim[Test], collapse = ", "), " not found")) - return(NULL) - } Outputs_Sim <- Outputs_Sim[!duplicated(Outputs_Sim)] @@ -331,15 +301,12 @@ CreateRunOptions <- function(FUN_MOD, InputsModel, IndPeriod_WarmUp = NULL, IndP } else { if (!is.vector(Outputs_Cal)) { stop("'Outputs_Cal' must be a vector of characters") - return(NULL) } if (!is.character(Outputs_Cal)) { stop("'Outputs_Cal' must be a vector of characters") - return(NULL) } if (sum(is.na(Outputs_Cal)) != 0) { stop("'Outputs_Cal' must not contain NA") - return(NULL) } } if ("all" %in% Outputs_Cal) { @@ -351,8 +318,6 @@ CreateRunOptions <- function(FUN_MOD, InputsModel, IndPeriod_WarmUp = NULL, IndP if (length(Test) != 0) { stop(paste0("'Outputs_Cal' is incorrectly defined: ", paste(Outputs_Cal[Test], collapse = ", "), " not found")) - return(NULL) - } Outputs_Cal <- Outputs_Cal[!duplicated(Outputs_Cal)] Outputs_Calxxx <- unique(Outputs_Cal[!duplicated(Outputs_Cal)]) @@ -388,7 +353,6 @@ CreateRunOptions <- function(FUN_MOD, InputsModel, IndPeriod_WarmUp = NULL, IndP } if (is.null(Factor)) { stop("'InputsModel' must be of class 'hourly', 'daily', 'monthly' or 'yearly'") - return(NULL) } MeanAnSolidPrecip <- rep(mean(SolidPrecip) * Factor, NLayers) ### default value: same Gseuil for all layers @@ -401,15 +365,12 @@ CreateRunOptions <- function(FUN_MOD, InputsModel, IndPeriod_WarmUp = NULL, IndP if ("CemaNeige" %in% ObjectClass & !is.null(MeanAnSolidPrecip)) { if (!is.vector(MeanAnSolidPrecip)) { stop(paste0("'MeanAnSolidPrecip' must be a vector of numeric values")) - return(NULL) } if (!is.numeric(MeanAnSolidPrecip)) { stop(paste0("'MeanAnSolidPrecip' must be a vector of numeric values")) - return(NULL) } if (length(MeanAnSolidPrecip) != NLayers) { stop(paste0("'MeanAnSolidPrecip' must be a numeric vector of length ", NLayers, "")) - return(NULL) } } diff --git a/R/ErrorCrit.R b/R/ErrorCrit.R index b57ef82f..a84230a6 100644 --- a/R/ErrorCrit.R +++ b/R/ErrorCrit.R @@ -4,11 +4,9 @@ ErrorCrit <- function(InputsCrit, OutputsModel, FUN_CRIT, warnings = TRUE, verbo if (!inherits(InputsCrit, "InputsCrit")) { stop("InputsCrit must be of class 'InputsCrit'") - return(NULL) } if (!inherits(OutputsModel, "OutputsModel")) { stop("OutputsModel must be of class 'OutputsModel'") - return(NULL) } if (!missing(FUN_CRIT)) { warning("argument 'FUN_CRIT' is deprecated. The error criterion function is now automatically get from the 'InputsCrit' object", call. = FALSE) diff --git a/R/RunModel_CemaNeige.R b/R/RunModel_CemaNeige.R index fb1517a5..db5f3b5b 100644 --- a/R/RunModel_CemaNeige.R +++ b/R/RunModel_CemaNeige.R @@ -4,7 +4,6 @@ RunModel_CemaNeige <- function(InputsModel, RunOptions, Param, IsHyst = FALSE) { ## Arguments_check if (!is.logical(IsHyst) | length(IsHyst) != 1L) { stop("'IsHyst' must be a 'logical' of length 1") - return(NULL) } @@ -17,31 +16,24 @@ RunModel_CemaNeige <- function(InputsModel, RunOptions, Param, IsHyst = FALSE) { ## Arguments_check if (!inherits(InputsModel, "InputsModel")) { stop("'InputsModel' must be of class 'InputsModel'") - return(NULL) } if (!inherits(InputsModel, "daily")) { stop("'InputsModel' must be of class 'daily'") - return(NULL) } if (!inherits(InputsModel, "CemaNeige")) { stop("'InputsModel' must be of class 'CemaNeige'") - return(NULL) } if (!inherits(RunOptions, "RunOptions")) { stop("'RunOptions' must be of class 'RunOptions'") - return(NULL) } if (!inherits(RunOptions, "CemaNeige")) { stop("'RunOptions' must be of class 'CemaNeige'") - return(NULL) } if (!is.vector(Param) | !is.numeric(Param)) { stop("'Param' must be a numeric vector") - return(NULL) } if (sum(!is.na(Param)) != NParam) { stop(sprintf("'Param' must be a vector of length %i and contain no NA", NParam)) - return(NULL) } ## Input_data_preparation @@ -63,7 +55,6 @@ RunModel_CemaNeige <- function(InputsModel, RunOptions, Param, IsHyst = FALSE) { if (sum(is.na(ParamCemaNeige)) != 0) { stop("Param contains missing values") - return(NULL) } if ("all" %in% RunOptions$Outputs_Sim) { IndOutputsCemaNeige <- 1:length(FortranOutputsCemaNeige) diff --git a/R/RunModel_CemaNeigeGR4J.R b/R/RunModel_CemaNeigeGR4J.R index 4afe165a..6d4d4e41 100644 --- a/R/RunModel_CemaNeigeGR4J.R +++ b/R/RunModel_CemaNeigeGR4J.R @@ -4,7 +4,6 @@ RunModel_CemaNeigeGR4J <- function(InputsModel,RunOptions,Param, IsHyst = FALSE) ## Arguments_check if (!is.logical(IsHyst) | length(IsHyst) != 1L) { stop("'IsHyst' must be a 'logical' of length 1") - return(NULL) } NParam <- ifelse(IsHyst, 8L, 6L) @@ -13,15 +12,15 @@ RunModel_CemaNeigeGR4J <- function(InputsModel,RunOptions,Param, IsHyst = FALSE) ##Arguments_check - if(inherits(InputsModel,"InputsModel")==FALSE){ stop("InputsModel must be of class 'InputsModel'"); return(NULL); } - if(inherits(InputsModel,"daily" )==FALSE){ stop("InputsModel must be of class 'daily' "); return(NULL); } - if(inherits(InputsModel,"GR" )==FALSE){ stop("InputsModel must be of class 'GR' "); return(NULL); } - if(inherits(InputsModel,"CemaNeige" )==FALSE){ stop("InputsModel must be of class 'CemaNeige' "); return(NULL); } - if(inherits(RunOptions,"RunOptions" )==FALSE){ stop("RunOptions must be of class 'RunOptions' "); return(NULL); } - if(inherits(RunOptions,"GR" )==FALSE){ stop("RunOptions must be of class 'GR' "); return(NULL); } - if(inherits(RunOptions,"CemaNeige" )==FALSE){ stop("RunOptions must be of class 'CemaNeige' "); return(NULL); } - if(!is.vector(Param) | !is.numeric(Param)){ stop("Param must be a numeric vector"); return(NULL); } - if(sum(!is.na(Param))!=NParam){ stop(paste("Param must be a vector of length ",NParam," and contain no NA",sep="")); return(NULL); } + if(inherits(InputsModel,"InputsModel")==FALSE){ stop("InputsModel must be of class 'InputsModel'") } + if(inherits(InputsModel,"daily" )==FALSE){ stop("InputsModel must be of class 'daily' ") } + if(inherits(InputsModel,"GR" )==FALSE){ stop("InputsModel must be of class 'GR' ") } + if(inherits(InputsModel,"CemaNeige" )==FALSE){ stop("InputsModel must be of class 'CemaNeige' ") } + if(inherits(RunOptions,"RunOptions" )==FALSE){ stop("RunOptions must be of class 'RunOptions' ") } + if(inherits(RunOptions,"GR" )==FALSE){ stop("RunOptions must be of class 'GR' ") } + if(inherits(RunOptions,"CemaNeige" )==FALSE){ stop("RunOptions must be of class 'CemaNeige' ") } + 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_X1X3_threshold <- 1e-2 diff --git a/R/RunModel_CemaNeigeGR5J.R b/R/RunModel_CemaNeigeGR5J.R index fe5321ce..92fe0f66 100644 --- a/R/RunModel_CemaNeigeGR5J.R +++ b/R/RunModel_CemaNeigeGR5J.R @@ -4,7 +4,6 @@ RunModel_CemaNeigeGR5J <- function(InputsModel,RunOptions,Param, IsHyst = FALSE) ## Arguments_check if (!is.logical(IsHyst) | length(IsHyst) != 1L) { stop("'IsHyst' must be a 'logical' of length 1") - return(NULL) } NParam <- ifelse(IsHyst, 9L, 7L) @@ -12,15 +11,15 @@ RunModel_CemaNeigeGR5J <- function(InputsModel,RunOptions,Param, IsHyst = FALSE) FortranOutputs <- .FortranOutputs(GR = "GR5J", isCN = TRUE) ##Arguments_check - if(inherits(InputsModel,"InputsModel")==FALSE){ stop("InputsModel must be of class 'InputsModel'"); return(NULL); } - if(inherits(InputsModel,"daily" )==FALSE){ stop("InputsModel must be of class 'daily' "); return(NULL); } - if(inherits(InputsModel,"GR" )==FALSE){ stop("InputsModel must be of class 'GR' "); return(NULL); } - if(inherits(InputsModel,"CemaNeige" )==FALSE){ stop("InputsModel must be of class 'CemaNeige' "); return(NULL); } - if(inherits(RunOptions,"RunOptions" )==FALSE){ stop("RunOptions must be of class 'RunOptions' "); return(NULL); } - if(inherits(RunOptions,"GR" )==FALSE){ stop("RunOptions must be of class 'GR' "); return(NULL); } - if(inherits(RunOptions,"CemaNeige" )==FALSE){ stop("RunOptions must be of class 'CemaNeige' "); return(NULL); } - if(!is.vector(Param) | !is.numeric(Param)){ stop("Param must be a numeric vector"); return(NULL); } - if(sum(!is.na(Param))!=NParam){ stop(paste("Param must be a vector of length ",NParam," and contain no NA",sep="")); return(NULL); } + if(inherits(InputsModel,"InputsModel")==FALSE){ stop("InputsModel must be of class 'InputsModel'") } + if(inherits(InputsModel,"daily" )==FALSE){ stop("InputsModel must be of class 'daily' ") } + if(inherits(InputsModel,"GR" )==FALSE){ stop("InputsModel must be of class 'GR' ") } + if(inherits(InputsModel,"CemaNeige" )==FALSE){ stop("InputsModel must be of class 'CemaNeige' ") } + if(inherits(RunOptions,"RunOptions" )==FALSE){ stop("RunOptions must be of class 'RunOptions' ") } + if(inherits(RunOptions,"GR" )==FALSE){ stop("RunOptions must be of class 'GR' ") } + if(inherits(RunOptions,"CemaNeige" )==FALSE){ stop("RunOptions must be of class 'CemaNeige' ") } + 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_X1X3_threshold <- 1e-2 diff --git a/R/RunModel_CemaNeigeGR6J.R b/R/RunModel_CemaNeigeGR6J.R index afdad047..2301c5ac 100644 --- a/R/RunModel_CemaNeigeGR6J.R +++ b/R/RunModel_CemaNeigeGR6J.R @@ -4,7 +4,6 @@ RunModel_CemaNeigeGR6J <- function(InputsModel,RunOptions,Param, IsHyst = FALSE) ## Arguments_check if (!is.logical(IsHyst) | length(IsHyst) != 1L) { stop("'IsHyst' must be a 'logical' of length 1") - return(NULL) } NParam <- ifelse(IsHyst, 10L, 8L) @@ -12,15 +11,15 @@ RunModel_CemaNeigeGR6J <- function(InputsModel,RunOptions,Param, IsHyst = FALSE) FortranOutputs <- .FortranOutputs(GR = "GR6J", isCN = TRUE) ##Arguments_check - if(inherits(InputsModel,"InputsModel")==FALSE){ stop("InputsModel must be of class 'InputsModel'"); return(NULL); } - if(inherits(InputsModel,"daily" )==FALSE){ stop("InputsModel must be of class 'daily' "); return(NULL); } - if(inherits(InputsModel,"GR" )==FALSE){ stop("InputsModel must be of class 'GR' "); return(NULL); } - if(inherits(InputsModel,"CemaNeige" )==FALSE){ stop("InputsModel must be of class 'CemaNeige' "); return(NULL); } - if(inherits(RunOptions,"RunOptions" )==FALSE){ stop("RunOptions must be of class 'RunOptions' "); return(NULL); } - if(inherits(RunOptions,"GR" )==FALSE){ stop("RunOptions must be of class 'GR' "); return(NULL); } - if(inherits(RunOptions,"CemaNeige" )==FALSE){ stop("RunOptions must be of class 'CemaNeige' "); return(NULL); } - if(!is.vector(Param) | !is.numeric(Param)){ stop("Param must be a numeric vector"); return(NULL); } - if(sum(!is.na(Param))!=NParam){ stop(paste("Param must be a vector of length ",NParam," and contain no NA",sep="")); return(NULL); } + if(inherits(InputsModel,"InputsModel")==FALSE){ stop("InputsModel must be of class 'InputsModel'") } + if(inherits(InputsModel,"daily" )==FALSE){ stop("InputsModel must be of class 'daily' ") } + if(inherits(InputsModel,"GR" )==FALSE){ stop("InputsModel must be of class 'GR' ") } + if(inherits(InputsModel,"CemaNeige" )==FALSE){ stop("InputsModel must be of class 'CemaNeige' ") } + if(inherits(RunOptions,"RunOptions" )==FALSE){ stop("RunOptions must be of class 'RunOptions' ") } + if(inherits(RunOptions,"GR" )==FALSE){ stop("RunOptions must be of class 'GR' ") } + if(inherits(RunOptions,"CemaNeige" )==FALSE){ stop("RunOptions must be of class 'CemaNeige' ") } + 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_X1X3X6_threshold <- 1e-2 diff --git a/R/RunModel_GR1A.R b/R/RunModel_GR1A.R index 882cacd1..4c0eaee3 100644 --- a/R/RunModel_GR1A.R +++ b/R/RunModel_GR1A.R @@ -4,13 +4,13 @@ RunModel_GR1A <- function(InputsModel,RunOptions,Param){ FortranOutputs <- .FortranOutputs(GR = "GR1A")$GR ##Arguments_check - if(inherits(InputsModel,"InputsModel")==FALSE){ stop("InputsModel must be of class 'InputsModel'"); return(NULL); } - if(inherits(InputsModel,"yearly" )==FALSE){ stop("InputsModel must be of class 'yearly' "); return(NULL); } - if(inherits(InputsModel,"GR" )==FALSE){ stop("InputsModel must be of class 'GR' "); return(NULL); } - if(inherits(RunOptions,"RunOptions" )==FALSE){ stop("RunOptions must be of class 'RunOptions' "); return(NULL); } - if(inherits(RunOptions,"GR" )==FALSE){ stop("RunOptions must be of class 'GR' "); return(NULL); } - if(!is.vector(Param) | !is.numeric(Param)){ stop("Param must be a numeric vector"); return(NULL); } - if(sum(!is.na(Param))!=NParam){ stop(paste("Param must be a vector of length ",NParam," and contain no NA",sep="")); return(NULL); } + if(inherits(InputsModel,"InputsModel")==FALSE){ stop("InputsModel must be of class 'InputsModel'") } + if(inherits(InputsModel,"yearly" )==FALSE){ stop("InputsModel must be of class 'yearly' ") } + if(inherits(InputsModel,"GR" )==FALSE){ stop("InputsModel must be of class 'GR' ") } + if(inherits(RunOptions,"RunOptions" )==FALSE){ stop("RunOptions must be of class 'RunOptions' ") } + 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); ##Input_data_preparation diff --git a/R/RunModel_GR2M.R b/R/RunModel_GR2M.R index fec37264..ac37b14a 100644 --- a/R/RunModel_GR2M.R +++ b/R/RunModel_GR2M.R @@ -4,13 +4,13 @@ RunModel_GR2M <- function(InputsModel,RunOptions,Param){ FortranOutputs <- .FortranOutputs(GR = "GR2M")$GR ##Arguments_check - if(inherits(InputsModel,"InputsModel")==FALSE){ stop("InputsModel must be of class 'InputsModel'"); return(NULL); } - if(inherits(InputsModel,"monthly" )==FALSE){ stop("InputsModel must be of class 'monthly' "); return(NULL); } - if(inherits(InputsModel,"GR" )==FALSE){ stop("InputsModel must be of class 'GR' "); return(NULL); } - if(inherits(RunOptions,"RunOptions" )==FALSE){ stop("RunOptions must be of class 'RunOptions' "); return(NULL); } - if(inherits(RunOptions,"GR" )==FALSE){ stop("RunOptions must be of class 'GR' "); return(NULL); } - if(!is.vector(Param) | !is.numeric(Param)){ stop("Param must be a numeric vector"); return(NULL); } - if(sum(!is.na(Param))!=NParam){ stop(paste("Param must be a vector of length ",NParam," and contain no NA",sep="")); return(NULL); } + if(inherits(InputsModel,"InputsModel")==FALSE){ stop("InputsModel must be of class 'InputsModel'") } + if(inherits(InputsModel,"monthly" )==FALSE){ stop("InputsModel must be of class 'monthly' ") } + if(inherits(InputsModel,"GR" )==FALSE){ stop("InputsModel must be of class 'GR' ") } + if(inherits(RunOptions,"RunOptions" )==FALSE){ stop("RunOptions must be of class 'RunOptions' ") } + 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_X1X2_threshold <- 1e-2 diff --git a/R/RunModel_GR4H.R b/R/RunModel_GR4H.R index c23ecb51..30d2532b 100644 --- a/R/RunModel_GR4H.R +++ b/R/RunModel_GR4H.R @@ -4,13 +4,13 @@ RunModel_GR4H <- function(InputsModel,RunOptions,Param){ FortranOutputs <- .FortranOutputs(GR = "GR4H")$GR ##Arguments_check - if(inherits(InputsModel,"InputsModel")==FALSE){ stop("InputsModel must be of class 'InputsModel'"); return(NULL); } - if(inherits(InputsModel,"hourly" )==FALSE){ stop("InputsModel must be of class 'hourly' "); return(NULL); } - if(inherits(InputsModel,"GR" )==FALSE){ stop("InputsModel must be of class 'GR' "); return(NULL); } - if(inherits(RunOptions,"RunOptions" )==FALSE){ stop("RunOptions must be of class 'RunOptions' "); return(NULL); } - if(inherits(RunOptions,"GR" )==FALSE){ stop("RunOptions must be of class 'GR' "); return(NULL); } - if(!is.vector(Param) | !is.numeric(Param)){ stop("Param must be a numeric vector"); return(NULL); } - if(sum(!is.na(Param))!=NParam){ stop(paste("Param must be a vector of length ",NParam," and contain no NA",sep="")); return(NULL); } + if(inherits(InputsModel,"InputsModel")==FALSE){ stop("InputsModel must be of class 'InputsModel'") } + if(inherits(InputsModel,"hourly" )==FALSE){ stop("InputsModel must be of class 'hourly' ") } + if(inherits(InputsModel,"GR" )==FALSE){ stop("InputsModel must be of class 'GR' ") } + if(inherits(RunOptions,"RunOptions" )==FALSE){ stop("RunOptions must be of class 'RunOptions' ") } + 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_X1X3_threshold <- 1e-2 diff --git a/R/RunModel_GR4J.R b/R/RunModel_GR4J.R index 0dc9cce3..622d4edb 100644 --- a/R/RunModel_GR4J.R +++ b/R/RunModel_GR4J.R @@ -4,13 +4,13 @@ RunModel_GR4J <- function(InputsModel,RunOptions,Param){ FortranOutputs <- .FortranOutputs(GR = "GR4J")$GR ##Arguments_check - if(inherits(InputsModel,"InputsModel")==FALSE){ stop("InputsModel must be of class 'InputsModel'"); return(NULL); } - if(inherits(InputsModel,"daily" )==FALSE){ stop("InputsModel must be of class 'daily' "); return(NULL); } - if(inherits(InputsModel,"GR" )==FALSE){ stop("InputsModel must be of class 'GR' "); return(NULL); } - if(inherits(RunOptions,"RunOptions" )==FALSE){ stop("RunOptions must be of class 'RunOptions' "); return(NULL); } - if(inherits(RunOptions,"GR" )==FALSE){ stop("RunOptions must be of class 'GR' "); return(NULL); } - if(!is.vector(Param) | !is.numeric(Param)){ stop("Param must be a numeric vector"); return(NULL); } - if(sum(!is.na(Param))!=NParam){ stop(paste("Param must be a vector of length ",NParam," and contain no NA",sep="")); return(NULL); } + if(inherits(InputsModel,"InputsModel")==FALSE){ stop("InputsModel must be of class 'InputsModel'") } + if(inherits(InputsModel,"daily" )==FALSE){ stop("InputsModel must be of class 'daily' ") } + if(inherits(InputsModel,"GR" )==FALSE){ stop("InputsModel must be of class 'GR' ") } + if(inherits(RunOptions,"RunOptions" )==FALSE){ stop("RunOptions must be of class 'RunOptions' ") } + 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_X1X3_threshold <- 1e-2 diff --git a/R/RunModel_GR5J.R b/R/RunModel_GR5J.R index f71a4046..7d253668 100644 --- a/R/RunModel_GR5J.R +++ b/R/RunModel_GR5J.R @@ -4,13 +4,13 @@ RunModel_GR5J <- function(InputsModel,RunOptions,Param){ FortranOutputs <- .FortranOutputs(GR = "GR5J")$GR ##Arguments_check - if(inherits(InputsModel,"InputsModel")==FALSE){ stop("InputsModel must be of class 'InputsModel'"); return(NULL); } - if(inherits(InputsModel,"daily" )==FALSE){ stop("InputsModel must be of class 'daily' "); return(NULL); } - if(inherits(InputsModel,"GR" )==FALSE){ stop("InputsModel must be of class 'GR' "); return(NULL); } - if(inherits(RunOptions,"RunOptions" )==FALSE){ stop("RunOptions must be of class 'RunOptions' "); return(NULL); } - if(inherits(RunOptions,"GR" )==FALSE){ stop("RunOptions must be of class 'GR' "); return(NULL); } - if(!is.vector(Param) | !is.numeric(Param)){ stop("Param must be a numeric vector"); return(NULL); } - if(sum(!is.na(Param))!=NParam){ stop(paste("Param must be a vector of length ",NParam," and contain no NA",sep="")); return(NULL); } + if(inherits(InputsModel,"InputsModel")==FALSE){ stop("InputsModel must be of class 'InputsModel'") } + if(inherits(InputsModel,"daily" )==FALSE){ stop("InputsModel must be of class 'daily' ") } + if(inherits(InputsModel,"GR" )==FALSE){ stop("InputsModel must be of class 'GR' ") } + if(inherits(RunOptions,"RunOptions" )==FALSE){ stop("RunOptions must be of class 'RunOptions' ") } + 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_X1X3_threshold <- 1e-2 diff --git a/R/RunModel_GR6J.R b/R/RunModel_GR6J.R index 5a36a496..64f69add 100644 --- a/R/RunModel_GR6J.R +++ b/R/RunModel_GR6J.R @@ -4,13 +4,13 @@ RunModel_GR6J <- function(InputsModel,RunOptions,Param){ FortranOutputs <- .FortranOutputs(GR = "GR6J")$GR ##Arguments_check - if(inherits(InputsModel,"InputsModel")==FALSE){ stop("InputsModel must be of class 'InputsModel'"); return(NULL); } - if(inherits(InputsModel,"daily" )==FALSE){ stop("InputsModel must be of class 'daily' "); return(NULL); } - if(inherits(InputsModel,"GR" )==FALSE){ stop("InputsModel must be of class 'GR' "); return(NULL); } - if(inherits(RunOptions,"RunOptions" )==FALSE){ stop("RunOptions must be of class 'RunOptions' "); return(NULL); } - if(inherits(RunOptions,"GR" )==FALSE){ stop("RunOptions must be of class 'GR' "); return(NULL); } - if(!is.vector(Param) | !is.numeric(Param)){ stop("Param must be a numeric vector"); return(NULL); } - if(sum(!is.na(Param))!=NParam){ stop(paste("Param must be a vector of length ",NParam," and contain no NA",sep="")); return(NULL); } + if(inherits(InputsModel,"InputsModel")==FALSE){ stop("InputsModel must be of class 'InputsModel'") } + if(inherits(InputsModel,"daily" )==FALSE){ stop("InputsModel must be of class 'daily' ") } + if(inherits(InputsModel,"GR" )==FALSE){ stop("InputsModel must be of class 'GR' ") } + if(inherits(RunOptions,"RunOptions" )==FALSE){ stop("RunOptions must be of class 'RunOptions' ") } + 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_X1X3X6_threshold <- 1e-2 diff --git a/R/SeriesAggreg.R b/R/SeriesAggreg.R index bf70767d..5ee8d997 100644 --- a/R/SeriesAggreg.R +++ b/R/SeriesAggreg.R @@ -10,20 +10,16 @@ SeriesAggreg <- function(TabSeries, ##check_TabSeries if (is.null(TabSeries) ) { stop("TabSeries must be a dataframe containing the dates and data to be converted") - return(NULL) } if (!is.data.frame(TabSeries)) { stop("TabSeries must be a dataframe containing the dates and data to be converted") - return(NULL) } if (ncol(TabSeries) < 2) { stop("TabSeries must contain at least two columns (including the coulmn of dates") - return(NULL) } ##check_TimeFormat if (!any(class(TabSeries[, 1]) %in% "POSIXt")) { stop("TabSeries first column must be a vector of class POSIXlt or POSIXct") - return(NULL) } if (any(class(TabSeries[, 1]) %in% "POSIXlt")) { TabSeries[, 1] <- as.POSIXct(TabSeries[, 1]) @@ -31,96 +27,73 @@ SeriesAggreg <- function(TabSeries, for (iCol in 2:ncol(TabSeries)) { if (!is.numeric(TabSeries[,iCol])) { stop("TabSeries columns (other than the first one) be of numeric class") - return(NULL) } } if (is.null(TimeFormat)) { stop("TimeFormat must be 'hourly', 'daily', 'monthly' or 'yearly'") - return(NULL) } if (!is.vector(TimeFormat)) { stop("TimeFormat must be 'hourly', 'daily', 'monthly' or 'yearly'") - return(NULL) } if (!is.character(TimeFormat)) { stop("TimeFormat must be 'hourly', 'daily', 'monthly' or 'yearly'") - return(NULL) } if (length(TimeFormat) != 1) { stop("TimeFormat must be 'hourly', 'daily', 'monthly' or 'yearly'") - return(NULL) } if (! TimeFormat %in% c("hourly", "daily", "monthly", "yearly")) { stop("TimeFormat must be 'hourly', 'daily', 'monthly' or 'yearly'") - return(NULL) - } ##check_NewTimeFormat if (is.null(NewTimeFormat)) { stop("NewTimeFormat must be 'hourly', 'daily', 'monthly' or 'yearly'") - return(NULL) } if (!is.vector(NewTimeFormat)) { stop("NewTimeFormat must be 'hourly', 'daily', 'monthly' or 'yearly'") - return(NULL) } if (!is.character(NewTimeFormat)) { stop("NewTimeFormat must be 'hourly', 'daily', 'monthly' or 'yearly'") - return(NULL) } if (length(NewTimeFormat) != 1) { stop("NewTimeFormat must be 'hourly', 'daily', 'monthly' or 'yearly'") - return(NULL) } if (! NewTimeFormat %in% c("hourly", "daily", "monthly", "yearly")) { stop("NewTimeFormat must be 'hourly', 'daily', 'monthly' or 'yearly'") - return(NULL) } ##check_ConvertFun if (is.null(ConvertFun)) { stop("ConvertFun must be a vector of character") - return(NULL) } if (!is.vector(ConvertFun)) { stop("ConvertFun must be a vector of character") - return(NULL) } if (!is.character(ConvertFun)) { stop("ConvertFun must be a vector of character") - return(NULL) } if (length(ConvertFun) != (ncol(TabSeries) - 1)) { stop( paste("ConvertFun must be of length", ncol(TabSeries) - 1, "(length=ncol(TabSeries)-1)") ) - return(NULL) } if (sum(ConvertFun %in% c("sum", "mean") == FALSE) != 0) { stop("ConvertFun elements must be either 'sum' or 'mean'") - return(NULL) } ##check_YearFirstMonth if (is.null(YearFirstMonth)) { stop("YearFirstMonth must be an integer between 1 and 12") - return(NULL) } if (!is.vector(YearFirstMonth)) { stop("YearFirstMonth must be an integer between 1 and 12") - return(NULL) } if (!is.numeric(YearFirstMonth)) { stop("YearFirstMonth must be an integer between 1 and 12") - return(NULL) } YearFirstMonth <- as.integer(YearFirstMonth) if (length(YearFirstMonth) != 1) { stop("YearFirstMonth must be only one integer between 1 and 12") - return(NULL) - } if (YearFirstMonth %in% (1:12) == FALSE) { stop("YearFirstMonth must be only one integer between 1 and 12") - return(NULL) } ##check_DatesR_integrity if (TimeFormat == "hourly") { @@ -138,14 +111,12 @@ SeriesAggreg <- function(TabSeries, TmpDatesR <- seq(from = TabSeries[1, 1], to = tail(TabSeries[, 1], 1), by = by) if (!identical(TabSeries[, 1], TmpDatesR)) { stop("Some dates might not be ordered or are missing in TabSeries") - return(NULL) } ##check_conversion_direction if ((TimeFormat == "daily" & NewTimeFormat %in% c("hourly") ) | (TimeFormat == "monthly" & NewTimeFormat %in% c("hourly","daily") ) | (TimeFormat == "yearly" & NewTimeFormat %in% c("hourly","daily","monthly"))) { stop("Only time aggregation can be performed") - return(NULL) } ##check_if_conversion_not_needed if ((TimeFormat == "hourly" & NewTimeFormat == "hourly" ) | diff --git a/R/TransfoParam_GR1A.R b/R/TransfoParam_GR1A.R index cb3b197c..3c3e85af 100644 --- a/R/TransfoParam_GR1A.R +++ b/R/TransfoParam_GR1A.R @@ -9,7 +9,6 @@ TransfoParam_GR1A <- function(ParamIn, Direction) { if (ncol(ParamIn) != NParam) { stop(paste("the GR1A model requires ", NParam, " parameters", sep = "")) - return(NULL) } if (Direction == "TR") { diff --git a/R/TransfoParam_GR2M.R b/R/TransfoParam_GR2M.R index a875c44d..2e093192 100644 --- a/R/TransfoParam_GR2M.R +++ b/R/TransfoParam_GR2M.R @@ -8,7 +8,6 @@ TransfoParam_GR2M <- function(ParamIn, Direction) { } if (ncol(ParamIn) != NParam) { stop(paste("the GR2M model requires ", NParam, " parameters", sep = "")) - return(NULL) } if (Direction == "TR") { diff --git a/R/TransfoParam_GR4H.R b/R/TransfoParam_GR4H.R index f2dbdf37..4a63a787 100644 --- a/R/TransfoParam_GR4H.R +++ b/R/TransfoParam_GR4H.R @@ -3,7 +3,7 @@ TransfoParam_GR4H <- function(ParamIn,Direction){ NParam <- 4; Bool <- is.matrix(ParamIn); if(Bool==FALSE){ ParamIn <- rbind(ParamIn); } - if(ncol(ParamIn)!=NParam){ stop(paste("the GR4H model requires ",NParam," parameters",sep="")); return(NULL); } + if(ncol(ParamIn)!=NParam){ stop(paste("the GR4H model requires ",NParam," parameters",sep="")) } if(Direction=="TR"){ ParamOut <- ParamIn; diff --git a/R/TransfoParam_GR4J.R b/R/TransfoParam_GR4J.R index 6d59afef..c10e2815 100644 --- a/R/TransfoParam_GR4J.R +++ b/R/TransfoParam_GR4J.R @@ -3,7 +3,7 @@ TransfoParam_GR4J <- function(ParamIn,Direction){ NParam <- 4; Bool <- is.matrix(ParamIn); if(Bool==FALSE){ ParamIn <- rbind(ParamIn); } - if(ncol(ParamIn)!=NParam){ stop(paste("the GR4J model requires ",NParam," parameters",sep="")); return(NULL); } + if(ncol(ParamIn)!=NParam){ stop(paste("the GR4J model requires ",NParam," parameters",sep="")) } if(Direction=="TR"){ ParamOut <- ParamIn; diff --git a/R/TransfoParam_GR5J.R b/R/TransfoParam_GR5J.R index b006d86f..99f5a30a 100644 --- a/R/TransfoParam_GR5J.R +++ b/R/TransfoParam_GR5J.R @@ -3,7 +3,7 @@ TransfoParam_GR5J <- function(ParamIn,Direction){ NParam <- 5; Bool <- is.matrix(ParamIn); if(Bool==FALSE){ ParamIn <- rbind(ParamIn); } - if(ncol(ParamIn)!=NParam){ stop(paste("the GR5J model requires ",NParam," parameters",sep="")); return(NULL); } + if(ncol(ParamIn)!=NParam){ stop(paste("the GR5J model requires ",NParam," parameters",sep="")) } if(Direction=="TR"){ ParamOut <- ParamIn; diff --git a/R/TransfoParam_GR6J.R b/R/TransfoParam_GR6J.R index 9cdda8ee..de3b8e08 100644 --- a/R/TransfoParam_GR6J.R +++ b/R/TransfoParam_GR6J.R @@ -3,7 +3,7 @@ TransfoParam_GR6J <- function(ParamIn,Direction){ NParam <- 6; Bool <- is.matrix(ParamIn); if(Bool==FALSE){ ParamIn <- rbind(ParamIn); } - if(ncol(ParamIn)!=NParam){ stop(paste("the GR6J model requires ",NParam," parameters",sep="")); return(NULL); } + if(ncol(ParamIn)!=NParam){ stop(paste("the GR6J model requires ",NParam," parameters",sep="")) } if(Direction=="TR"){ ParamOut <- ParamIn; diff --git a/R/plot.OutputsModel.R b/R/plot.OutputsModel.R index 9c369272..3b6fedf9 100644 --- a/R/plot.OutputsModel.R +++ b/R/plot.OutputsModel.R @@ -5,7 +5,6 @@ plot.OutputsModel <- function(x, Qobs = NULL, IndPeriod_Plot = NULL, BasinArea = if (!inherits(OutputsModel, "GR") & !inherits(OutputsModel, "CemaNeige")) { stop(paste("OutputsModel not in the correct format for default plotting", sep = "")) - return(NULL) } @@ -29,16 +28,14 @@ plot.OutputsModel <- function(x, Qobs = NULL, IndPeriod_Plot = NULL, BasinArea = if ("CemaNeigeLayers" %in% names(OutputsModel)) { if ("Psol" %in% names(OutputsModel$CemaNeigeLayers[[1]])) { BOOL_Psol <- TRUE; } } - if ( is.null( which)) { stop("which must be a vector of character"); return(NULL); } - if (!is.vector( which)) { stop("which must be a vector of character"); return(NULL); } - if (!is.character(which)) { stop("which must be a vector of character"); return(NULL); } + if ( is.null( which)) { stop("which must be a vector of character") } + if (!is.vector( which)) { stop("which must be a vector of character") } + if (!is.character(which)) { stop("which must be a vector of character") } if (any(!which %in% c("all", "Precip", 'Temp', "SnowPack", "Flows", "Regime", "CumFreq", "CorQQ"))) { stop("Incorrect element found in argument which:\nit can only contain 'all', 'Precip', 'Temp', 'SnowPack', 'Flows', 'Regime', 'CumFreq' or 'CorQQ'") - return(NULL) } if (all(which %in% c("Temp", "SnowPack")) & !inherits(OutputsModel, "CemaNeige")) { stop("Incorrect element found in argument which:\nwithout CemaNeige it can only contain 'all', 'Precip', 'Flows', 'Regime', 'CumFreq' or 'CorQQ'") - return(NULL) } if (length(unique(which %in% c("Temp", "SnowPack"))) == 2 & !inherits(OutputsModel, "CemaNeige")) { warning("Incorrect element found in argument which:\nit can only contain 'all', 'Precip', 'Flows', 'Regime', 'CumFreq' or 'CorQQ'\nwithout CemaNeige 'Temp' and 'SnowPack' are not available") @@ -50,9 +47,9 @@ plot.OutputsModel <- function(x, Qobs = NULL, IndPeriod_Plot = NULL, BasinArea = if (!BOOL_Dates) { - stop(paste("OutputsModel must contain at least DatesR to allow plotting", sep = "")); return(NULL); } + stop(paste("OutputsModel must contain at least DatesR to allow plotting", sep = "")) } if (inherits(OutputsModel, "GR") & !BOOL_Qsim) { - stop(paste("OutputsModel must contain at least Qsim to allow plotting", sep = "")); return(NULL); } + stop(paste("OutputsModel must contain at least Qsim to allow plotting", sep = "")) } if (BOOL_Dates) { MyRollMean1 <- function(x, n) { @@ -68,7 +65,7 @@ plot.OutputsModel <- function(x, Qobs = NULL, IndPeriod_Plot = NULL, BasinArea = if (inherits(OutputsModel, "daily" ) & TimeStep %in% ( 24*60*60)) { BOOL_TS <- TRUE; NameTS <- "day" ; plotunit <- "[mm/d]"; formatAxis <- "%m/%Y"; } if (inherits(OutputsModel, "monthly") & TimeStep %in% (c(28, 29, 30, 31)*24*60*60)) { BOOL_TS <- TRUE; NameTS <- "month"; plotunit <- "[mm/month]"; formatAxis <- "%m/%Y"; } if (inherits(OutputsModel, "yearly" ) & TimeStep %in% ( c(365, 366)*24*60*60)) { BOOL_TS <- TRUE; NameTS <- "year" ; plotunit <- "[mm/y]"; formatAxis <- "%Y" ; } - if (!BOOL_TS) { stop(paste("the time step of the model inputs could not be found", sep = "")); return(NULL); } + if (!BOOL_TS) { stop(paste("the time step of the model inputs could not be found", sep = "")) } } if (length(IndPeriod_Plot) == 0) { IndPeriod_Plot <- 1:length(OutputsModel$DatesR); } if (inherits(OutputsModel, "CemaNeige")) { NLayers <- length(OutputsModel$CemaNeigeLayers); } @@ -391,7 +388,7 @@ plot.OutputsModel <- function(x, Qobs = NULL, IndPeriod_Plot = NULL, BasinArea = MyRollMean3(DataDailyInterAn$Qobs , NDaysWindow), MyRollMean3(DataDailyInterAn$Qsim, NDaysWindow))); colnames(DataDailyInterAn) <- c("Dates", "Precip", "Psol", "Qobs", "Qsim"); ## Scale_conversion_to_make_them_become_a_monthly_regime - if (plotunitregime != "[mm/month]") { stop(paste("incorrect unit for regime plot", sep = "")); return(NULL); } + if (plotunitregime != "[mm/month]") { stop(paste("incorrect unit for regime plot", sep = "")) } DataDailyInterAn <- as.data.frame(cbind(DataDailyInterAn[1], DataDailyInterAn[2:5]*30)); } ## Plot_preparation -- GitLab