Skip to content

Commit

Permalink
Auto fix obs nodes in case of changing soil profile
Browse files Browse the repository at this point in the history
  • Loading branch information
mrustl committed Jul 9, 2024
1 parent 4a8c6eb commit 25bc249
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion R/write_profile.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""))
Expand Down

0 comments on commit 25bc249

Please sign in to comment.