Commit 2f7c5399 authored by Delaigue Olivier's avatar Delaigue Olivier
Browse files

v1.2.13.2 UPDATE: CreateRunOptions now check the compatibility between...

v1.2.13.2 UPDATE: CreateRunOptions now check the compatibility between FUN_MOD, IniStates and IsHyst arguments
parent ed6680fe
Package: airGR
Type: Package
Title: Suite of GR Hydrological Models for Precipitation-Runoff Modelling
Version: 1.2.13.1
Version: 1.2.13.2
Date: 2019-04-01
Authors@R: c(
person("Laurent", "Coron", role = c("aut", "trl"), comment = c(ORCID = "0000-0002-1503-6204")),
......
......@@ -13,7 +13,7 @@ output:
### 1.2.13.1 Release Notes (2019-04-01)
### 1.2.13.2 Release Notes (2019-04-01)
......
......@@ -139,10 +139,10 @@ CreateRunOptions <- function(FUN_MOD, InputsModel, IndPeriod_WarmUp = NULL, IndP
stop("'IndPeriod_WarmUp' should be of type integer")
}
if (identical(IndPeriod_WarmUp, as.integer(0)) & verbose) {
message(paste0(WTxt, ". No warm up period is used"))
message(paste0(WTxt, " No warm up period is used"))
}
if ((IndPeriod_Run[1] - 1) != tail(IndPeriod_WarmUp, 1) & !identical(IndPeriod_WarmUp, as.integer(0))) {
WTxt <- paste0(WTxt, ". Model warm up period is not directly before the model run period")
WTxt <- paste0(WTxt, " Model warm up period is not directly before the model run period")
}
}
if (!is.null(WTxt) & warnings) {
......@@ -209,32 +209,49 @@ CreateRunOptions <- function(FUN_MOD, InputsModel, IndPeriod_WarmUp = NULL, IndP
if (!is.null(IniStates)) {
if (!inherits(IniStates, "IniStates")) {
stop("'IniStates' must be an object of class 'IniStates'\n")
stop("'IniStates' must be an object of class 'IniStates'")
}
if (sum(ObjectClass %in% class(IniStates)) < 2) {
stop(paste0("non convenient 'IniStates' for this 'FUN_MOD'\n"))
stop(paste0("non convenient 'IniStates' for the chosen 'FUN_MOD'"))
}
if (identical(FUN_MOD, RunModel_GR1A) & !is.null(IniStates)) { ## GR1A
stop(paste0("'IniStates' is not available for this 'FUN_MOD'\n"))
stop(paste0("'IniStates' is not available for the chosen 'FUN_MOD'"))
}
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"))
stop(paste0("non convenient 'IniStates' for the chosen 'FUN_MOD'.' In 'IniStates', 'UH1' has to be a vector of NA for GR5J"))
}
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'"))
stop(paste0("non convenient 'IniStates' for the chosen 'FUN_MOD'.' GR6J needs an exponential store value in 'IniStates'"))
}
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'"))
stop(paste0("non convenient 'IniStates' for the chosen 'FUN_MOD'.' No exponential store value needed in 'IniStates'"))
}
# if (length(na.omit(unlist(IniStates))) != NState) {
# stop(paste0("the length of IniStates must be ", NState, " for the chosen FUN_MOD"))
# }
if ((!"CemaNeige" %in% ObjectClass & inherits(IniStates, "CemaNeige")) |
( "CemaNeige" %in% ObjectClass & !inherits(IniStates, "CemaNeige"))) {
stop("'FUN_MOD' and 'IniStates' must be both of class 'CemaNeige'")
}
if (!"CemaNeige" %in% ObjectClass & "hysteresis" %in% ObjectClass) {
stop("'IsHyst' cannot be TRUE for the chosen 'FUN_MOD'")
}
if (( "hysteresis" %in% ObjectClass & !inherits(IniStates, "hysteresis")) |
(!"hysteresis" %in% ObjectClass & inherits(IniStates, "hysteresis"))) {
stop("'IsHyst' and 'IniStates' are not consistent on the use of the hysteresis")
}
if (!"CemaNeige" %in% ObjectClass & any(is.na(IniStates$CemaNeigeLayers$G ))) {
IniStates$CemaNeigeLayers$G <- NULL
IniStates$CemaNeigeLayers$G <- NULL
}
if (!"CemaNeige" %in% ObjectClass & any(is.na(IniStates$CemaNeigeLayers$eTG))) {
IniStates$CemaNeigeLayers$eTG <- NULL
}
if (!"CemaNeige" %in% ObjectClass & any(is.na(IniStates$CemaNeigeLayers$Gthr))) {
IniStates$CemaNeigeLayers$Gthr <- NULL
}
if (!"CemaNeige" %in% ObjectClass & any(is.na(IniStates$CemaNeigeLayers$Glocmax))) {
IniStates$CemaNeigeLayers$Glocmax <- NULL
}
IniStates$Store$Rest <- rep(NA, 4)
IniStates <- unlist(IniStates)
IniStates[is.na(IniStates)] <- 0
......
Markdown is supported
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