Commit 30975c15 authored by Delaigue Olivier's avatar Delaigue Olivier
Browse files

style: indent code in RunModel_Lag

Refs #103
parent 32a256ff
Pipeline #21625 canceled with stages
......@@ -18,19 +18,13 @@ RunModel_Lag <- function(InputsModel, RunOptions, Param) {
stop(paste("'Param' must be a vector of length", NParam, "and contain no NA"))
}
if (is.null(InputsModel$OutputsModel)) {
stop(
"'InputsModel' should contain an 'OutputsModel' key containing the output of the runoff of the downstream subcatchment"
)
stop("'InputsModel' should contain an 'OutputsModel' key containing the output of the runoff of the downstream subcatchment")
}
if (is.null(InputsModel$OutputsModel$Qsim)) {
stop(
"'InputsModel$OutputsModel' should contain a key 'Qsim' containing the output of the runoff of the downstream subcatchment"
)
stop("'InputsModel$OutputsModel' should contain a key 'Qsim' containing the output of the runoff of the downstream subcatchment")
}
if (sum(!is.na(InputsModel$OutputsModel$Qsim)) != length(RunOptions$IndPeriod_Run)) {
stop(
"'InputsModel$OutputsModel$Qim' should have the same lenght as 'RunOptions$IndPeriod_Run' and contain no NA"
)
stop("'InputsModel$OutputsModel$Qim' should have the same lenght as 'RunOptions$IndPeriod_Run' and contain no NA")
}
OutputsModel <- InputsModel$OutputsModel
......@@ -75,7 +69,7 @@ RunModel_Lag <- function(InputsModel, RunOptions, Param) {
rep(0, floor(PT[x] + 1))
})
}
#message("Initstates: ",paste(IniStates, collapse = ", "))
# message("Initstates: ", paste(IniStates, collapse = ", "))
for (upstream_basin in seq_len(NbUpBasins)) {
Qupstream <- c(IniStates[[upstream_basin]],
......@@ -84,9 +78,8 @@ RunModel_Lag <- function(InputsModel, RunOptions, Param) {
# Upstream flow with area needs to be converted to m3 by time step
Qupstream <- Qupstream * InputsModel$BasinAreas[upstream_basin] * 1e3
}
#message("Qupstream[", upstream_basin, "]: ", paste(Qupstream, collapse = ", "))
OutputsModel$Qsim <-
OutputsModel$Qsim +
# message("Qupstream[", upstream_basin, "]: ", paste(Qupstream, collapse = ", "))
OutputsModel$Qsim <- OutputsModel$Qsim +
Qupstream[2:(1 + LengthTs)] * HUTRANS[1, upstream_basin] +
Qupstream[1:LengthTs] * HUTRANS[2, upstream_basin]
}
......@@ -97,14 +90,14 @@ RunModel_Lag <- function(InputsModel, RunOptions, Param) {
}
# Convert back Qsim to mm
OutputsModel$Qsim <- OutputsModel$Qsim / sum(InputsModel$BasinAreas, na.rm = TRUE) / 1e3
#message("Qsim: ",paste(OutputsModel$Qsim, collapse = ", "))
# message("Qsim: ", paste(OutputsModel$Qsim, collapse = ", "))
if ("StateEnd" %in% RunOptions$Outputs_Sim) {
OutputsModel$StateEnd$SD <- lapply(seq(NbUpBasins), function(x) {
lastTS <- RunOptions$IndPeriod_Run[length(RunOptions$IndPeriod_Run)]
InputsModel$Qupstream[(lastTS - floor(PT[x])):lastTS, x]
})
#message("StateEnd: ",paste(OutputsModel$StateEnd$SD, collapse = ", "))
# message("StateEnd: ", paste(OutputsModel$StateEnd$SD, collapse = ", "))
}
return(OutputsModel)
......
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