From 25bc249b172439c7a4cb7ad6a6b00a73129d4ee2 Mon Sep 17 00:00:00 2001 From: mrustl Date: Tue, 9 Jul 2024 15:33:37 +0200 Subject: [PATCH] Auto fix obs nodes in case of changing soil profile --- R/write_profile.R | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/R/write_profile.R b/R/write_profile.R index 247f87d..49f8c66 100644 --- a/R/write_profile.R +++ b/R/write_profile.R @@ -112,10 +112,16 @@ write_profile <- function(profile, obsnodes <- if(is.null(profile$obsnodes$n)) { obsnodes <- stringr::str_pad(0,width = 5,side = "left") } else { + if(profile$obsnodes$n > 0) { + if(max(profile$obsnodes$ids) > max(profile$profile$node_id)) { + valid_ids <- which(profile$obsnodes$ids <= max(profile$profile$node_id)) + profile$obsnodes$ids <- profile$obsnodes$ids[valid_ids] + profile$obsnodes$n <- length(profile$obsnodes$ids) + } + stringr::str_pad(profile$obsnodes$n,width = 5,side = "left") } - if(profile$obsnodes$n > 0) { obsnodes <- c(obsnodes, paste0(stringr::str_pad(profile$obsnodes$ids,width = 5,side = "left"), collapse = ""))