Skip to content

Commit

Permalink
Fix ncTestRuns: avoid duplicated soil layers
Browse files Browse the repository at this point in the history
Resolved problem: repeated calls to `tools/check_ncTestRuns.sh -t 30` caused repeated addition of a 100-cm and a 120-cm deep soil layer to "soils.in" even if they already were present
  • Loading branch information
dschlaep committed Dec 16, 2024
1 parent ad38267 commit 7969fd3
Showing 1 changed file with 30 additions and 19 deletions.
49 changes: 30 additions & 19 deletions tests/ncTestRuns/scripts/Rscript__ncTestRuns_01_createTestRuns.R
Original file line number Diff line number Diff line change
Expand Up @@ -1635,29 +1635,40 @@ for (k0 in seq_len(nrow(listTestRuns))) {
fname <- file.path(dir_testRun, "Input", "soils.in")

fin <- suppressWarnings(readLines(fname))
lid <- max(which(nchar(fin) > 0L)) # last line with values
ids1 <- seq_len(lid)
idsExtra <- seq(from = 0L - nExtraSoilLayers + 1L, to = 0L, by = 1L)

fextra <- strsplit(fin[lid + idsExtra], split = "[ ]+")
fextra <- lapply(fextra, function(x) x[nchar(x) > 0L])
stopifnot(length(unique(lengths(fextra))) == 1L)
# Count number of soil layers in "soils.in"
nhas <- intersect(
grep("(^#)", x = trimws(fin), invert = TRUE),
which(nchar(trimws(fin)) > 0L)
) |>
unique() |>
length()

fextra <- mapply(
function(sl, d) {
c(as.character(d), sl[-1L])
},
fextra,
cumsum(hzthkTestRun)[length(hzthkTestRun) + idsExtra],
SIMPLIFY = FALSE
)
if (nhas == nSoilLayersDefault && nExtraSoilLayers > 0L) {
lid <- max(which(nchar(fin) > 0L)) # last line with values
ids1 <- seq_len(lid)
idsExtra <- seq(from = 0L - nExtraSoilLayers + 1L, to = 0L, by = 1L)

fin2 <- c(
fin,
vapply(fextra, paste, FUN.VALUE = NA_character_, collapse = " ")
)
fextra <- strsplit(fin[lid + idsExtra], split = "[ ]+")
fextra <- lapply(fextra, function(x) x[nchar(x) > 0L])
stopifnot(length(unique(lengths(fextra))) == 1L)

writeLines(fin2, con = fname)
fextra <- mapply(
function(sl, d) {
c(as.character(d), sl[-1L])
},
fextra,
cumsum(hzthkTestRun)[length(hzthkTestRun) + idsExtra],
SIMPLIFY = FALSE
)

fin2 <- c(
fin,
vapply(fextra, paste, FUN.VALUE = NA_character_, collapse = " ")
)

writeLines(fin2, con = fname)
}
}


Expand Down

0 comments on commit 7969fd3

Please sign in to comment.