Commit 12ce4921 authored by Dorchies David's avatar Dorchies David
Browse files

fix(set_initial_condition): test and debug

- add logger for debugging purpose
- remove extra stuffs in sic project example
- debug set_initial_condition with successful test

Refs #4
1 merge request!2Resolve "Import initial conditions from a result to a new scenario/variant"
Showing with 542 additions and 544 deletions
+542 -544
......@@ -19,4 +19,5 @@ Depends:
RoxygenNote: 7.1.1
Roxygen: list(markdown = TRUE)
Imports:
logger,
terra
#' Convert a list of parameters into command line arguments
#'
#' @param params a [list] of [character] with each item is identified by
#' @param cfg
#' @param params a [list] of [character] containing the parameters to send to the fortran program with format `list(param=value, ...)`
#' @template param_cfg
#'
#' @return A [character] with each parameter is converted to "[key param]=[value param]" and each parameter separated by a space character.
#' @return A [character] with each parameter is converted to `[key param]=[value param]` and each parameter separated by a space character.
#' @export
#'
#' @examples
#' convert_sic_param(list(SCE = 1, VAR = 1))
#'
convert_sic_params <- function(params, cfg = loadConfig()) {
if (!"INTERF" %in% names(params)) {
params <- c(list(INTERF = cfg$sic$fortran$prms$INTERF), params)
......
......@@ -3,7 +3,7 @@
#' Import initial conditions from a scenario/variant result calculation to a new scenario/variant.
#'
#' @param params [numeric], arguments passed to Edisic for importing initial conditions. See details
#' @param cfg
#' @template param_cfg
#'
#' @details `params` [numeric] vector of length 5. Each number correspond to:
#'
......@@ -13,31 +13,32 @@
#' 1. number of the scenario where the initial conditions are exported to
#' 1. number of the variant where the initial conditions are exported to (Use "0" for no variant)
#'
#' @return
#' @export
#'
#' @examples
#' \dontrun{
#' # Import initial conditions from the scenario #1 without variant at time 0s
#' # to the variant #1 in the scenario #1
#' set_initial_conditions("1 0 0 1 1")
#' set_initial_conditions(c(1, 0, 0, 1, 1))
#' }
set_initial_conditions <- function(params, cfg = loadConfig()) {
if (!is.numeric(params) || length(params) != 5) {
stop("`params` should be a numeric of length 5")
}
sArgs <- paste(params, collapse = " ")
shell(
shQuote(
paste(
file.path(cfg$sic$path, cfg$sic$edisic),
shQuote(dirname(cfg$project$path), type = "cmd"),
"CI",
shQuote(basename(cfg$project$path), type = "cmd"),
sArgs
),
type = "cmd2"
cmd_line <- shQuote(
paste(
file.path(cfg$sic$path, cfg$sic$edisic),
shQuote(dirname(cfg$project$path), type = "cmd"),
"CI",
shQuote(basename(cfg$project$path), type = "cmd"),
sArgs
),
type = "cmd2"
)
logger::log_debug(cmd_line)
shell(
cmd_line,
wait = T,
translate = T
)
......
......@@ -2,7 +2,7 @@
#'
#' @param prog [character], the program to run. Should be one of "talweg"
#' @param params [list] or [character], see details
#' @param cfg
#' @template param_cfg
#'
#' @details If argument `params` is a [list], arguments are injected in the command line by taking the items of the list with the conversion
#' `[key]=[value]`. If argument `params` is a [character]
......@@ -18,14 +18,17 @@
#'}
sic_run_fortran <- function(prog, params, cfg = loadConfig()) {
if (is.list(params)) params <- convert_sic_params(params, cfg)
cmd_line <- shQuote(
paste(
file.path(cfg$sic$path, cfg$sic[[prog]]),
shQuote(cfg$project$path, type = "cmd"),
params
),
type = "cmd2"
)
logger::log_debug(cmd_line)
shell(
shQuote(
paste(
file.path(cfg$sic$path, cfg$sic[[prog]]),
shQuote(cfg$project$path, type = "cmd"),
params
),
type = "cmd2"),
cmd_line,
wait = T,
translate = T
)
......
This diff is collapsed.
#' @param cfg a [config] object. Configuration to use. See [loadConfig] for details
......@@ -7,13 +7,17 @@
convert_sic_params(params, cfg = loadConfig())
}
\arguments{
\item{params}{a \link{list} of \link{character} with each item is identified by}
\item{params}{a \link{list} of \link{character} containing the parameters to send to the fortran program with format \code{list(param=value, ...)}}
\item{cfg}{}
\item{cfg}{a \link{config} object. Configuration to use. See \link{loadConfig} for details}
}
\value{
A \link{character} with each parameter is converted to "\link{key param}=\link{value param}" and each parameter separated by a space character.
A \link{character} with each parameter is converted to \verb{[key param]=[value param]} and each parameter separated by a space character.
}
\description{
Convert a list of parameters into command line arguments
}
\examples{
convert_sic_param(list(SCE = 1, VAR = 1))
}
......@@ -9,10 +9,7 @@ set_initial_conditions(params, cfg = loadConfig())
\arguments{
\item{params}{\link{numeric}, arguments passed to Edisic for importing initial conditions. See details}
\item{cfg}{}
}
\value{
\item{cfg}{a \link{config} object. Configuration to use. See \link{loadConfig} for details}
}
\description{
Import initial conditions from a scenario/variant result calculation to a new scenario/variant.
......@@ -31,6 +28,6 @@ Import initial conditions from a scenario/variant result calculation to a new sc
\dontrun{
# Import initial conditions from the scenario #1 without variant at time 0s
# to the variant #1 in the scenario #1
set_initial_conditions("1 0 0 1 1")
set_initial_conditions(c(1, 0, 0, 1, 1))
}
}
......@@ -11,7 +11,7 @@ sic_run_fortran(prog, params, cfg = loadConfig())
\item{params}{\link{list} or \link{character}, see details}
\item{cfg}{}
\item{cfg}{a \link{config} object. Configuration to use. See \link{loadConfig} for details}
}
\value{
......
# Set local configuration for SIC tests
xml_path <- tempfile("sic_project", fileext = ".xml")
file.copy(system.file("sic_project_test1.xml", package = "rsic2"),
xml_path,
overwrite = TRUE)
cfg <- loadConfig(xml_path = xml_path)
loadLocalConfig <- function() {
xml_path <- tempfile("sic_project", fileext = ".xml")
file.copy(system.file("sic_project_test1.xml", package = "rsic2"),
xml_path,
overwrite = TRUE)
loadConfig(xml_path = xml_path)
}
skip_on_ci()
test_that("set_initial_conditions works", {
cfg <- loadLocalConfig()
sic_run_fortran("fluvia", list(SCE = 1), cfg = cfg)
set_initial_conditions(c(1, 0, 0, 1, 1), cfg = cfg)
sic_run_fortran("sirene", list(SCE = 1, VAR = 1), cfg = cfg)
expect_true(file.exists(gsub("\\.xml", "_1_1.res", cfg$project$path)))
})
skip_on_ci()
test_that("fluvia on SCE=1 should create a binary result file", {
cfg <- loadLocalConfig()
sic_run_fortran("fluvia", list(SCE = 1), cfg = cfg)
expect_true(file.exists(gsub("\\.xml", "_1_0.res", cfg$project$path)))
expect_true(file.exists(gsub("\\.xml", "_1_0.rci", cfg$project$path)))
......
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