Commit 637aef7e authored by Delaigue Olivier's avatar Delaigue Olivier
Browse files

CHECKOUT 93ed9b27 v1.1.2.40 CLEAN: add check...

CHECKOUT 93ed9b27 v1.1.2.40 CLEAN: add check in TransfoParam_CemaNeige
Showing with 19 additions and 11 deletions
+19 -11
TransfoParam_CemaNeige <- function(ParamIn, Direction) { TransfoParam_CemaNeige <- function(ParamIn, Direction) {
NParam <- 2
Bool <- is.matrix(ParamIn) NParam <- 2L
if (Bool == FALSE) {
ParamIn <- rbind(ParamIn) ## 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) { if (ncol(ParamIn) != NParam) {
stop(paste( "the CemaNeige module requires ", NParam, " parameters \n", sep = "" )) stop(sprintf( "the CemaNeige module requires %i parameters", NParam))
return(NULL)
} }
if (Direction == "TR") { if (Direction == "TR") {
ParamOut <- ParamIn ParamOut <- ParamIn
ParamOut[, 1] <- (ParamIn[, 1] + 9.99) / 19.98 ### CemaNeige X1 (weighting coefficient for snow pack thermal state) 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) ParamOut[, 2] <- exp(ParamIn[, 2]) / 200 ### CemaNeige X2 (degree-day melt coefficient)
} }
if (Direction == "RT") { if (Direction == "RT") {
ParamOut <- ParamIn ParamOut <- ParamIn
ParamOut[, 1] <- ParamIn[, 1] * 19.98 - 9.99 ### CemaNeige X1 (weighting coefficient for snow pack thermal state) 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) ParamOut[, 2] <- log(ParamIn[, 2] * 200) ### CemaNeige X2 (degree-day melt coefficient)
} }
if (Bool == FALSE) { if (Bool) {
ParamOut <- ParamOut[1, ] ParamOut <- as.vector(ParamOut)
} }
return(ParamOut) return(ParamOut)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment