Commit 4a75492f authored by Dorchies David's avatar Dorchies David
Browse files

Merge branch '2-functions-to-run-talweg-fluvia-sirene' into 'main'

Resolve "Functions to run Talweg, Fluvia, Sirene"

Closes #2

See merge request !1
1 merge request!1Resolve "Functions to run Talweg, Fluvia, Sirene"
Showing with 4462 additions and 1 deletion
+4462 -1
......@@ -43,3 +43,8 @@ vignettes/*.pdf
# Project specific
###############################################################################
/config.yml
/vignettes/config.yml
/tests/testthat/config.yml
*.INI
*.ini
# Generated by roxygen2: do not edit by hand
export(loadConfig)
export(sic_run_fortran)
......@@ -30,7 +30,10 @@
#' str(cfg)
loadConfig <- function(sic_path = NULL, xml_path = NULL, userFile = "config.yml", pathDefaultCfg = system.file("config.yml", package = "rsic2")) {
cfg <- config::get(file = pathDefaultCfg)
if (file.exists(userFile)) {cfg = config::merge(cfg,config::get(file = userFile))}
if (file.exists(userFile)) {
message("Reading user configuration from ", userFile)
cfg = config::merge(cfg,config::get(file = userFile))
}
if (!is.null(sic_path)) cfg$sic$path <- sic_path
if (!is.null(xml_path)) cfg$project$path <- xml_path
if (!dir.exists(cfg$sic$path)) {
......
#' Run Talweg, Fluvia or Sirene
#'
#' @param prog [character], the program to run. Should be one of "talweg"
#' @param params [list] or [character], see details
#' @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]
#'
#' @return
#' @export
#'
#' @examples
#' \dontrun{
#' # Run steady simulation for the scenario #1
#' params <- list(SCE=1)
#' sic_run_fortran("fluvia", params)
#'}
sic_run_fortran <- function(prog, params, cfg = loadConfig()) {
if (is.list(params)) params <- convert_sic_params(params, cfg)
shell(
shQuote(
paste(
file.path(cfg$sic$path, cfg$sic[[prog]]),
shQuote(cfg$project$path, type = "cmd"),
params
),
type = "cmd2"),
wait = T,
translate = T
)
}
This diff is collapsed.
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/sic_run_fortran.R
\name{sic_run_fortran}
\alias{sic_run_fortran}
\title{Run Talweg, Fluvia or Sirene}
\usage{
sic_run_fortran(prog, params, cfg = loadConfig())
}
\arguments{
\item{prog}{\link{character}, the program to run. Should be one of "talweg"}
\item{params}{\link{list} or \link{character}, see details}
\item{cfg}{}
}
\value{
}
\description{
Run Talweg, Fluvia or Sirene
}
\details{
If argument \code{params} is a \link{list}, arguments are injected in the command line by taking the items of the list with the conversion
\verb{[key]=[value]}. If argument \code{params} is a \link{character}
}
\examples{
\dontrun{
# Run steady simulation for the scenario #1
params <- list(SCE=1)
sic_run_fortran("fluvia", params)
}
}
# 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)
test_that("fluvia on SCE=1 should create a binary result file", {
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