UtilsRunModel.R 1.49 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#' Create `OutputsModel` for GR non-Cemaneige models
#'
#' @param InputsModel output of [CreateInputsModel]
#' @param RunOptions output of [CreateRunOptions]
#' @param RESULTS outputs of [.Fortran]
#' @param LInputSeries number of time steps of warm-up + run periods
#' @param CemaNeigeLayers outputs of Cemaneige pre-process
#'
#' @return
#' @noRd
#'
.GetOutputsModel <- function(InputsModel,
                                RunOptions,
                                RESULTS,
                                LInputSeries,
                                CemaNeigeLayers = NULL) {

  IndPeriod2 <- (length(RunOptions$IndPeriod_WarmUp)+1):LInputSeries
  FortranOutputs <- RunOptions$FortranOutputs$GR

  if ("all" %in% RunOptions$Outputs_Sim) {
    IndOutputs <- as.integer(1:length(FortranOutputs))
  } else {
    IndOutputs <- which(FortranOutputs %in% RunOptions$Outputs_Sim)
  }

  OutputsModel <- list()

  if("DatesR" %in% RunOptions$Outputs_Sim) {
30
    OutputsModel$DatesR <- InputsModel$DatesR[RunOptions$IndPeriod_Run]
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
  }

  seqOutputs <- seq_len(RESULTS$NOutputs)
  names(seqOutputs) <- FortranOutputs[IndOutputs]

  OutputsModel <- c(OutputsModel,
                    lapply(seqOutputs, function(i) RESULTS$Outputs[IndPeriod2, i]))

  if(!is.null(CemaNeigeLayers)) {
    OutputsModel$CemaNeigeLayers <- CemaNeigeLayers
  }

  if("StateEnd" %in% RunOptions$Outputs_Sim) {
    OutputsModel$StateEnd <- RESULTS$StateEnd
  }

47
48
  class(OutputsModel) <- c("OutputsModel", class(RunOptions)[-1])

49
50
  return(OutputsModel)
}