Skip to content

Commit d4ff208

Browse files
committed
Fix reading HYDRUS1D.DAT
1 parent 8aa5271 commit d4ff208

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

R/read_write_hydrus1d_dat.R

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ read_hydrus1d <- function(path = system.file("extdata/model/test/HYDRUS1D.dat",
1515

1616
section_start_idx <- which(stringr::str_detect(lines, "\\["))
1717

18-
section_end_idx <- c(max(section_start_idx) - 4, length(lines))
18+
section_end_idx <- c(max(section_start_idx) - 2, length(lines))
1919

2020
section_names <- stringr::str_remove_all(lines[section_start_idx], "\\[|\\]")
2121

@@ -31,13 +31,18 @@ read_hydrus1d <- function(path = system.file("extdata/model/test/HYDRUS1D.dat",
3131
}
3232

3333

34-
setNames(lapply(seq_len(length(section_names)), function(i) {
34+
res <- setNames(lapply(seq_len(length(section_names)), function(i) {
3535

36-
mat_data <- stringr::str_split_fixed(lines[(section_start_idx[i]+1):section_end_idx[i]], pattern = "=", n = 2)
36+
mat_data <- stringr::str_split_fixed(lines[(section_start_idx[i]+1):section_end_idx[i]],
37+
pattern = "=",
38+
n = 2)
3739

3840
setNames(lapply(mat_data[, 2], convert_to_numeric), mat_data[, 1])
3941
}), nm = section_names)
4042

43+
res$Profile$ProfileDepth <- toupper(format(res$Profile$ProfileDepth,
44+
scientific = TRUE,
45+
digits = 1))
4146

4247
}
4348

0 commit comments

Comments
 (0)