Skip to content
Snippets Groups Projects
Commit df943d35 authored by Johannes Boog's avatar Johannes Boog
Browse files

[base] add export routines for includes

parent e11a5c01
No related branches found
No related tags found
1 merge request!55[base] update package to OGS6.4.2
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#' Wrapper function to create a \code{.prj} XML document based on the user #' Wrapper function to create a \code{.prj} XML document based on the user
#' input data #' input data
#' @param ogs6_obj OGS6: Simulation object #' @param ogs6_obj OGS6: Simulation object
#' @param copy_ext_files flag: Wether referenced files are copied or not.
#' @noRd #' @noRd
export_prj <- function(ogs6_obj, copy_ext_files = F) { export_prj <- function(ogs6_obj, copy_ext_files = F) {
...@@ -21,13 +22,23 @@ export_prj <- function(ogs6_obj, copy_ext_files = F) { ...@@ -21,13 +22,23 @@ export_prj <- function(ogs6_obj, copy_ext_files = F) {
meshes <- ogs6_obj$meshes meshes <- ogs6_obj$meshes
geometry <- ogs6_obj$geometry geometry <- ogs6_obj$geometry
# copy meshes if required # handle meshes
if(isTRUE(copy_ext_files)){ if(!is.null(meshes) & length(meshes) != 0){
for(i in seq(meshes)){
vtu_path <- meshes[[i]][["path"]] # copy meshes if required
file.copy(vtu_path, ogs6_obj$sim_path) if(isTRUE(copy_ext_files)){
meshes[[i]][["path"]] <- basename(vtu_path) for(i in seq(meshes)){
}} vtu_path <- meshes[[i]][["path"]]
file.copy(vtu_path, ogs6_obj$sim_path)
meshes[[i]][["path"]] <- basename(vtu_path)
}}
# export vtu
meshes_node <- meshes_to_xml(meshes)
xml2::xml_add_child(prj_xml,
meshes_node)
}
# handle gml # handle gml
if(!is.null(ogs6_obj$gml)){ if(!is.null(ogs6_obj$gml)){
...@@ -46,29 +57,27 @@ export_prj <- function(ogs6_obj, copy_ext_files = F) { ...@@ -46,29 +57,27 @@ export_prj <- function(ogs6_obj, copy_ext_files = F) {
xml2::as_xml_document(to_node(geometry))) xml2::as_xml_document(to_node(geometry)))
} }
# export vtu
meshes_node <- meshes_to_xml(meshes)
xml2::xml_add_child(prj_xml,
meshes_node)
#Get implemented classes #Get implemented classes
prj_components <- ogs6_prj_top_level_classes() prj_components <- ogs6_prj_top_level_classes()
# handle includes # handle to level include
if(names(ogs6_obj$processes)[[1]] == "include"){ if(!is.null(ogs6_obj$include)){
processes <- ogs6_obj$processes include <- ogs6_obj$include
if(isTRUE(copy_ext_files)){ if(isTRUE(copy_ext_files)){
file.copy(processes[[1]][["file"]], ogs6_obj$sim_path) file.copy(include[["file"]], ogs6_obj$sim_path)
processes[[1]][["file"]] <- basename(processes[[1]][["file"]]) include[["file"]] <- basename(include[["file"]])
} }
include_list <- list(include)
processes_node <- to_node(processes, attribute_names = "include") names(include_list) <- "include"
include_node <- to_node(include, attribute_names = "include")
xml2::xml_add_child(prj_xml, xml2::xml_add_child(prj_xml,
xml2::as_xml_document(processes_node)) xml2::as_xml_document(include_node))
prj_components <- prj_components[names(prj_components) != "processes"] prj_components <- prj_components[names(prj_components) != "include"]
} }
#Add default cases #Add default cases
for(i in seq_len(length(prj_components))){ for(i in seq_len(length(prj_components))){
param_name <- names(prj_components)[[i]] param_name <- names(prj_components)[[i]]
...@@ -83,22 +92,39 @@ export_prj <- function(ogs6_obj, copy_ext_files = F) { ...@@ -83,22 +92,39 @@ export_prj <- function(ogs6_obj, copy_ext_files = F) {
next next
} }
# in case copy referenced files # wether to handle include or prj class object
if(copy_ext_files){ if("include" %in% names(param)[[1]]){
if(param_name=="chemical_system"){
file.copy(param$database, ogs6_obj$sim_path) if(isTRUE(copy_ext_files)){
param$database <- basename(param$database) file.copy(param[[1]][["file"]], ogs6_obj$sim_path)
param[[1]][["file"]] <- basename(param[[1]][["file"]])
} }
if(param_name=="python_script"){
file.copy(param, ogs6_obj$sim_path) param_node <- to_node(param, attribute_names = "include")
param <- basename(param) names(param_node) <- param_name
xml2::xml_add_child(prj_xml,
xml2::as_xml_document(param_node))
# prj class param
} else{
# in case copy referenced files
if(copy_ext_files){
if(param_name=="chemical_system"){
file.copy(param$database, ogs6_obj$sim_path)
param$database <- basename(param$database)
}
if(param_name=="python_script"){
file.copy(param, ogs6_obj$sim_path)
param <- basename(param)
}
} }
}
# create xml node # create xml node
param_node <- to_node(param, param_name) param_node <- to_node(param, param_name)
xml2::xml_add_child(prj_xml, xml2::xml_add_child(prj_xml,
xml2::as_xml_document(param_node)) xml2::as_xml_document(param_node))
}
} }
file <- paste0(ogs6_obj$sim_path, ogs6_obj$sim_name, ".prj") file <- paste0(ogs6_obj$sim_path, ogs6_obj$sim_name, ".prj")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment