Skip to content

Commit

Permalink
Merge branch 'main' into new-release
Browse files Browse the repository at this point in the history
  • Loading branch information
plecharpent committed Feb 20, 2024
2 parents 83438d1 + 4cd5168 commit c026395
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions R/stics_wrapper.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
#'
#' @export
#'
#' @importFrom foreach %dopar%
#' @importFrom foreach %dopar% %do%
#' @importFrom parallel clusterCall makeCluster stopCluster
#' @importFrom doParallel registerDoParallel
#' @importFrom magrittr %>%
Expand Down Expand Up @@ -181,8 +181,13 @@ stics_wrapper <- function(model_options,
registerDoParallel(cl)
clusterCall(cl, function(x) .libPaths(x), .libPaths())

`%doparornot%` <- `%dopar%`
} else `%doparornot%` <- `%do%`
#`%doparornot%` <- `%dopar%`
`%do_par_or_not%` <- foreach::`%dopar%`
} else {
#`%doparornot%` <- `%do%`
`%do_par_or_not%` <- foreach::`%do%`

}

# Define the list of USMs to simulate and initialize results -----------------
# Check the available USMs
Expand Down Expand Up @@ -282,7 +287,8 @@ stics_wrapper <- function(model_options,
i = seq_along(sit2simulate),
.export = c("run_stics", "select_results"),
.packages = c("SticsRFiles")
) %doparornot% {
#) %doparornot% {
) %do_par_or_not% {
## Loops on the USMs that can be simulated
## out is a list containing vectors of:
## o list of simulated outputs,
Expand Down Expand Up @@ -411,7 +417,7 @@ stics_wrapper <- function(model_options,
# The following could be done only once in case of repeated call
# to the wrapper (e.g. parameters estimation ...)
SticsRFiles::set_usm_txt(
filepath = file.path(run_dir, "new_travail.usm"),
file = file.path(run_dir, "new_travail.usm"),
param = "codesuite", value = 1
)
}
Expand All @@ -425,7 +431,7 @@ stics_wrapper <- function(model_options,
### snow_variables.txt (for usms that have a successor)
if (!is.na(is_succ) && is_succ) {
SticsRFiles::set_usm_txt(
filepath = file.path(
file = file.path(
run_dir,
"new_travail.usm"
),
Expand Down Expand Up @@ -641,7 +647,7 @@ select_results <- function(keep_all_data, sit_var_dates_mask, var_names,
req_var_names <- c(var_names)
}

## Convert required variables names to Stics variables names (i.e. handle ())
## Convert required variables names to Stics variables names (i.e. handle ())
req_var_names <- SticsRFiles:::var_to_col_names(req_var_names)

## Add reserved keywords "Plant" and "Date" from the list
Expand All @@ -653,8 +659,8 @@ select_results <- function(keep_all_data, sit_var_dates_mask, var_names,
inter_var_names <- sim_var_names[req_vars_idx]


## In case some variables are not simulated, warn the user, add them in var.mod
## and re-simulate or select the results if var.mod has already been modified.
## In case some variables are not simulated, warn the user, add them in var.mod
## and re-simulate or select the results if var.mod has already been modified.
if (length(inter_var_names) < length(req_var_names)) {
if (varmod_modified) {
## var.mod has already been modified ... warn the user the required
Expand All @@ -668,7 +674,7 @@ select_results <- function(keep_all_data, sit_var_dates_mask, var_names,
"not simulated by the Stics model for USM",
situation,
"although added in", file.path(run_dir, "var.mod"),
"=> these variables may not be Stics variables, please check spelling. \n ",
"=> these variables may not be Stics variables, please check spelling. \n ",
"Simulated variables:", paste(sim_var_names, collapse = ", ")
))
res$flag_error <- FALSE
Expand Down

0 comments on commit c026395

Please sign in to comment.