diff --git a/DESCRIPTION b/DESCRIPTION index 10e8fb115712cbdf7be46416cd233195c6b50c46..27c5f0b1c5c5699d1c458aadfa350d70d6676d02 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: airGR Type: Package Title: Suite of GR Hydrological Models for Precipitation-Runoff Modelling -Version: 1.1.2.39 -Date: 2019-01-29 +Version: 1.1.2.40 +Date: 2019-01-30 Authors@R: c( person("Laurent", "Coron", role = c("aut", "trl"), comment = c(ORCID = "0000-0002-1503-6204")), person("Charles", "Perrin", role = c("aut", "ths"), comment = c(ORCID = "0000-0001-8552-1881")), diff --git a/NEWS.rmd b/NEWS.rmd index 65a9529cbdaabd08d5f9f476a98c17ae9adab69c..c0cd39a88bca3531bfc805679d025b5387c04641 100644 --- a/NEWS.rmd +++ b/NEWS.rmd @@ -13,7 +13,7 @@ output: -### 1.1.2.39 Release Notes (2019-01-29) +### 1.1.2.40 Release Notes (2019-01-30) diff --git a/R/TransfoParam_CemaNeige.R b/R/TransfoParam_CemaNeige.R index d49d600d1c3b47024091dd635021a2ddec895da8..4754595ea2caa3db2259b76633bd4ec2c5f344a4 100644 --- a/R/TransfoParam_CemaNeige.R +++ b/R/TransfoParam_CemaNeige.R @@ -1,31 +1,39 @@ TransfoParam_CemaNeige <- function(ParamIn, Direction) { - NParam <- 2 - Bool <- is.matrix(ParamIn) - - if (Bool == FALSE) { - ParamIn <- rbind(ParamIn) + + NParam <- 2L + + + ## check_arguments + Bool <- is.vector(ParamIn) + if (Bool) { + ParamIn <- matrix(ParamIn, nrow = 1) + warning("'ParamIn' automatically convert to 'matrix'") + } + if (!inherits(ParamIn, "matrix")) { + stop("'ParamIn' must be of class 'matrix'") + } + if (!inherits(Direction, "character") | length(Direction) != 1 | any(!Direction %in% c("RT", "TR"))) { + stop("'Direction' must be a character vector of length 1 equal to 'RT' or 'TR'") } - if (ncol(ParamIn) != NParam) { - stop(paste( "the CemaNeige module requires ", NParam, " parameters \n", sep = "" )) - return(NULL) + stop(sprintf( "the CemaNeige module requires %i parameters", NParam)) } + if (Direction == "TR") { ParamOut <- ParamIn ParamOut[, 1] <- (ParamIn[, 1] + 9.99) / 19.98 ### CemaNeige X1 (weighting coefficient for snow pack thermal state) ParamOut[, 2] <- exp(ParamIn[, 2]) / 200 ### CemaNeige X2 (degree-day melt coefficient) } - if (Direction == "RT") { ParamOut <- ParamIn ParamOut[, 1] <- ParamIn[, 1] * 19.98 - 9.99 ### CemaNeige X1 (weighting coefficient for snow pack thermal state) ParamOut[, 2] <- log(ParamIn[, 2] * 200) ### CemaNeige X2 (degree-day melt coefficient) } - if (Bool == FALSE) { - ParamOut <- ParamOut[1, ] + if (Bool) { + ParamOut <- as.vector(ParamOut) } return(ParamOut)